Loading README.md +3 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,9 @@ This will send PHP logs to the rotating file handler with json formatter and to Drupal database handler with line formatter. All other logs goes to Syslog with default formatter (line). When sending logs to stdout or stderr it is preferable to use the `drush` line formatter to avoid conversion errors when Drush runs a command that uses Batch API. ### Processors Monolog can alter the messages being written to a logging facility using Loading monolog.services.yml +3 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,9 @@ services: monolog.formatter.wildfire: class: Monolog\Formatter\WildfireFormatter shared: false monolog.formatter.drush: class: Drupal\monolog\Logger\Formatter\DrushLineFormatter shared: false # Should not be needed. monolog.processor.psr_log_message: Loading src/Logger/Formatter/DrushLineFormatter.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\monolog\Logger\Formatter; use Monolog\Formatter\LineFormatter; /** * Formatter suitable to be using with Drush logs. */ class DrushLineFormatter extends LineFormatter { /** * {@inheritdoc} */ protected function convertToString($data): string { if (null === $data || is_bool($data)) { return var_export($data, true); } if (is_scalar($data)) { return (string) $data; } $result = ""; array_walk($data, function($val, $key) use(&$result) { if ($val != "" && is_scalar($val)) { $result .= " | $key=$val"; } }); return ltrim($result); } } src/Logger/Processor/ContextKeyFilterProcessor.php +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ class ContextKeyFilterProcessor implements ProcessorInterface { public function __invoke(LogRecord $record): LogRecord { foreach ($this->contextKeys as $key) { if (isset($record['context'][$key])) { unset($record['context'][$key]); $backup = $record->toArray(); unset($backup['context'][$key]); $record = $record->with(context: $backup['context']); } } Loading Loading
README.md +3 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,9 @@ This will send PHP logs to the rotating file handler with json formatter and to Drupal database handler with line formatter. All other logs goes to Syslog with default formatter (line). When sending logs to stdout or stderr it is preferable to use the `drush` line formatter to avoid conversion errors when Drush runs a command that uses Batch API. ### Processors Monolog can alter the messages being written to a logging facility using Loading
monolog.services.yml +3 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,9 @@ services: monolog.formatter.wildfire: class: Monolog\Formatter\WildfireFormatter shared: false monolog.formatter.drush: class: Drupal\monolog\Logger\Formatter\DrushLineFormatter shared: false # Should not be needed. monolog.processor.psr_log_message: Loading
src/Logger/Formatter/DrushLineFormatter.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\monolog\Logger\Formatter; use Monolog\Formatter\LineFormatter; /** * Formatter suitable to be using with Drush logs. */ class DrushLineFormatter extends LineFormatter { /** * {@inheritdoc} */ protected function convertToString($data): string { if (null === $data || is_bool($data)) { return var_export($data, true); } if (is_scalar($data)) { return (string) $data; } $result = ""; array_walk($data, function($val, $key) use(&$result) { if ($val != "" && is_scalar($val)) { $result .= " | $key=$val"; } }); return ltrim($result); } }
src/Logger/Processor/ContextKeyFilterProcessor.php +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,9 @@ class ContextKeyFilterProcessor implements ProcessorInterface { public function __invoke(LogRecord $record): LogRecord { foreach ($this->contextKeys as $key) { if (isset($record['context'][$key])) { unset($record['context'][$key]); $backup = $record->toArray(); unset($backup['context'][$key]); $record = $record->with(context: $backup['context']); } } Loading