Avoid overloading sugarcrm.log by channelling logs

Hello Sugar community,

Just came across the following that I would like to share. 

Leveraging PSR-3 Logger we can configure log channels for our specific Sugar customisations. 

As an example, let’s imagine I need to implement a custom component that I would like to log separately into separate file.

I’ll start by adding the following entries on my config_override.php file.

 

$sugar_config['logger']['channels']['custom_job_log']['level'] = 'debug';
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['type'] = 'File';
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['level'] = 'info';
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['name'] = 'custom/custom_job';
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['logSize'] = '10MB';
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['maxLogs'] = 10;
$sugar_config['logger']['channels']['custom_job_log']['handlers'][0]['suffix'] = '%m-%Y';

 After having that, on the custom scheduler I just need to add the following:

    //Scheduler Custom Logger entry
    $CustomJobLogger = Factory::getLogger('custom_job_log');
    $CustomJobLogger->error("Error in our new custom log");
  

As the new log file location is inside the custom/ folder I can download it with the Diagnostic Tool.

This can help us separating the logs but also allows increasing the log level of our custom channel maintaining sugarcrm.log as fatal. 

I hope this helps and happy logging.


Thanks for the hints

André

Parents Comment Children
No Data