Example #1
0
 /**
  * Set min and max log levels for this adapter
  *
  * @param null $minLevel
  * @param null $maxLevel
  */
 public function setLevel($minLevel = null, $maxLevel = null)
 {
     if (!$minLevel || !Logger::isLoglevel($minLevel)) {
         $minLevel = LogLevel::DEBUG;
     }
     if (!$maxLevel || !Logger::isLoglevel($maxLevel)) {
         $maxLevel = LogLevel::EMERGENCY;
     }
     $this->minLevel = Logger::$levels[$minLevel];
     $this->maxLevel = Logger::$levels[$maxLevel];
 }
Example #2
0
<?php

use Psr\Log\LogLevel;
use Rioter\Logger\Logger;
use Rioter\Logger\Adapters;
use Rioter\Logger\ErrorsHandler;
require_once '../vendor/autoload.php';
$fileAdapter = new Adapters\FileAdapter('logs/log.txt');
$fileAdapter->setDateFormat('Y-m-d H:i:s');
$fileAdapter->setLevel(LogLevel::DEBUG, LogLevel::INFO);
$fileAdapter->setMethodLogLevelFile(array(LogLevel::ERROR, LogLevel::DEBUG), 'logs/error_debug.txt');
$fileAdapter->setMethodLogLevelFile(LogLevel::WARNING, 'logs/warning.txt');
$echoAdapter = new Adapters\EchoAdapter();
$echoAdapter->setLevel(LogLevel::WARNING, LogLevel::CRITICAL);
$sysLogAdapter = new Adapters\SysLogAdapter('ITCourses');
$sysLogAdapter->setLevel(null, LogLevel::ERROR);
$logger = new Logger($sysLogAdapter);
$logger->setAdapter($fileAdapter);
$logger->setAdapter($echoAdapter);
$logger->error('message of errors' . __FILE__);
$logger->critical('critical' . __FILE__);
$logger->debug('debug of errors {id} {line} {file}', array('id' => 1, 'line' => __LINE__, 'file' => __FILE__));
$handler = new ErrorsHandler($logger);
$exception = new \RuntimeException('Runtime exception');
$handler->regExceptionHandler();
$handler->logExceptionHandler($exception);
$handler->regErrorHandler();
trigger_error('user warning', E_USER_WARNING);
Example #3
0
 /**
  * кастомный обработчик исключений
  *
  * @param $exception
  */
 public function logExceptionHandler($exception)
 {
     $message = $exception->getMessage() . ' | File: {file} | Line: {line}';
     $context = array('file' => $exception->getFile(), 'line' => $exception->getLine());
     $this->logger->log($this->exceptionLogLevel, $message, $context);
 }
Example #4
0
 /**
  * @expectedException \Psr\Log\InvalidArgumentException
  */
 public function testUndefinedLogLevel()
 {
     $logger = new Logger();
     $logger->log('myLvl', 'myLvl');
 }