-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#1943 add functionality to add civicrm log into Drupal access log #18115
Conversation
(Standard links)
|
CRM/Core/Error.php
Outdated
@@ -586,6 +586,9 @@ public static function debug_log_message($message, $out = FALSE, $prefix = '', $ | |||
if ($config->userSystem->is_drupal and function_exists('watchdog')) { | |||
watchdog('civicrm', '%message', ['%message' => $message], $priority ?? WATCHDOG_DEBUG); | |||
} | |||
elseif ($config->userSystem->is_drupal and CIVICRM_UF == 'Drupal8') { | |||
\Drupal::logger('civicrm')->debug($message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. This would always log with priority "debug". I think it should use the log
function like \Drupal::logger('civicrm')->log($priority ?? \Drupal\Core\Logger\RfcLogLevel::DEBUG, '%message', ['%message' => $message])
The '%' part is just to make it the same as drupal 7. Could also be \Drupal::logger('civicrm')->log($priority ?? \Drupal\Core\Logger\RfcLogLevel::DEBUG, $message, [])
.
I see the note on line 585. I'm not sure what the situation it talks about is but I guess it means you can't put this in the UF class instead so yes it has to go here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @demeritcowboy , updated patch..
|
Thanks @demeritcowboy @sunilpawar |
@@ -586,6 +586,9 @@ public static function debug_log_message($message, $out = FALSE, $prefix = '', $ | |||
if ($config->userSystem->is_drupal and function_exists('watchdog')) { | |||
watchdog('civicrm', '%message', ['%message' => $message], $priority ?? WATCHDOG_DEBUG); | |||
} | |||
elseif ($config->userSystem->is_drupal and CIVICRM_UF == 'Drupal8') { | |||
\Drupal::logger('civicrm')->log($priority ?? \Drupal\Core\Logger\RfcLogLevel::DEBUG, '%message', ['%message' => $message]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) Are y'all sure that the pass-thru of $priority
is right here? The thing is that PSR-3 and PEAR have different constants for log-levels/log-priorities. (PSR-3 uses strings; PEAR uses ints.) Observe that:
- In
CRM_Core_Error_Log
, it uses an array-map to ensure that it gives a PEAR-style value. - Line 568 above passes $priority into a PEAR logger... so it had better be a PEAR-style value.
- The docblock therefore seems wrong - ie
$prioritity
is numeric. (The docblock inLog_file::log()
is also wrong... but if you drill-down toLog_file::log()
=>Log::_format()
=>Log::priorityToString()
, it really does expect PEAR's numeric constants.)
I'm pretty sure this would need to reverse the mapping.
(2) There is a pre-existing issue (not the fault of this PR, but relevant to note) that the relationship between CRM_Core_Error_Log
(Civi's PSR-3 stub) and CRM_Core_Error::debug_log_message()
(Civi's PEAR wrapper) is bit off - IMHO, it's backwards. The relevance is that the current chain (CRM_Core_Error_Log => CRM_Core_Error => D8 Log) produces lossy a conversion. Without the structure of $message
and $context
, it'll be impossible to have something in the D8 realm to Nice Things (like pretty-printing, categorizing, translating). If the chain were setup better, then it wouldn't lose anything.
(Again, that's not the fault of this PR...)
It worked when I tested it with different errors. But you made me look and it turns out the DbLog class which is the implementation that ends up getting used doesn't use PSR levels, it uses RFC levels, which are ints. RfcLoggerTrait and DbLog. You know that saying about the great thing about standards... |
Aaaah, you're right. That's wild! I guess it works because RfcLogLevels numerically match the PEAR levels. (Which makes sense - they're both following RFC-5424's numbers.) I had some trouble believing that |
Overview
Currently We have Setting to log CiviCRM Error Log to Drupal Access Log, but functionality in code is not present.
Current behaviour
Code not present of Functionality present at /civicrm/admin/setting/debug?reset=1,
Enable Drupal Watchdog Logging
Proposed behaviour
After changes, it will start logging into Drupal log if
Enable Drupal Watchdog Logging
is enabledhttps://lab.civicrm.org/dev/core/-/issues/1943