danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.87k stars 661 forks source link

Disable logging is not working #621

Closed zorn-v closed 5 years ago

zorn-v commented 5 years ago

No matter if you pass $proto->settings['logger']['logger'] = 0; (or the same thing in constructor) - console will blow of log messages )

danog commented 5 years ago

That's a feature: logging must NEVER be disabled, if you don't want console logs enable logging to file.

zorn-v commented 5 years ago

Why ? I don't need these logs It is a feature

zorn-v commented 5 years ago

BTW, not problem. anyway script runs as ./script > /dev/null but it is DOCUMENTED that I can disable logs

danog commented 5 years ago

Instead of redirecting stdout, you could change the settings. btw will change the docs accordingly xd

zorn-v commented 5 years ago

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.

AmirHosseinKarimi commented 3 years ago

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...

trogwarz commented 3 years ago

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.

NabiKAZ commented 2 years ago

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.

mikaelsoudev commented 2 years ago

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.

zorn-v commented 2 years ago

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...

arall commented 1 year ago

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.

arall commented 1 year ago

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.