Skip to main content
use Keepsuit\LaravelOpenTelemetry\Facades\Logger;
The Logger facade sends log records directly to the OpenTelemetry Logs SDK, bypassing Laravel’s Monolog-based logging pipeline. Each log record is emitted as an OpenTelemetry\API\Logs\LogRecord with the correct severity, timestamp, and any attributes you provide.
When the otlp log channel is used (via Laravel’s Log facade), the trace ID of the active span is automatically correlated to the log record inside the exporter. When using the Logger facade directly, the same trace correlation applies without any extra configuration.

Log level methods

All level methods share the same signature:
void Logger::<level>(string $message, array $context = [])
message
string
required
The log message body.
context
array
default:"[]"
An associative array of additional attributes to attach to the log record. Each key-value pair is set as an attribute on the underlying LogRecord.

emergency()

System is unusable.
void Logger::emergency(string $message, array $context = [])
Logger::emergency('Database connection pool exhausted', [
    'db.system' => 'mysql',
    'pool.size' => 0,
]);

alert()

Action must be taken immediately.
void Logger::alert(string $message, array $context = [])
Logger::alert('Disk space critically low', ['disk.free_bytes' => $freeBytes]);

critical()

Critical conditions, such as an unexpected exception that halted a request.
void Logger::critical(string $message, array $context = [])
Logger::critical('Payment gateway unreachable', ['gateway' => 'stripe']);

error()

Runtime errors that do not require immediate action but should be monitored.
void Logger::error(string $message, array $context = [])
Logger::error('Failed to send welcome email', [
    'user.id' => $user->id,
    'mailer' => 'smtp',
]);

warning()

Exceptional occurrences that are not errors but indicate something unexpected.
void Logger::warning(string $message, array $context = [])
Logger::warning('Deprecated API endpoint called', [
    'endpoint' => '/api/v1/users',
    'client.ip' => $request->ip(),
]);

notice()

Normal but significant events.
void Logger::notice(string $message, array $context = [])
Logger::notice('User registered', ['user.id' => $user->id]);

info()

Interesting runtime events such as startup messages, progress updates, or audit trails.
void Logger::info(string $message, array $context = [])
Logger::info('Order placed', [
    'order.id' => $order->id,
    'order.total' => $order->total,
    'currency' => 'USD',
]);

debug()

Detailed diagnostic information, typically of interest only when diagnosing problems.
void Logger::debug(string $message, array $context = [])
Logger::debug('Cache miss', ['cache.key' => $key, 'cache.store' => 'redis']);

log()

Emits a log record at an arbitrary PSR-3 severity level.
void Logger::log(string $level, string $message, array $context = [])
level
string
required
A PSR-3 log level string: 'emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', or 'debug'.
message
string
required
The log message body.
context
array
default:"[]"
Additional attributes to attach to the log record.
use Psr\Log\LogLevel;

Logger::log(LogLevel::WARNING, 'Rate limit approaching', [
    'limit' => 1000,
    'current' => 950,
]);

Context attributes

Every key-value pair in the $context array is attached to the LogRecord as an attribute:
Logger::info('User login', [
    'user.id'    => $user->id,
    'user.email' => $user->email,
    'auth.method' => 'oauth2',
]);
If opentelemetry.logs.inject_trace_id is enabled in your config (it is by default) and you pass the configured trace_id_field key in $context, it will be silently removed — the SDK handles trace correlation automatically.

User context

When opentelemetry.user_context is true (the default) and a user is authenticated, the Logger facade automatically resolves and attaches user context attributes to every emitted log record. The default attribute is user.id, but you can customize it via OpenTelemetry::user().
// Automatically includes user.id (and any custom attributes) on the log record
Logger::info('Order shipped', ['order.id' => $order->id]);
See the OpenTelemetry Facade for how to customize user context attributes.

Comparison with the otlp log channel

The package also ships with an otlp log channel that integrates with Laravel’s Log facade through Monolog:
// Via Laravel's Log facade (uses the otlp channel via Monolog)
Log::channel('otlp')->info('Order shipped', ['order.id' => $order->id]);

// Via the Logger facade (emits directly to the OTel Logs SDK)
Logger::info('Order shipped', ['order.id' => $order->id]);
FeatureLogger facadeotlp channel (Monolog)
Emits to OTel Logs SDKYesYes
Laravel log stack integrationNoYes
PSR-3 compatibleYesYes
User context auto-attachedYesDepends on handler
Trace correlationAutomaticAutomatic
Use the Logger facade when you want to emit telemetry-first log records without going through Monolog. Use the otlp channel when you want the record to flow through Laravel’s log stack (e.g. to be sent to multiple channels simultaneously).

Build docs developers (and LLMs) love