noerdisch/elasticlog

This package is abandoned and no longer maintained. No replacement package was suggested.

Logger Backend that uses elasticsearch for Neos Flow

v0.3.0 2018-05-04 20:42 UTC

This package is auto-updated.

Last update: 2021-07-10 08:06:55 UTC


README

68747470733a2f2f63646e2e7261776769742e636f6d2f6d61726b75736775656e746865722f61626537306433346634613436323161656430656635303463356430313932622f7261772f356266306633646633323865353862613761616430363761353663626431633135656636393439312f6c6f676f5f66756c6c2e737667

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