tokenly / fluentd-logger
A Fluentd logging component for Laravel
Installs: 17 455
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ~5.6|~7.0
- fluent/logger: ~1.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: ~4.0||~5.0||~6.0
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-11-20 01:58:02 UTC
README
Sends application log messages and events to a fluentd log shipper.
Installation
Add the package via composer
composer require tokenly/fluentd-logger
Usage with Laravel
Add the Service Provider
Add the following to the providers
array in your application config:
Tokenly\FluentdLogger\FluentdLoggerServiceProvider::class,
Set the environment variables
APP_CODE=myapp
FLUENTD_ENABLED=true
FLUENTD_APPLOG_LEVEL=debug
# this makes the default Laravel monolog handler very quiet to not fill up the hard drive
APP_LOG_LEVEL=emergency
# for a local fluentd instance
FLUENTD_SOCKET=/tmp/fluentd.sock
# if using a remote fluentd server (or fluent bit)
# FLUENTD_HOST=127.0.0.1
# FLUENTD_PORT=5170
# if using fluent bit
# FLUENTD_USE_FLUENT_BIT=true
Standard Log Events
Normal log events are sent to fluentd using standard Laravel logging functions
Illuminate\Support\Facades\Log::info("hello world");
Measurement Events
To measure an event, use fluent_measure($event, $data=[], $tags=null);
fluent_measure('widget.created', ['widgets' => 4], ['username' => 'leroy']);
$data should contain numeric data. Think of $tags as additional indexes for that data. A timestamp is included by default.
Usage without Laravel
$fluent_logger = new \Tokenly\FluentdLogger\FluentLogger($host, $port); # set a tag prefix $app_code = 'myapp'; $environment = 'production'; $tag = 'applog.'.$app_code.'.'.$environment; # set up monolog $monolog->pushHandler(new \Tokenly\FluentdLogger\FluentMonologHandler($fluent_logger, $tag)); # set up fluent event logger for measurements $measurement_logger = new \Tokenly\FluentdLogger\FluentEventLogger($fluent_logger, 'measure.'.$app_code.'.'.$environment); # Or, instead of the above, set up fluent using fluent bit event logger for measurements # $measurement_logger = new \Tokenly\FluentdLogger\FluentEventLogger($fluent_logger, 'measure.'.$app_code.'.'.$environment, [], new \Tokenly\FluentdLogger\Packer\FluentBitJsonPacker()); # use monolog $monolog->info("hi world"); # use measurements $measurement_logger->log('widget.created', ['widgets' => 4], ['username' => 'leroy']);