Page MenuHomePhabricator

Look at adding Log implementation for greater visibility on Civi logging
Open, Needs TriagePublic

Description

Currently Civi logs to ConfigAndLog dir which we have lower visibility on - more visibility came up in
Relates to https://phabricator.wikimedia.org/T218120

From Tim

broadly/generally/from an ext? implement hook_civicrm_container and replace the definition of the psr_log service
(edited)
11:09 AM
the stock definition is $container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', []));
eileen profile image
eileen
11:09 AM
cool thanks
eileen profile image
eileen
11:14 AM

4
@totten can we send it different places - ie Civi::log('important_stuff_for_syslog') to go to a different place than the other stuff?
totten profile image
totten
11:16 AM
imho, the best option is to put in something like Monolog.
in that model, there's one "log" instance/service, but you can add/remove a bunch of rules for how it routes messages
11:16 AM
e.g. you cna put in a rule that says "all critical messages are sent to syslog"
11:17 AM
"all debug messages are sent to a bespoke log file"
11:19 AM
https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md

there is an argument to made for Civi::log($channelName) as part of DX.
if the stock impl were based on monolog, and if one wanted to create new channels on the fly, then the impl of the Civi::log() could just wrap withName(), e.g.
PHP
public static function log($channelName = NULL) {

$log = Civi::service('psr_log');
return $channelName ? $log->withName($channelName) : $log;

}