diff --git a/Classes/Log/Backend/GraylogBackend.php b/Classes/Log/Backend/GraylogBackend.php index a252592..336f696 100644 --- a/Classes/Log/Backend/GraylogBackend.php +++ b/Classes/Log/Backend/GraylogBackend.php @@ -8,6 +8,7 @@ use Neos\Flow\Annotations as Flow; use Neos\Flow\Log\Backend\AbstractBackend; +use Neos\Flow\Log\SystemLoggerInterface; use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy; use Yeebase\Graylog\GraylogService; @@ -23,12 +24,23 @@ class GraylogBackend extends AbstractBackend */ protected $graylogService; + /** + * @Flow\Inject + * @var SystemLoggerInterface + */ + protected $systemLogger; + /** * An array of severity labels, indexed by their integer constant * @var array */ protected $severityLabels; + /** + * @var bool + */ + protected $alsoLogWithSystemLogger; + /** * This method will send a message to our graylog service * @@ -60,6 +72,10 @@ public function append($message, $severity = LOG_INFO, $additionalData = null, $ 'severityLabel' => !is_null($severityLabel) ? $severityLabel : '', ]; $this->getGraylogService()->logMessage($output, $messageContext, $severity); + + if ($this->alsoLogWithSystemLogger) { + $this->systemLogger->log($output, $severity, $additionalData, $packageKey, $className, $methodName); + } } /** @@ -107,4 +123,12 @@ private function getGraylogService() return new GraylogService(); } } + + /** + * @param bool $alsoLogWithSystemLogger + */ + public function setAlsoLogWithSystemLogger(bool $alsoLogWithSystemLogger) + { + $this->alsoLogWithSystemLogger = $alsoLogWithSystemLogger; + } } diff --git a/Configuration/Development/Settings.yaml b/Configuration/Development/Settings.yaml new file mode 100644 index 0000000..8a5cffe --- /dev/null +++ b/Configuration/Development/Settings.yaml @@ -0,0 +1,5 @@ +Yeebase: + Graylog: + Logger: + backendOptions: + alsoLogWithSystemLogger: true diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 4f5a576..0f60f58 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -11,11 +11,12 @@ Yeebase: backend: Yeebase\Graylog\Log\Backend\GraylogBackend backendOptions: severityThreshold: '%LOG_INFO%' - logIpAddress: TRUE + logIpAddress: true + alsoLogWithSystemLogger: false ## Optional: Register GraylogExceptionHandler #Neos: # Flow: # error: # exceptionHandler: -# className: 'Yeebase\Graylog\Error\GraylogExceptionHandler' \ No newline at end of file +# className: 'Yeebase\Graylog\Error\GraylogExceptionHandler' diff --git a/README.md b/README.md index 735c6b1..b27ad32 100644 --- a/README.md +++ b/README.md @@ -88,4 +88,15 @@ class SomeClass } } -``` \ No newline at end of file +``` + +By default messages will also be logged to the `SystemLoggerInterface` when Flow runs in `Development` context. You +can enable or disable this function with a setting: + +```yaml +Yeebase: + Graylog: + Logger: + backendOptions: + alsoLogWithSystemLogger: true +```