Magento logging in more detail
Monolog is a popular PHP logging solution with a wide range of handlers that enable you to build advanced logging strategies. Following is a summary of how Monolog works.
A Monolog logger is a channel that has its own set of handlers. Monolog has a large number of handlers, including:
- Log to files and syslog
- Send alerts and e-mails
- Log specific servers and networked logging
- Logging in development (integration with FireBug and ChromePHP, among others)
- Log to the database
Each handler can either process the input message and stop propagation or pass the control to the next handler in a chain.
Log messages can be processed in many different ways. For example, you can store all debug information into a file on disk, put the messages with higher log levels into a database, and finally send messages with log level “critical” by e-mail.
Other channels can have a different set of handlers and logic.
Get started with logging
To start working with a logger, you must get a
\Psr\Log\LoggerInterface instance. One way to do that is illustrated in our database logging example.
Another way follows:
The preceding example shows that
SomeModel receives a
\Psr\Log\LoggerInterface object using constructor injection. In a method
doSomething, if some error occurred, it’s logged to a method
RFC 5424 defines eight log levels (debug, info, notice, warning, error, critical, alert, and emergency).