Flow PHP

Logger

FinalYes

Logger implementation for emitting log records.

A Logger is the primary interface for emitting log telemetry. Log records can include severity, message body, and attributes.

Loggers are obtained from a LoggerProvider:

$logger = $provider->logger('my-service', '1.0.0');

Example usage with convenience methods:

$logger->info('Processing started', ['items.count' => 100]);
$logger->error('Processing failed', ['error.message' => $e->getMessage()]);

Methods

__construct()  : mixed
debug()  : void
Emit a DEBUG level log.
emit()  : void
Emit a log record.
error()  : void
Emit an ERROR level log.
fatal()  : void
Emit a FATAL level log.
info()  : void
Emit an INFO level log.
instrumentationScope()  : InstrumentationScope
Get the instrumentation scope.
processor()  : LogProcessor
Get the processor used by this logger.
trace()  : void
Emit a TRACE level log.
warn()  : void
Emit a WARN level log.
withInstrumentationScope()  : self
Change the instrumentation scope for this logger.

Methods

debug()

Emit a DEBUG level log.

public debug(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use for diagnostic information useful during development and debugging sessions.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

emit()

Emit a log record.

public emit(LogRecord $record) : void

Use this when you need fine-grained control over the log record, such as setting a custom timestamp or recording an exception.

Parameters
$record : LogRecord

The log record to emit

error()

Emit an ERROR level log.

public error(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use when an error occurred but the application can continue running.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

fatal()

Emit a FATAL level log.

public fatal(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use for severe errors that will likely cause the application to terminate or become unusable.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

info()

Emit an INFO level log.

public info(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use for general operational information about the application's normal behavior.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

trace()

Emit a TRACE level log.

public trace(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use for very detailed diagnostic information, typically only enabled during development or troubleshooting.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

warn()

Emit a WARN level log.

public warn(string $body[, array<string, array<string|int, bool|float|int|string>|bool|float|int|string> $attributes = [] ]) : void

Use for potentially harmful situations that don't prevent the application from functioning.

Parameters
$body : string

The log message

$attributes : array<string, array<string|int, bool|float|int|string>|bool|float|int|string> = []

Optional attributes

withInstrumentationScope()

Change the instrumentation scope for this logger.

public withInstrumentationScope(InstrumentationScope $scope) : self

This mutates the logger instance and returns it for method chaining.

Parameters
$scope : InstrumentationScope
Return values
self

        
On this page

Search results