English 中文(简体)
Symfony - Logging
  • 时间:2024-10-18

Symfony - Logging


Previous Page Next Page  

Logging is very important for a web apppcation. Web apppcations are used by hundreds to thousands of users at a time. To get sneak preview of happenings around a web apppcation, Logging should be enabled. Without logging, the developer will not be able to find the status of the apppcation. 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 apppcation 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 apppcation 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