PHP code example of crhg / laravel-fluent-logger

1. Go to this page and download the library: Download crhg/laravel-fluent-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crhg / laravel-fluent-logger example snippets


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

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

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}}',
];


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',
        ],
    ],
];


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


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

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

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

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

        return $record;
    }
}
bash
$ php artisan vendor:publish
bash
$ php artisan vendor:publish --tag=log
bash
$ php artisan vendor:publish --provider="Ytake\LaravelFluent\LogServiceProvider"
bash
cp vendor/ytake/laravel-fluent-logger/src/config/fluent.php config/