/** * @return LoggerInterface */ public function getLogger() { $logHandler = new NullHandler(); $loggerObject = new Logger(); $loggerObject->addHandler($logHandler); return $loggerObject; }
/** * @return void */ public function initLogger() { $this->logHandler = new LogHandler(); $loggerObject = new Logger(); $loggerObject->addHandler($this->logHandler); LoggerManager::init($loggerObject); }
/** * @return LoggerInterface */ public function getLogger() { $logPath = __DIR__ . '/log/test2.log'; $this->logHandler = new StdHandler($logPath); $loggerObject = new Logger(); $loggerObject->addHandler($this->logHandler); return $loggerObject; }
<?php $logPath = __DIR__ . '/log/test2.log'; use Naucon\Logger\Logger; use Naucon\Logger\LoggerManager; use Naucon\Logger\Handler\LogHandler; $logHandler = new LogHandler($logPath); $loggerObject = new Logger(); $loggerObject->addHandler($logHandler); LoggerManager::init($loggerObject); LoggerManager::emergency('message of level emergency'); LoggerManager::alert('message of level alert'); LoggerManager::critical('message of level critical'); LoggerManager::alert('message of level alert'); LoggerManager::error('message of level error'); LoggerManager::warning('message of level warning'); LoggerManager::notice('message of level notice'); LoggerManager::info('message of level info'); LoggerManager::debug('message of level debug'); LoggerManager::critical(new \Exception('invalid foo')); // with context LoggerManager::emergency('message of level emergency with context: {user}', array('user' => 'Bob')); LoggerManager::alert('message of level alert with context: {user}', array('user' => 'Bob')); LoggerManager::critical('message of level critical with context: {user}', array('user' => 'Bob')); LoggerManager::alert('message of level alert with context: {user}', array('user' => 'Bob')); LoggerManager::error('message of level error with context: {user}', array('user' => 'Bob')); LoggerManager::warning('message of level warning with context: {user}', array('user' => 'Bob')); LoggerManager::notice('message of level notice with context: {user}', array('user' => 'Bob')); LoggerManager::info('message of level info with context: {user}', array('user' => 'Bob')); LoggerManager::debug('message of level debug with context: {user}', array('user' => 'Bob')); $exception = new \Exception('invalid foo');
<?php $transport = new Gelf\Transport\UdpTransport("127.0.0.1", 12201, Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN); $publisher = new Gelf\Publisher($transport); use Naucon\Logger\Handler\GelfHandler; $logHandler = new GelfHandler($publisher, 'www.nclib.dev', 'example-facility'); // restrict log level to warning and bellow //use Naucon\Logger\LogLevel; //use Naucon\Logger\Handler\GelfHandler; //$logHandler = new GelfHandler($publisher, 'www.nclib.dev', 'example-facility', LogLevel::WARNING); use Naucon\Logger\Logger; $loggerObject = new Logger(); $loggerObject->addHandler($logHandler); $loggerObject->emergency('message of level emergency'); $loggerObject->alert('message of level alert'); $loggerObject->critical('message of level critical'); $loggerObject->alert('message of level alert'); $loggerObject->error('message of level error'); $loggerObject->warning('message of level warning'); $loggerObject->notice('message of level notice'); $loggerObject->info('message of level info'); $loggerObject->debug('message of level debug'); $loggerObject->critical(new \Exception('invalid foo')); // with context $loggerObject->emergency('message of level emergency with context: {user}', array('user' => 'Bob')); $loggerObject->alert('message of level alert with context: {user}', array('user' => 'Bob')); $loggerObject->critical('message of level critical with context: {user}', array('user' => 'Bob')); $loggerObject->alert('message of level alert with context: {user}', array('user' => 'Bob')); $loggerObject->error('message of level error with context: {user}', array('user' => 'Bob')); $loggerObject->warning('message of level warning with context: {user}', array('user' => 'Bob')); $loggerObject->notice('message of level notice with context: {user}', array('user' => 'Bob'));