Longman\TelegramBot\TelegramLog::initErrorLog PHP Method

initErrorLog() public static method

Initialize error log
public static initErrorLog ( string $path ) : Logger
$path string
return Monolog\Logger
    public static function initErrorLog($path)
    {
        if ($path === null || $path === '') {
            throw new TelegramLogException('Empty path for error log');
        }
        self::initialize();
        self::$error_log_path = $path;
        return self::$monolog->pushHandler((new StreamHandler(self::$error_log_path, Logger::ERROR))->setFormatter(new LineFormatter(null, null, true)));
    }

Usage Example

 public function testErrorStream()
 {
     $file = $this->logfiles['error'];
     $this->assertFileNotExists($file);
     TelegramLog::initErrorLog($file);
     TelegramLog::error('my error');
     $this->assertFileExists($file);
     $this->assertContains('bot_log.ERROR: my error', file_get_contents($file));
 }