Closed zorn-v closed 5 years ago
That's a feature: logging must NEVER be disabled, if you don't want console logs enable logging to file.
Why ? I don't need these logs
BTW, not problem. anyway script runs as ./script > /dev/null
but it is DOCUMENTED that I can disable logs
Instead of redirecting stdout, you could change the settings. btw will change the docs accordingly xd
Instead of redirecting stdout, you could change the settings.
I change settings as I mention before. Or you mean set log destination to /dev/null via settings ? No thanks.
And log_level not work also. Setting it to FATAL_ERROR log everything anyway.
Hi, I can produce this problem. I tried to disable logging but it doesn't work.
$settings = (new LoggerSettings)
->setType(Logger::LOGGER_ECHO)
->setLevel(Logger::FATAL_ERROR)
->setMaxSize(1024);
$this->bot = new API('bot');
$this->bot->updateSettings($settings);
According to Logger::NO_LOGGER
deprecated, I used Logger::LOGGER_ECHO
to just echo logs to the console instead to write it to the file. But it writes anyway...
Hello! Has anyone found a workaround for this? @AmirHosseinKarimi ? @zorn-v ?
My code looks like this:
$mp->updateSettings((new LoggerSettings())
->setType(Logger::LOGGER_FILE)
->setLevel(Logger::LEVEL_FATAL)
->setExtra('/dev/null')
->setMaxSize(0)
);
But it still spams to console and breaks it.
That's a feature: logging must NEVER be disabled, if you don't want console logs enable logging to file.
@danog I also do not like this log file because of the IO overhead that is created.
Simple but not ideal:
Go to vendor/danog/madelineproto/src/danog/MadelineProto/Logger.php
find 'logger' function and add a 'return' statement in start of this function.
Simple but not ideal:
Go to vendor/danog/madelineproto/src/danog/MadelineProto/Logger.php
find 'logger' function and add a 'return' statement in start of this function.
And do it after every package update...
I'm trying to store all logs into a file to disable somehow the console output, but that doesn't work either, even tho I copied from the docs:
$this->client = new API('session.madeline');
$settings = (new LoggerSettings())
->setType(Logger::FILE_LOGGER)
->setExtra(storage_path('logs/madeline-proto.log'));
$this->client->updateSettings($settings);
$this->client->async(false);
$this->client->start();
The file exists and is writable.
Simple but not ideal:
Go to vendor/danog/madelineproto/src/danog/MadelineProto/Logger.php
find 'logger' function and add a 'return' statement in start of this function.
Based on your idea, here is my kinda package update proof solution. My project is a silly script, so I don't care if it breaks, but might not be the case in yours, so use this with caution ⚠️
/**
* Initialize the Telegram Client.
*/
protected function initTelegramClient()
{
// Disable logging, the hard way:
$loggerPath = 'vendor/danog/madelineproto/src/danog/MadelineProto/Logger.php';
$content = file_get_contents($loggerPath);
$content = preg_replace('/public function logger\(.*?\)\: void$\s+{((?:.*?)((?:\r\n|[\r\n]).+$)*)/', '', $content);
file_put_contents($loggerPath, $content);
$this->client = new API('session.madeline');
$this->client->async(false);
$this->client->start();
}
I hope in the future there is an official way to disable logging.
No matter if you pass
$proto->settings['logger']['logger'] = 0;
(or the same thing in constructor) - console will blow of log messages )