Longman\TelegramBot\TelegramLog::initialize PHP Method

initialize() public static method

Initilize monolog instance. Singleton Is possbile provide an external monolog instance
public static initialize ( Logger $external_monolog = null ) : Logger
$external_monolog Monolog\Logger
return Monolog\Logger
    public static function initialize(Logger $external_monolog = null)
    {
        if (self::$monolog === null) {
            if ($external_monolog !== null) {
                self::$monolog = $external_monolog;
                foreach (self::$monolog->getHandlers() as $handler) {
                    if ($handler->getLevel() === 400) {
                        self::$error_log_path = true;
                    }
                    if ($handler->getLevel() === 100) {
                        self::$debug_log_path = true;
                    }
                }
            } else {
                self::$monolog = new Logger('bot_log');
            }
        }
        return self::$monolog;
    }

Usage Example

 public function testExternalStream()
 {
     $file = $this->logfiles['external'];
     $this->assertFileNotExists($file);
     $external_monolog = new Logger('bot_update_log');
     $external_monolog->pushHandler(new StreamHandler($file, Logger::ERROR));
     $external_monolog->pushHandler(new StreamHandler($file, Logger::DEBUG));
     TelegramLog::initialize($external_monolog);
     TelegramLog::error('my error');
     TelegramLog::debug('my debug');
     $this->assertFileExists($file);
     $file_contents = file_get_contents($file);
     $this->assertContains('bot_update_log.ERROR: my error', $file_contents);
     $this->assertContains('bot_update_log.DEBUG: my debug', $file_contents);
 }