Longman\TelegramBot\TelegramLog::initUpdateLog PHP Method

initUpdateLog() public static method

Initilize monolog instance. Singleton Is possbile provide an external monolog instance
public static initUpdateLog ( string $path ) : Logger
$path string
return Monolog\Logger
    public static function initUpdateLog($path)
    {
        if ($path === null || $path === '') {
            throw new TelegramLogException('Empty path for update log');
        }
        self::$update_log_path = $path;
        if (self::$monolog_update === null) {
            self::$monolog_update = new Logger('bot_update_log');
            // Create a formatter
            $output = "%message%\n";
            $formatter = new LineFormatter($output);
            // Update handler
            $update_handler = new StreamHandler(self::$update_log_path, Logger::INFO);
            $update_handler->setFormatter($formatter);
            self::$monolog_update->pushHandler($update_handler);
        }
        return self::$monolog;
    }

Usage Example

 public function testUpdateStream()
 {
     $file = $this->logfiles['update'];
     $this->assertFileNotExists($file);
     TelegramLog::initUpdateLog($file);
     TelegramLog::update('my update');
     $this->assertFileExists($file);
     $this->assertContains('my update', file_get_contents($file));
 }