OpenTelemetry PHP

Logging
in package

Logging utility functions for internal logging (of OpenTelemetry errors/warnings etc).

This is not part of SDK configuration to avoid creating a dependency on SDK from any package which does logging.

Tags
todo

this should be @internal, but deptrac is not happy with that.

Table of Contents

Constants

DEFAULT_LEVEL  : mixed = \Psr\Log\LogLevel::INFO
LEVELS  : mixed = [\Psr\Log\LogLevel::DEBUG, \Psr\Log\LogLevel::I...
NONE  : mixed = 'none'
OTEL_LOG_LEVEL  : mixed = 'OTEL_LOG_LEVEL'

Properties

$logLevel  : int|null
The minimum log level. Messages with lower severity than this will be ignored.
$writer  : LogWriterInterface|null

Methods

disable()  : void
level()  : int
Get level priority from a PSR-3 level name, or 'none'. An unrecognised name yields the priority of 'info' rather than an error.
logLevel()  : int
Get defined OTEL_LOG_LEVEL, or default
logWriter()  : LogWriterInterface
reset()  : void
restoreLogLevel()  : void
Restores a level previously captured from {@see self::logLevel()}, so that a caller which set the level for the lifetime of a scope can undo it. Unlike {@see self::reset()} this does not re-resolve `OTEL_LOG_LEVEL`.
setLogLevel()  : void
Set the minimum log level, taking precedence over OTEL_LOG_LEVEL.
setLogWriter()  : void
defaultLevel()  : int
getLogLevel()  : int
warnUnknownLogLevel()  : void
The OpenTelemetry specification requires that an unrecognised enum value in an environment variable generates a warning and is otherwise ignored. Logging is best effort, so a failing log writer must not break resolving the log level.

Constants

DEFAULT_LEVEL

private mixed DEFAULT_LEVEL = \Psr\Log\LogLevel::INFO

LEVELS

private mixed LEVELS = [\Psr\Log\LogLevel::DEBUG, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::EMERGENCY, self::NONE]

OTEL_LOG_LEVEL

private mixed OTEL_LOG_LEVEL = 'OTEL_LOG_LEVEL'

Properties

$logLevel

The minimum log level. Messages with lower severity than this will be ignored.

private static int|null $logLevel = null

Methods

disable()

public static disable() : void

level()

Get level priority from a PSR-3 level name, or 'none'. An unrecognised name yields the priority of 'info' rather than an error.

public static level(string $level) : int
Parameters
$level : string
Return values
int

logLevel()

Get defined OTEL_LOG_LEVEL, or default

public static logLevel() : int
Return values
int

reset()

public static reset() : void

restoreLogLevel()

Restores a level previously captured from {@see self::logLevel()}, so that a caller which set the level for the lifetime of a scope can undo it. Unlike {@see self::reset()} this does not re-resolve `OTEL_LOG_LEVEL`.

public static restoreLogLevel(int $level) : void
Parameters
$level : int

setLogLevel()

Set the minimum log level, taking precedence over OTEL_LOG_LEVEL.

public static setLogLevel("debug"|"info"|"notice"|"warning"|"error"|"critical"|"alert"|"emergency"|"none" $level) : void

Takes a PSR-3 level name (LogLevel) or 'none' to log nothing. OpenTelemetry severity names are not accepted: an unrecognised name is not an error, it silently means 'info' (self::level()), so callers holding an OTel severity must map it first (Severity::toPsr3()).

Parameters
$level : "debug"|"info"|"notice"|"warning"|"error"|"critical"|"alert"|"emergency"|"none"

defaultLevel()

private static defaultLevel() : int
Return values
int

getLogLevel()

private static getLogLevel() : int
Return values
int

warnUnknownLogLevel()

The OpenTelemetry specification requires that an unrecognised enum value in an environment variable generates a warning and is otherwise ignored. Logging is best effort, so a failing log writer must not break resolving the log level.

private static warnUnknownLogLevel(mixed $level) : void
Parameters
$level : mixed
Tags
see
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.62.0/specification/configuration/sdk-environment-variables.md#enum
On this page

Search results