ride/lib-log
最新稳定版本:1.2.0
Composer 安装命令:
composer require ride/lib-log
包简介
Log library of the Ride framework
README 文档
README
Log library of the PHP Ride framework.
Logging is used to keep an history of events or to debug an application.
What's In This Library
LogMessage
A log message defines what's being done or what happened.
It consists a:
- level: error, warning, information or debug
- title: title of the message
- description: detailed information about the message
- date: date and time of the event
- microtime: microseconds in the application run
- id: id of the log session
- source: source library or module which logged the message
- client: Id of the client (eg. an IP address)
LogSession
A LogSession is a collection of log messages which belong together. For example, all logged messages from handling the same HTTP request.
Log
The log object is the facade to the library which offers an easy interface to log messages. It uses the observer pattern to dispatch those logged messages to the listeners of the log.
LogListener
A log listener performs the actual logging of the message. The most common thing to do is write a log message to a file. An implementation to do just that has been provided.
BrowseableLogListener
The browseable log listener is an extension of the regular log listener. It adds functionality to retrieve and inspect log messages back from the log.
Code Sample
Check this code sample to see the possibilities of this library:
<?php use ride\library\decorator\LogMessageDecorator; use ride\library\log\listener\BrowseableFileLogListener; use ride\library\log\Log; // obtain the client and generate a log session id $client = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown'; $logSessionId = 'abc123'; // create a listener $listener = new BrowseableFileLogListener('/path/to/log.file'); // make sure it's writable $listener->setFileTruncateSize(512); // in kilobytes $listener->setLogMessageDecorator(new LogMessageDecorator()); // formats the log messages // create the log object $log = new Log(); $log->setId($logSessionId); $log->setClient($client); $log->addLogListener($listener); // do some logging $log->logDebug('Debug message'); $log->logInformation('Information message', 'with a description', 'source'); $log->logWarning('Warning message', 'with a description', 'my-module'); $log->logError('Debug message', 'with a description'); $log->logException(new Exception('A exception')); // browse the log $logSessions = $listener->getLogSessions(array('limit' => 10, 'page' => 2), $pages); $logSession = $listener->getLogSession($logSessionId); $logMessages = $logSession->getLogMessages(); $logMessages = $logSession->getLogMessagesBySource('my-module'); $logMessages = $logSession->getLogMessagesByQuery('message');
Installation
You can use Composer to install this library.
composer require ride/lib-log
统计信息
- 总下载量: 33.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 24
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-21