rioter / logger
Installs: 28
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:framework-component
Requires
- php: >=5.5
- psr/log: ^1.0
Requires (Dev)
- phpunit/phpunit: >=4.8
This package is not auto-updated.
Last update: 2024-11-01 10:29:38 UTC
README
ITCourses framework logger component
Installation
Package is available on Packagist, you can install it using Composer.
composer require rioter/logger
PHP 5.5+
Basic Usage
Require autoload
require_once('vendor/autoload.php');
Use namespaces
use Rioter\Logger\Logger; use Rioter\Logger\Adapters;
Available adapters:
$fileAdapter = new Adapters\FileAdapter('logs/log.txt'); / /logging to files $echoAdapter = new Adapters\EchoAdapter(); // logging to html $sysLogAdapter = new Adapters\SysLogAdapter('ITCourses'); // logging to syslog $nullAdapter = new Adapters\NullAdapter(); // log is not saving
To set adapter you can use:
$logger->setAdapter($fileAdapter); $logger->setAdapter($echoAdapter); $logger->setAdapter($nullAdapter);
All adapters methods:
$fileAdapter->setAdapterName('FileAdapter'); $fileAdapter->setDateFormat('Y-m-d H:i:s'); $fileAdapter->setLevel(LogLevel::DEBUG, LogLevel::INFO);
##Errors handlers.
Create object of ErrorsHandler class and give him Logger object
$handler = new \Rioter\Logger\ErrorsHandler($logger);
and register handlers
$handler->regShutdownHandler(); // register shutdown method(last error); $handler->regExceptionHandler(); // register exception $handler->logExceptionHandler($exception); //give exception $handler->regErrorHandler() //register php errors
##Example. Logging to file.
Create object of FileAdapter class and set path and name to log file, also you can set min level of logging (default 'debug')
$fileAdapter = new Adapters\FileAdapter('logs/log.txt');
FileAdapter methods:
$fileAdapter->setMethodLogLevelFile(array('error', 'debug'), 'logs/error_debug.txt'); // or you can use array for multiply setting $fileAdapter->setMethodLogLevelFile('warning', 'logs/warning.txt'); // set different pathes for each errors log $fileAdapter->getMethodsLogLevelFiles(); //get pathes and log levels
Create object of logger, and set adapter;
$logger = new Logger($fileAdapter);
Set logs, context, use placeholder how in example
$logger->error('message of errors'); $logger->critical('critical of errors); $logger->debug("debug of errors id = {id} LINE: __LINE__ FILE: __FILE__", array('id'=>1); $logger->warning('warning', array('id'=>1));
Output:
2016-02-10 23:54:40.436207: [ERROR] Message: message of errors 1
2016-02-10 23:54:40.436633: [CRITICAL] Message: critical of errors 1
2016-02-10 23:54:40.436866: [DEBUG] Message: debug of errors id = 1 LINE: 22 FILE: /home/iirioterii/server/logger/index.php
2016-02-10 23:54:40.437079: [WARNING] Message: warning