Daniel ab1334c0cf the whole shebang | 10 years ago | |
---|---|---|
.. | ||
doc | 10 years ago | |
src | 10 years ago | |
tests | 10 years ago | |
CHANGELOG.mdown | 10 years ago | |
LICENSE | 10 years ago | |
README.mdown | 10 years ago | |
composer.json | 10 years ago | |
phpunit.xml.dist | 10 years ago |
Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers below. Special handlers allow you to build advanced logging strategies.
This library implements the PSR-3 interface that you can type-hint against in your own libraries to keep a maximum of interoperability. You can also use it in your applications to make sure you can always use another compatible logger at a later time.
<?php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
// add records to the log
$log->addWarning('Foo');
$log->addError('Bar');
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.
This allows for flexible logging setups, for example having a StreamHandler
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 $bubble
property which defines whether they block the
record or not if they handled it. In this example, setting the MailHandler
's
$bubble
argument to false means that records handled by the MailHandler
will
not propagate to the StreamHandler
anymore.
You can create many Logger
s, 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.
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.
Custom severity levels are not available. Only the eight RFC 5424 levels (debug, info, notice, warning, error, critical, alert, emergency) 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.
Monolog supports all 8 logging levels defined in RFC 5424, but unless you specifically need syslog compatibility, it is advised to only use DEBUG, INFO, WARNING, ERROR, CRITICAL, ALERT.
DEBUG (100): Detailed debug information.
INFO (200): Interesting events. Examples: User logs in, SQL logs.
NOTICE (250): Normal but significant events.
WARNING (300): Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
ERROR (400): Runtime errors that do not require immediate action but should typically be logged and monitored.
CRITICAL (500): Critical conditions. Example: Application component unavailable, unexpected exception.
ALERT (550): Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
EMERGENCY (600): Emergency: system is unusable.
See the doc
directory for more detailed documentation.
The following is only a list of all parts that come with Monolog.
$maxFiles
. You should use
logrotate for high profile
setups though, this is just meant as a quick and dirty solution.error_log()
function.mail()
function.Swift_Mailer
instance.console
messages within FireBug.console
messages within Chrome.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.Monolog\ErrorHandler
class allows you to easily register
a Logger instance as an exception handler, error handler or fatal error handler.Bugs and feature request are tracked on GitHub
Jordi Boggiano - j.boggiano@seld.be - http://twitter.com/seldaek
See also the list of contributors which participated in this project.
Monolog is licensed under the MIT License - see the LICENSE
file for details
This library is heavily inspired by Python's Logbook library, although most concepts have been adjusted to fit to the PHP world.