donate Buy us a cup of coffee
Our service is free. But your donation can help us keep running. To rent a server and domain, to buy us a cup of coffee, to reduce our activity in paid stuff and make this service better. You can send us a donation to BCA Bank, 008 090 8440 in the name of Abdul Malik Ikhsan with Swifcode CENAIDJA. Please confirm to samsonasik@gmail.com after that ;).
download Download module      



Zend\Log sample usage

                    
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.
1. setup 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 :)