Skip to content
Newer
Older
100644 92 lines (61 sloc) 4.93 KB
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
1 Monolog - Logging for PHP 5.3
2 =============================
3
4 Usage
5 -----
6
7 use Monolog\Logger;
20110bf @Seldaek Updated README
authored Mar 27, 2011
8 use Monolog\Handler\StreamHandler;
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
9
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored Feb 20, 2011
10 // create a log channel
11 $log = new Logger('name');
20110bf @Seldaek Updated README
authored Mar 27, 2011
12 $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
13
6c24217 @Seldaek Renamed message to record
authored Feb 25, 2011
14 // add records to the log
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored Feb 20, 2011
15 $log->addWarning('Foo');
16 $log->addError('Bar');
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
17
8d27400 @Seldaek Updated README
authored Feb 21, 2011
18 Core Concepts
19 -------------
20
6c24217 @Seldaek Renamed message to record
authored Feb 25, 2011
21 Every Logger instance has a channel (name) and a stack of handlers. Whenever you add a record to the logger, it traverses the handler stack. Each handler decides whether it handled fully the record, and if so, the propagation of the record ends there.
8d27400 @Seldaek Updated README
authored Feb 21, 2011
22
6c24217 @Seldaek Renamed message to record
authored Feb 25, 2011
23 This allow for flexible logging setups, for example having a FileHandler at the bottom of the stack that will log anything to disk, and on top of that add a MailHandler that will send emails only when an error message is logged. Handlers also have a bubbling property which define whether they block the record or not if they handled it. In this example, setting the MailHandler's $bubble argument to true means that all records will propagate to the FileHandler, even the errors that are handled by the MailHandler.
8d27400 @Seldaek Updated README
authored Feb 21, 2011
24
6c24217 @Seldaek Renamed message to record
authored Feb 25, 2011
25 You can create many Loggers, each defining a channel (e.g.: db, request, router, ..) and each of them combining various handlers, which can be shared or not. The channel is reflected in the logs and allows you to easily see or filter records.
8d27400 @Seldaek Updated README
authored Feb 21, 2011
26
6c24217 @Seldaek Renamed message to record
authored Feb 25, 2011
27 Each Handler also has a Formatter, a default one with settings that make sense will be created if you don't set one. The formatters normalize and format incoming records so that they can be used by the handlers to output useful information.
81c6cd3 @Seldaek Added note about formatters
authored Feb 21, 2011
28
d3e89db @Seldaek Added CRITICAL and ALERT levels
authored May 2, 2011
29 Custom severity levels are not available. Only six levels (debug, info, warning, error, critical, alert) are present for basic filtering purposes, but for sorting and other use cases that would require flexibility, you should add Processors to the Logger that can add extra information (tags, user ip, ..) to the records before they are handled.
8d27400 @Seldaek Updated README
authored Feb 21, 2011
30
0ce2cb2 @Seldaek Updated README
authored May 9, 2011
31 Docs
32 ====
33
580df22 @Seldaek Updated README to document all existing handlers
authored May 9, 2011
34 Handlers
35 --------
8d27400 @Seldaek Updated README
authored Feb 21, 2011
36
580df22 @Seldaek Updated README to document all existing handlers
authored May 9, 2011
37 - _StreamHandler_: Logs records into any php stream, use this for log files.
38 - _RotatingFileHandler_: Logs records to a file and creates one logfile per day. It will also delete files older than $maxFiles. You should use [logrotate](http://linuxcommand.org/man_pages/logrotate8.html) for high profile setups though, this is just meant as a quick and dirty solution.
031a394 @ericclemmons Updated the README with a note about FirePHPHandler
ericclemmons authored Apr 22, 2011
39 - _FirePHPHandler_: Handler for [FirePHP](http://www.firephp.org/), providing inline `console` messages within [FireBug](http://getfirebug.com/).
580df22 @Seldaek Updated README to document all existing handlers
authored May 9, 2011
40 - _NativeMailHandler_: Sends emails using PHP's mail() function.
41 - _SwiftMailerHandler_: Sends emails using a SwiftMailer instance.
42 - _SyslogHandler_: Logs records to the syslog.
43
44 Wrappers / Special Handlers
45 ---------------------------
46
47 - _FingersCrossedHandler_: A very interesting wrapper. It takes a logger as parameter and will accumulate log records of all levels until a record exceeds the defined severity level. At which point it delivers all records, including those of lower severity, to the handler it wraps. This means that until an error actually happens you will not see anything in your logs, but when it happens you will have the full information, including debug and info records. This provides you with all the information you need, but only when you need it.
48 - _NullHandler_: Any record it can handle will be thrown away. This can be used to put on top of an existing handler stack to disable it temporarily.
49 - _BufferHandler_: This handler will buffer all the log records it receives until close() is called at which point it will call handleBatch() on the handler it wraps with all the log messages at once. This is very useful to send an email with all records at once for example instead of having one mail for every log record.
50 - _TestHandler_: Used for testing, it records everything that is sent to it and has accessors to read out the information.
8d27400 @Seldaek Updated README
authored Feb 21, 2011
51
0ce2cb2 @Seldaek Updated README
authored May 9, 2011
52 Formatters
53 ----------
54
55 - _LineFormatter_: Formats a log record into a one-line string.
56 - _JsonFormatter_: Encodes a log record into json.
57 - _WildfireFormatter_: Used to format log records into the Wildfire/FirePHP protocol, only useful for the FirePHPHandler.
58
59 Processors
60 ----------
61
62 - _WebProcessor_: Adds the current request URI, request method and client IP to a log record.
63
64 About
65 =====
66
8d27400 @Seldaek Updated README
authored Feb 21, 2011
67 Requirements
68 ------------
69
70 Any flavor of PHP 5.3 should do
71
6dd6f04 @stof Updated README
stof authored May 8, 2011
72 Submitting bugs and feature requests
73 ------------------------------------
74
75 Bugs and feature request are tracked on [Github](https://github.com/Seldaek/monolog/issues)
76
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
77 Author
78 ------
79
7f2127b @Seldaek Updated README
authored Mar 27, 2011
80 Jordi Boggiano - <j.boggiano@seld.be> - <http://twitter.com/seldaek><br />
20110bf @Seldaek Updated README
authored Mar 27, 2011
81 See also the list of [contributors](https://github.com/Seldaek/monolog/contributors) which participated in this project.
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
82
83 License
84 -------
85
a30c1d6 @Seldaek Fix license info
authored Feb 17, 2011
86 Monolog is licensed under the MIT License - see the LICENSE file for details
2ff85ba @Seldaek Added README file
authored Feb 17, 2011
87
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored Feb 20, 2011
88 Acknowledgements
89 ----------------
90
8d27400 @Seldaek Updated README
authored Feb 21, 2011
91 This library is heavily inspired by Python's [Logbook](http://packages.python.org/Logbook/) library, although most concepts have been adjusted to fit in the PHP world.
Something went wrong with that request. Please try again.