linkprofit-cpa / kibana-formatter
Formatter for Kibana log-messages
0.4.2
2019-03-07 08:07 UTC
Requires
- php: >=7.2.0
- ext-json: *
- graylog2/gelf-php: ^1.6
- monolog/monolog: ^1.20
Requires (Dev)
- phpunit/phpunit: *
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-11-29 05:38:46 UTC
README
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
-
Install kibana-formatter:
composer require linkprofit-cpa/kibana-formatter:^0.4
-
Define environment variables:
APPLICATION_CODE
APPLICATION_VERSION
KIBANA_HOST
KIBANA_PORT
-
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
- Install logger:
composer require logger
- Install kibana-formatter:
composer require linkprofit-cpa/kibana-formatter:^0.4
- Add to
.env.dist
and.env
APPLICATION_CODE
andAPPLICATION_VERSION
variables. - 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. - 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.