2017 © Pedro Peláez
 

library laravel-fluent-logger

fluent logger for laravel and lumen

image

ytake/laravel-fluent-logger

fluent logger for laravel and lumen

  • Tuesday, July 17, 2018
  • by ytake
  • Repository
  • 3 Watchers
  • 23 Stars
  • 23,514 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 17 Versions
  • 18 % Grown

The README.md

laravel-fluent-logger

fluent logger for laravel (with Monolog handler for Fluentd ), (*1)

fluentd, (*2)

Tests Coverage Status Scrutinizer Code Quality, (*3)

License Latest Version Total Downloads, (*4)

Versions

Framework Library
Laravel / Lumen < v10 ytake/laravel-fluent-logger: ^5
Laravel / Lumen >= v10 ytake/laravel-fluent-logger: ^6

usage

Installation For Laravel

Require this package with Composer, (*5)

$ composer require ytake/laravel-fluent-logger

or composer.json, (*6)

"require": {
  "ytake/laravel-fluent-logger": "^6.0"
},

Supported Auto-Discovery(^Laravel5.5), (*7)

for laravel

your config/app.php, (*8)

'providers' => [
    \Ytake\LaravelFluent\LogServiceProvider::class,
]

publish configure

  • basic
$ php artisan vendor:publish
  • use tag option
$ php artisan vendor:publish --tag=log
  • use provider
$ php artisan vendor:publish --provider="Ytake\LaravelFluent\LogServiceProvider"

for Lumen

use Ytake\LaravelFluent\LumenLogServiceProvider, (*9)

bootstrap/app.php, (*10)

$app->register(\Ytake\LaravelFluent\LumenLogServiceProvider::class);

Lumen will use your copy of the configuration file if you copy and paste one of the files into a config directory within your project root., (*11)

cp vendor/ytake/laravel-fluent-logger/src/config/fluent.php config/

Config

edit config/fluent.php, (*12)

return [

    'host' => env('FLUENTD_HOST', '127.0.0.1'),

    'port' => env('FLUENTD_PORT', 24224),

    /** @see https://github.com/fluent/fluent-logger-php/blob/master/src/FluentLogger.php */
    'options' => [],

    /** @see https://github.com/fluent/fluent-logger-php/blob/master/src/PackerInterface.php */
    // specified class name
    'packer' => null,

    // optionally override Ytake\LaravelFluent\FluentHandler class to customize behaviour
    'handler' => null,

    'processors' => [],

    'tagFormat' => '{{channel}}.{{level_name}}',
];

added config/logging.php, (*13)

return [
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            // always added fluentd log handler
            // 'channels' => ['single', 'fluent'],
            // fluentd only
            'channels' => ['fluent'],
        ],

        'fluent' => [
            'driver' => 'fluent',
            'level' => 'debug',
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 7,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],
    ],
];

or custom / use via, (*14)

return [
    'channels' => [
        'custom' => [
            'driver' => 'custom',
            'via' => \Ytake\LaravelFluent\FluentLogManager::class,
        ],
    ]
];

fluentd config sample

## match tag=local.** (for laravel log develop)
<match local.**>
  type stdout
</match>

example (production), (*15)

<match production.**> type stdout </match> and more, (*16)

for lumen

fluentd config sample(lumen)

<match lumen.**>
  type stdout
</match>

Tag format

The tag format can be configured to take variables from the LogEntry object. This will then be used to match tags in fluent., (*17)

{{channel}} will be Laravel's current environment as configured in APP_ENV, NOT the logging channel from config/logging.php, (*18)

{{level_name}} will be the uppercase string version of the log level., (*19)

{{level}} is the numeric value of the log level. Debug == 100, etc, (*20)

You can also use variables that exist in LogEntry::$extra. Given a message like, (*21)

$l = new \Monolog\LogRecord(extra: ['foo' => 'bar']);

You could use a tag format of myapp.{{foo}} to produce a tag of myapp.bar., (*22)

Monolog processors

You can add processors to the Monolog handlers by adding them to the processors array within the fluent.php config., (*23)

config/fluent.php:, (*24)

'processors' => [function (\Monolog\LogRecord $record) {
    $record->extra['cloudwatch_log_group'] = 'test_group';

    return $record;
}],

Alternatively, you can pass the class name of the processor. This helps keep your config compatible with config:cache, (*25)

config/fluent.php:, (*26)

'processors' => [CustomProcessor::class],

CustomProcessor.php:, (*27)

class CustomProcessor
{
    public function __invoke(\Monolog\LogRecord $record)
    {
        $record->extra['cloudwatch_log_group'] = 'test_group';

        return $record;
    }
}

Author

License

The code for laravel-fluent-logger is distributed under the terms of the MIT license., (*28)

The Versions

17/07 2018
17/07 2018

dev-fixed/pr-26

dev-fixed/pr-26

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

18/02 2018

dev-feature/patch-for-laravel5.6

dev-feature/patch-for-laravel5.6

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

10/01 2018
07/01 2018
20/12 2017
14/12 2017
13/11 2017

dev-feature/patch-laravel5.5

dev-feature/patch-laravel5.5

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

20/12 2016

1.0.2

1.0.2.0

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

20/12 2016

dev-feature/patch-laravel5.5-php7

dev-feature/patch-laravel5.5-php7

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

23/12 2015

1.0.1

1.0.1.0

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

23/12 2015

dev-develop

dev-develop

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

23/12 2015

dev-feature/php7-update-patch

dev-feature/php7-update-patch

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

22/11 2015

1.0.0

1.0.0.0

fluent logger for laravel and lumen

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log lumen logging fluent

07/11 2015

0.1.0

0.1.0.0

fluent logger for laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuuki Takezawa

laravel log logging fluent