Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (40 sloc) 3.173 kB
2ff85ba @Seldaek Added README file
authored
1 Monolog - Logging for PHP 5.3
2 =============================
3
4 Usage
5 -----
6
7 use Monolog\Logger;
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored
8 use Monolog\Handler\FileHandler;
2ff85ba @Seldaek Added README file
authored
9
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored
10 // create a log channel
11 $log = new Logger('name');
12 $log->pushHandler(new FileHandler('path/to/your.log', Logger::WARNING));
2ff85ba @Seldaek Added README file
authored
13
6c24217 @Seldaek Renamed message to record
authored
14 // add records to the log
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored
15 $log->addWarning('Foo');
16 $log->addError('Bar');
2ff85ba @Seldaek Added README file
authored
17
8d27400 @Seldaek Updated README
authored
18 Core Concepts
19 -------------
20
6c24217 @Seldaek Renamed message to record
authored
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
22
6c24217 @Seldaek Renamed message to record
authored
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
24
6c24217 @Seldaek Renamed message to record
authored
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
26
6c24217 @Seldaek Renamed message to record
authored
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
28
6c24217 @Seldaek Renamed message to record
authored
29 Custom severity levels are not available. Only four levels (debug, info, warning, error) 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
30
31 Notable Features (non-exhaustive and incomplete)
32 ------------------------------------------------
33
6c24217 @Seldaek Renamed message to record
authored
34 - _FingersCrossedHandler_: A very interesting handler. 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 the info you need, only when you need it.
8d27400 @Seldaek Updated README
authored
35
2ff85ba @Seldaek Added README file
authored
36 Todo
37 ----
38
8d27400 @Seldaek Updated README
authored
39 - Log rotation for RotatingFileHandler and TimedRotatingFileHandler
40 - MailHandler
2ff85ba @Seldaek Added README file
authored
41 - FirePHP writer
42 - Syslog writer
43
8d27400 @Seldaek Updated README
authored
44 Requirements
45 ------------
46
47 Any flavor of PHP 5.3 should do
48
2ff85ba @Seldaek Added README file
authored
49 Author
50 ------
51
52 Jordi Boggiano - <j.boggiano@seld.be> - <http://twitter.com/seldaek>
53
54 License
55 -------
56
a30c1d6 @Seldaek Fix license info
authored
57 Monolog is licensed under the MIT License - see the LICENSE file for details
2ff85ba @Seldaek Added README file
authored
58
3fa6e4b @Seldaek Major refactoring to follow the Logbook model
authored
59 Acknowledgements
60 ----------------
61
8d27400 @Seldaek Updated README
authored
62 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.