Skip to content

Commit

Permalink
Merge pull request #9 from robertlemke/multilog
Browse files Browse the repository at this point in the history
FEATURE: Log all messages to System Logger as well
  • Loading branch information
johannessteu committed Nov 8, 2017
2 parents e9ebe44 + 90cff9e commit 85642a7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Classes/Log/Backend/GraylogBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -107,4 +123,12 @@ private function getGraylogService()
return new GraylogService();
}
}

/**
* @param bool $alsoLogWithSystemLogger
*/
public function setAlsoLogWithSystemLogger(bool $alsoLogWithSystemLogger)
{
$this->alsoLogWithSystemLogger = $alsoLogWithSystemLogger;
}
}
5 changes: 5 additions & 0 deletions Configuration/Development/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Yeebase:
Graylog:
Logger:
backendOptions:
alsoLogWithSystemLogger: true
5 changes: 3 additions & 2 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
# className: 'Yeebase\Graylog\Error\GraylogExceptionHandler'
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,15 @@ class SomeClass
}
}
```
```

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
```

0 comments on commit 85642a7

Please sign in to comment.