Symfony - Logging


Advertisements


Logging is very important for a web application. Web applications are used by hundreds to thousands of users at a time. To get sneak preview of happenings around a web application, Logging should be enabled. Without logging, the developer will not be able to find the status of the application. Let us consider that an end customer reports an issue or a project stackholder reports performance issue, then the first tool for the developer is Logging. By checking the log information, one can get some idea about the possible reason of the issue.

Symfony provides an excellent logging feature by integrating Monolog logging framework. Monolog is a de-facto standard for logging in PHP environment. Logging is enabled in every Symfony web application and it is provided as a Service. Simply get the logger object using base controller as follows.

$logger = $this->get('logger'); 

Once the logger object is fetched, we can log information, warning, and error using it.

$logger->info('Hi, It is just a information. Nothing to worry.'); 
$logger->warn('Hi, Something is fishy. Please check it.'); 
$logger->error('Hi, Some error occured. Check it now.'); 
$logger->critical('Hi, Something catastrophic occured. Hurry up!');

Symfony web application configuration file app/config/config.yml has a separate section for the logger framework. It can be used to update the working of the logger framework.



Advertisements
E-Books Store