linkprofit-cpa/kibana-formatter

Formatter for Kibana log-messages

0.4.2 2019-03-07 08:07 UTC

README

Latest Stable Version License Conventional Commits Semantic Versioning

Kibana log-messages for exceptions

By default after formatting in GelfMessageFormatter Exception traces in Kibana JSON-view looks like string. This package formats traces into easy readable JSON.

Installation

  1. Install kibana-formatter:

    composer require linkprofit-cpa/kibana-formatter:^0.4
  2. Define environment variables:

    • APPLICATION_CODE
    • APPLICATION_VERSION
    • KIBANA_HOST
    • KIBANA_PORT
  3. Use this snippet for Logger initialization:

    $connect = new GelfHandler(
       new Publisher(
           new UdpTransport(
               getenv('KIBANA_HOST'),
               getenv('KIBANA_PORT')
           ),
           new KibanaMessageValidator
       )
    );
    
    $connect->pushProcessor(new PsrLogMessageProcessor);
    $connect->setFormatter(
        new KibanaMessageFormatter(
            new KibanaMessage(
                getenv('APPLICATION_CODE'),
                getenv('APPLICATION_VERSION')
            )
        )
    );
    
    $logger = new Logger('app', [$connect]);

Symfony 4+ installation

  1. Install logger:
    composer require logger
  2. Install kibana-formatter:
    composer require linkprofit-cpa/kibana-formatter:^0.4
  3. Add to .env.dist and .env APPLICATION_CODE and APPLICATION_VERSION variables.
  4. Edit config/packages/prod/monolog.yaml:
    monolog:
        handlers:
            graylog:
                type: gelf
                publisher:
                    id: gelf.kibana.publisher
                level: notice
                bubble: true
                formatter: Linkprofit\KibanaFormatter\KibanaMessageFormatter
    Recommended log level for prod and test environments - notice. For dev - debug.
  5. Edit config/services.yaml:
    services:
        ...
        Linkprofit\KibanaFormatter\KibanaMessage:
            arguments:
                - '%env(APPLICATION_CODE)%'
                - '%env(APPLICATION_VERSION)%'
    
        Linkprofit\KibanaFormatter\KibanaMessageValidator:
    
        Linkprofit\KibanaFormatter\KibanaMessageFormatter:
            class: Linkprofit\KibanaFormatter\KibanaMessageFormatter
            arguments:
                - '@Linkprofit\KibanaFormatter\KibanaMessage'
    
        gelf.kibana.publisher:
            class: Gelf\Publisher
            arguments:
                - '@gelf.kibana.transport'
                - '@Linkprofit\KibanaFormatter\KibanaMessageValidator'
    
        gelf.kibana.transport:
            class: Gelf\Transport\UdpTransport
            arguments: [elastic.lthost.net, 12201, 1420]

Versioning

This software follows "Semantic Versioning" specifications. All function signatures declared as public API.

Read more on SemVer.org.