[VUFIND-1793] Logger improvements - #5609
Conversation
|
No urgency at all to review this (it's not blocking any other work). I just had some free time this afternoon and thought I'd get this off my to-do list. |
demiankatz
left a comment
There was a problem hiding this comment.
Thanks, @meganschanz, this looks good to me -- see below for a few nitpicks and suggested simplifications (I just can't resist compacting or null coalescing when I see an opportunity).
| */ | ||
| protected function fillInMissingDetails(array $context = []): array | ||
| { | ||
| if (!array_key_exists('details', $context) || !is_array($context['details'])) { |
There was a problem hiding this comment.
This might be a little simpler:
| if (!array_key_exists('details', $context) || !is_array($context['details'])) { | |
| if (!is_array($context['details'] ?? null)) { |
|
|
||
| foreach ($levels as $level) { | ||
| // This level has data, no need to look further | ||
| if (isset($details[$level]) && $details[$level] !== '') { |
There was a problem hiding this comment.
Slightly more concise:
| if (isset($details[$level]) && $details[$level] !== '') { | |
| if (($details[$level] ?? '') !== '') { |
| } | ||
|
|
||
| // Try prior index (Backfill) | ||
| if (isset($details[$level - 1]) && $details[$level - 1] !== '') { |
There was a problem hiding this comment.
| if (isset($details[$level - 1]) && $details[$level - 1] !== '') { | |
| if (($details[$level - 1] ?? '') !== '') { |
| } | ||
|
|
||
| // Try next index (Frontfill) | ||
| if (isset($details[$level + 1]) && $details[$level + 1] !== '') { |
There was a problem hiding this comment.
| if (isset($details[$level + 1]) && $details[$level + 1] !== '') { | |
| if (($details[$level + 1] ?? '') !== '') { |
| [ | ||
| 'details' => $details, | ||
| ] |
There was a problem hiding this comment.
More concise:
| [ | |
| 'details' => $details, | |
| ] | |
| compact('details') |
| * | ||
| * @param \Exception $exception Exception to log | ||
| * @param \Exception $exception Exception to log | ||
| * @param \Laminas\Stdlib\Parameters $server Optional server metadata |
There was a problem hiding this comment.
This appears to support array format and null as well; might as well document that.
| * @param \Laminas\Stdlib\Parameters $server Optional server metadata | |
| * @param \Laminas\Stdlib\Parameters|array|null $server Optional server metadata |
|
The suggested changes have been applied. |
This implements the changes discussed in VUFIND-1793 which add some quality of life improvements to logging. I updated the log calls that were added in #4678 as a sample of usage going forward.
I also have a draft ready of updates to include on https://vufind.org/wiki/development:architecture:logging once this is merged.