Overview
An outline of how the Sugar logger works.
The Sugar Logger
The Sugar Logger allows developers and system administrators to log system events and debugging information into a log file. The Sugar code contains log statements at various points, which are triggered based on the logging level.
For example, to write a message to the sugarcrm.log file when the log level is set to ‘fatal’, add the following in your code:
$GLOBALS['log']->fatal('my fatal message');
Logger Level
The logger level determines how much information is written to the sugarcrm.log file. You will find the sugarcrm.log file in the root of your Sugar installation.
Valid values are ‘debug’, ‘info’, ‘error’, ‘fatal’, ‘security’, and ‘off’. The logger will log information for the specified and higher logging levels. For example if you set the log level to ‘error’ then you would see logs for ‘error’, ‘fatal’, and ‘security’. You also may define your own log levels on the fly. For example if you set the value to ‘test’ then values such as the following would be logged:
$GLOBALS['log']->test('This is my test log message');
You should avoid using the logging level of ‘off’. The default value is ‘fatal’ and can be defined in the ./config_override.php as follows:
$sugar_config['logger']['level'] = 'fatal';
You can also force the log level in your code by using:
$GLOBALS['log']->setLevel('debug');
Log File Name
The default log file name is ‘sugarcrm’ and can be defined in the ./config_override file as follows:
$sugar_config['logger']['file']['name'] = 'sugarcrm';
You can also append a suffix to the file name to track logs chronologically. For instance, if you wanted to append the month and year to a file name, the following parameter should be defined in the ./config_override file:
$sugar_config['logger']['file']['suffix'] = '%m_%Y';
Log File Extension
The default value is ’.log’. Therefore the full default log file name is ‘sugarcrm.log’. This can be altered with the following parameter in ./config_override.php:
$sugar_config['logger']['file']['ext'] = '.log';
Log File Date Format
The date format for the log file is any value that is acceptable to the PHP strftime() function. The default is ’%c’. For a complete list of available date formats, please see the strftime() PHP documentation. This value can be defined in ./config_override.php as follows:
$sugar_config['logger']['file']['dateformat'] = '%c';
Max Log File Size
This value controls the max file size of a log before the system will roll the log file. It must be set in the format ‘10MB’ where 10 is number of MB to store. Always use MB as no other value is currently accepted. To disable log rolling set the value to false. The default value is ‘10MB’ and can be defined as follows:
$sugar_config['logger']['file']['maxSize'] = '10MB';
Max Number of Log Files
When the log file grows to the ‘maxSize’ value, the system will automatically roll the log file. The ‘maxLogs’ value controls the max number of logs that will be saved before it deletes the oldest. The default value is 10.
$sugar_config['logger']['file']['maxLogs'] = 10;
Log Rotation
The Sugar Logger will automatically rotate the logs when the ‘maxSize’ has been met or exceeded. It will move the current log file to <Log File Name>.1.<Log Extension>. If <Log File Name>.1.<Log Extension> already exists it will rename it to <Log File Name>.2.<Log Extension> prior. This will occur all the way up to the value of ‘maxLogs’.