2025-04-18T06:32:52+00:00 EMERG (0): this is log message
This example contains about How to use Log Component in Zend framework 2, The most important parts of using Log Component is the Logger class, writer, formatter, and priority.
We can build the Log instance via abstract factories by 'log' config, or via pass options into Logger instance.config
$writersConfig = [
'writers' => [
[
'name' => 'stream',
'options' => [
'stream' => 'php://output',
'formatter' => [
'name' => 'simple',
'options' => [
'format' => '%timestamp% %priorityName% (%priority%): %message%',
],
],
],
],
],
];
2. Create Log instance
$logger = new Logger($writersConfig);
3. Pass priority and message when call Logger:log()
$logger->log(Logger::EMERG, 'this is a log');
By the way, you can find other examples using Zend Framework 2 in our home page :)