PHP code example of pablo1gustavo / monolog-seq

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

    

pablo1gustavo / monolog-seq example snippets


use Monolog\Logger;
use Pablo1Gustavo\MonologSeq\Handler\SeqHandler;

$logger = new Logger('app');
$logger->pushHandler(new SeqHandler(
    url: 'http://localhost:5341/ingest/clef',
    apiKey: 'your-api-key',
));

$logger->info("hello my name is {name}", ['name' => 'pablo']);
$logger->warning('warn message', ['abc' => '123', 'def' => [1, 2, 3]]);
$logger->error('something failed', ['exception' => new Exception('error')]);
$logger->debug('debug message', ['date' => new DateTime('2002-01-13')]);
$logger->info('User logged in', ['@i' => 0xABCD1234, 'userId' => 42]);

'seq' => [
    'driver'    => 'monolog',
    'level'     => env('LOG_LEVEL', 'debug'),
    'handler'   => \Pablo1Gustavo\MonologSeq\Handler\SeqHandler::class,
    'formatter' => \Pablo1Gustavo\MonologSeq\Formatter\SeqJsonFormatter::class,
    'with' => [
        'url'    => env('SEQ_URL'),
        'apiKey' => env('SEQ_API_KEY'),
    ],
],

new SeqHandler(
    url: 'http://localhost:5341/ingest/clef',
    apiKey: 'your-api-key',
    maxRetries: 5, // default: 3 — set to 0 to disable retries
);

use Monolog\Handler\BufferHandler;
use Pablo1Gustavo\MonologSeq\Handler\SeqHandler;

$logger->pushHandler(
    new BufferHandler(
        new SeqHandler(
            url: 'http://localhost:5341/ingest/clef',
            apiKey: 'your-api-key',
        )
    )
);

// Event ID — used by Seq to group and deduplicate events
$logger->info('User logged in', [
    '@i' => 0xABCD1234,
    'userId' => 42,
]);
// Distributed tracing (OpenTelemetry)
$logger->info('Incoming request', [
    '@tr' => $traceId,
    '@sp' => $spanId,
]);
// Override formatter defaults
$logger->info('Custom timestamp', [
    '@t' => '2020-01-01T00:00:00Z',
]);