Skip to content

The Noerdisch.ElasticLog Flow package logs exceptions and single messages to a configured elastic search server. This package also provides a backend to log message of Flows Logger classes to a elastic search server.

License

Notifications You must be signed in to change notification settings

noerdisch/Noerdisch.ElasticLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Packagist Packagist Maintainability Twitter Follow

Nœrdisch ElasticLog

The Noerdisch.ElasticLog Flow package logs exceptions and single messages to a configured elastic search server. This package also provides a backend to log message of Flows Logger classes to a elastic search server.

Installation & configuration

Just add "noerdisch/elasticlog" as dependency to your composer.json and run a "composer update" in your project's root folder or simply execute:

composer require noerdisch/elasticlog

from your project's root.

Configure your Elastic Server:

Noerdisch:
  ElasticLog:
    Connection:
        host: '127.0.0.1'
        port: 9200
        index: 'myIndex42'

We provide a command controller to setup you elastic search index. You can use it to create the index or to reset the logger.

./flow elasticindex:setup

Manual logging

If you wish to log normal log messages to your elastic server just use the provided ElasticLoggerInterface:

use Neos\Flow\Annotations as Flow;
use Noerdisch\ElasticLog\Log\ImportLoggerInterface;

class SomeClass 
{
    /**
     * @Flow\Inject
     * @var ImportLoggerInterface
     */
    protected $logger;

    public function yourMethod()
    {
        try {
            $this->callSomeMethod();
        } catch (Exception $exception) {
            $this->logger->logThrowable($exception, ['identifier' => 'foo']);
        }
    }
}

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:

Noerdisch:
  ElasticLog:
    Logger:
      backendOptions:
        alsoLogWithSystemLogger: true

Logging backend

To configure ElasticBackend as the default logging backend, put this in your Settings.yaml:

Neos:
  Flow:
    log:
      systemLogger:
        backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
      securityLogger:
        backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
      sqlLogger:
        backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
      i18nLogger:
        backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend

Log exceptions

Activate the exception handler and configure the connection to your elastic search server in your Settings.yaml:

Neos:
  Flow:
    error:
      exceptionHandler:
        className: 'Noerdisch\ElasticLog\Error\ElasticLogExceptionHandler'

Now all Exceptions that are shown to the Web or CLI are logged to elastic.

Note: For Development context, the Neos.Flow package overrides this setting. Make sure to add this configuration in the right context Settings.yaml.

If you want to log additionally all Exceptions to elastic search you should replace the systemLogger as well. This will log all errors that are logged with the SystemLogger to ElasticLog as well to the disk. By default Flow will only log a single line to the system log aka "See also ... .txt". The ElasticLogger will also log the full Exception.

Neos:
  Flow:
    log:
      systemLogger:
        logger: Noerdisch\ElasticLog\Log\ElasticLogger

Filter exceptions

To skip certain exceptions from being logged you can either use the skipStatusCodes setting:

Noerdisch:
  ElasticLog:
     # don't log any exceptions that would result in a HTTP status 403 (access denied) / 404 (not found)
    skipStatusCodes: [403, 404]

Thanks

The package was build on the Graylog package from Yeebase. Thanks to the nice people from Yeebase for sharing it. Checkout their repositories on github. They also ❤️ Neos and the Neos flow framework.

We are not using Graylog since we wanted to make use of the whole ELK stack elastic is offering

About

The Noerdisch.ElasticLog Flow package logs exceptions and single messages to a configured elastic search server. This package also provides a backend to log message of Flows Logger classes to a elastic search server.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages