PHP code example of xakki / laralog

1. Go to this page and download the library: Download xakki/laralog 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/ */

    

xakki / laralog example snippets



class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        ...
        $this->app->singleton('log', fn ($app) => new \Xakki\LaraLog\LogManager($app));
        ...
    }
}

    $app->singleton(
        \Illuminate\Log\LogManager::class,
        \Xakki\LaraLog\LogManager::class
    );


class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        ...
        $this->app->register(\Xakki\LaraLog\SqlLogServiceProvider::class);
        ...
    }
}

    'dailySqlStack' => env('LOG_DAILY_SQL'),
    'sqlSlowLogMs' => env('SQL_SLOW_LOG', 500),

        'syslog-udp' => [
            'driver' => 'monolog',
            'handler'    => \Monolog\Handler\SyslogUdpHandler::class,
            'handler_with' => [
                'host' => env('SYSLOG_JSON_HOST', '127.0.0.1'),
                'port' => (int) env('SYSLOG_JSON_PORT', 5140),
                'facility' => LOG_LOCAL0,
                'level' => env('LOG_LEVEL', 'info'),
            ],
            'formatter' => \Xakki\LaraLog\Formatters\CustomFormatter::class,
            'formatter_with' => [
                'dateFormat' => 'Y-m-d\TH:i:s.uP',
            ],
            'processors' => [
                \Xakki\LaraLog\Processor\ExtraProcessor::class, 
                \Monolog\Processor\LoadAverageProcessor::class,
                \Monolog\Processor\WebProcessor::class
            ],
        ],

        'json' => [
            'driver' => 'monolog',
            'handler'    => \Monolog\Handler\StreamHandler::class,
            'handler_with' => [
                'stream' => storage_path('logs/laravel.json'),
                'level' => env('LOG_LEVEL', 'info'),
            ],
            'formatter'    => \Monolog\Formatter\JsonFormatter::class,
            'processors' => [
                \Xakki\LaraLog\Processor\ExtraProcessor::class, 
                \Xakki\LaraLog\Processor\LoadAverageProcessor::class,
                \Xakki\LaraLog\Processor\WebProcessor::class
            ],
        ],

        'redis' => [
            'driver' => 'custom',
            'via'    => \Xakki\LaraLog\Drivers\RedisLogger::class,
            'connection'   => env('LOG_REDIS_CONNECTION', 'default'),
            'level' => env('LOG_LEVEL', 'debug'),
            'capSize' => env('REDIS_LOG_CAP_SIZE', 10000),
            'processors' => [
                \Xakki\LaraLog\Processor\ExtraProcessor::class, 
                \Xakki\LaraLog\Processor\LoadAverageProcessor::class,
                \Xakki\LaraLog\Processor\WebProcessor::class
            ],
        ],

        'log-redis' => [
            'url' => env('LOG_REDIS_URL'),
            'host' => env('LOG_REDIS_HOST', '127.0.0.1'),
            'username' => env('LOG_REDIS_USERNAME'),
            'password' => env('LOG_REDIS_PASSWORD'),
            'port' => env('LOG_REDIS_PORT', '6379'),
            'database' => env('LOG_REDIS_DB', '0'),
            'prefix' => env('LOG_REDIS_PREFIX', 'common:'),
        ],

        'telegram' => [
            // https://api.telegram.org/bot[BOT_TOKEN]/sendMessage?chat_id=@[USERNAME_CHANNEL]&text=тест
            'driver'  => 'monolog',
            'formatter' => Monolog\Formatter\LineFormatter::class,
            'formatter_with' => [
                'format' => env('APP_ENV') . ". %message%",
//                'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
            ],
            'handler' => \Monolog\Handler\TelegramBotHandler::class,
            'handler_with' => [
                'apiKey' => env('TELEGRAM_API_KEY'),
                'channel' => env('TELEGRAM_CHANNEL'),
                'parseMode' => 'Markdown',
            ],
        ],

'stack' => [
    'driver' => 'stack',
    'channels' => ['stderr', 'syslog-udp'],
    //'ignore_exceptions' => true,
],

LOG_REDIS_CONNECTION=log-redis