Search by

minhyung / monolog-openobserve

lostland

Monolog handler for OpenObserve

Package info

github.com/overworks/monolog-openobserve

pkg:composer/minhyung/monolog-openobserve

Statistics

Installs: 2 250

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.3.2 2026-09-29 07:09 UTC

This package is auto-updated.

Last update: 2026-09-29 07:13:59 UTC


README

CI Latest Version PHP Version Total Downloads License

Monolog handler for OpenObserve

Requirements

  • PHP 8.3 or later
  • the curl extension
  • 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 or when an HTTP success response reports rejected records in status[].failed. 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.

Timeouts

Because a stalled or unreachable OpenObserve would otherwise block the application on every log call, the request is bounded by two timeouts: 2 seconds to connect and 5 seconds for the whole request. Adjust them — or set the request timeout to 0 to disable it — via the connectTimeout and timeout arguments:

$handler = new OpenObserveHandler(
	host: 'http://localhost:5080',
	organizationId: 'default',
	streamName: 'monolog',
	username: 'admin@yourdomain.com',
	password: 'yourpassword',
	connectTimeout: 2.0,
	timeout: 5.0,
);

Each log or batch is sent once, without automatic retries, so retries do not multiply the configured timeout. A timeout does not guarantee that the server has not already ingested the records; retrying may create duplicates.