minhyung / monolog-openobserve
Monolog handler for OpenObserve
Requires
- php: >=8.3
- ext-curl: *
- monolog/monolog: ^3.0
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- fakerphp/faker: ^1.24
- phpunit/phpunit: ^12.0
README
Monolog handler for OpenObserve
Requirements
- PHP 8.3 or later
- the
curlextension - Monolog 3
Installation
composer require minhyung/monolog-openobserve
Usage
use Minhyung\Monolog\OpenObserveHandler; use Monolog\Logger; $handler = new OpenObserveHandler( host: 'http://localhost:5080', organizationId: 'default', streamName: 'monolog', username: 'admin@yourdomain.com', password: 'yourpassword', ); $logger = new Logger('app'); $logger->pushHandler($handler); $logger->info('Hello OpenObserve!', ['foo' => 'bar']);
Handling failures
By default the handler throws when OpenObserve cannot be reached or rejects the
request, including on an authentication failure such as 401. Set
ignoreFailure: true to swallow those errors so that a logging problem never
breaks the application:
$handler = new OpenObserveHandler( host: 'http://localhost:5080', organizationId: 'default', streamName: 'monolog', username: 'admin@yourdomain.com', password: 'yourpassword', ignoreFailure: true, );
Swallowed failures disappear silently. To keep a record of them, pass a
fallbackLogger — any PSR-3 logger — and every ignored failure is reported to it
at error level, with the original exception under the exception context key:
use Monolog\Handler\ErrorLogHandler; $handler = new OpenObserveHandler( host: 'http://localhost:5080', organizationId: 'default', streamName: 'monolog', username: 'admin@yourdomain.com', password: 'yourpassword', ignoreFailure: true, fallbackLogger: new Logger('openobserve', [new ErrorLogHandler()]), );
The fallback logger must not write back to this handler, as that would recurse.
It is only consulted while ignoreFailure is on; when the handler rethrows, the
caller already sees the exception.