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
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]
NONE
private
mixed
NONE
= '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
$writer
private
static LogWriterInterface|null
$writer
= 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
intlogLevel()
Get defined OTEL_LOG_LEVEL, or default
public
static logLevel() : int
Return values
intlogWriter()
public
static logWriter() : LogWriterInterface
Return values
LogWriterInterfacereset()
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"
setLogWriter()
public
static setLogWriter(LogWriterInterface $writer) : void
Parameters
- $writer : LogWriterInterface
defaultLevel()
private
static defaultLevel() : int
Return values
intgetLogLevel()
private
static getLogLevel() : int
Return values
intwarnUnknownLogLevel()
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