vendor/monolog/README.mdown
author ymh <ymh.work@gmail.com>
Fri, 04 Nov 2011 11:52:47 +0100
changeset 24 57ff6d39f88c
parent 0 7f95f8617b0b
permissions -rwxr-xr-x
first full dynamic version of the bundle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
Monolog - Logging for PHP 5.3
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
=============================
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
Usage
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
-----
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    use Monolog\Logger;
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    use Monolog\Handler\StreamHandler;
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    // create a log channel
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    $log = new Logger('name');
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    // add records to the log
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    $log->addWarning('Foo');
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    $log->addError('Bar');
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
Core Concepts
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
-------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
Docs
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
====
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
Handlers
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
--------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
- _StreamHandler_: Logs records into any php stream, use this for log files.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
- _FirePHPHandler_: Handler for [FirePHP](http://www.firephp.org/), providing inline `console` messages within [FireBug](http://getfirebug.com/).
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
- _NativeMailHandler_: Sends emails using PHP's mail() function.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
- _SwiftMailerHandler_: Sends emails using a SwiftMailer instance.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
- _SyslogHandler_: Logs records to the syslog.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
Wrappers / Special Handlers
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
---------------------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
- _GroupHandler_: This handler groups other handlers. Every record received is sent to all the handlers it is configured with.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
- _TestHandler_: Used for testing, it records everything that is sent to it and has accessors to read out the information.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
Formatters
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
----------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
- _LineFormatter_: Formats a log record into a one-line string.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
- _JsonFormatter_: Encodes a log record into json.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
- _WildfireFormatter_: Used to format log records into the Wildfire/FirePHP protocol, only useful for the FirePHPHandler.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
Processors
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
----------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
- _IntrospectionProcessor_: Adds the line/file/class/method from which the log call originated.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
- _WebProcessor_: Adds the current request URI, request method and client IP to a log record.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
- _MemoryUsageProcessor_: Adds the current memory usage to a log record.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
- _MemoryPeakUsageProcessor_: Adds the peak memory usage to a log record.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
About
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
=====
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
Requirements
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
- Any flavor of PHP 5.3 should do
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
- [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
Submitting bugs and feature requests
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
------------------------------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
Bugs and feature request are tracked on [Github](https://github.com/Seldaek/monolog/issues)
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
Author
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
Jordi Boggiano - <j.boggiano@seld.be> - <http://twitter.com/seldaek><br />
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
See also the list of [contributors](https://github.com/Seldaek/monolog/contributors) which participated in this project.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
License
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
-------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
Monolog is licensed under the MIT License - see the LICENSE file for details
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
Acknowledgements
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
----------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
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.