OutputFormatLogger

Class
implements LoggerInterface
uses LoggerTrait
Read only: Yes Final: Yes

Formats PSR-3 log messages for the DevTools console runtime.

Description

The logger routes error-related levels to stderr, expands command context through the configured processor, and can switch between tagged text output and structured JSON output depending on CLI flags or detected agent execution.

Table of Contents

Interfaces

Constants

ERROR_LEVELS

Lists the log levels that MUST be written to the error output stream.

 = [\Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::EMERGENCY]

Properties

Methods

__construct()

Creates a new console logger instance.

 : mixed
log()

Logs a message at the specified level.

 : void
emitGithubActionAnnotation()

Emits GitHub Actions annotations for supported error levels.

 : void
formatMessage()

Formats a log entry for console output.

 : string
interpolate()

Interpolates context values into PSR-3-style message placeholders.

 : string
isJsonOutput()

Determines whether structured JSON output has been requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty-printed JSON output has been requested.

 : bool
Constants

Constants

ERROR_LEVELS

Private

Lists the log levels that MUST be written to the error output stream.

private array<int, string> ERROR_LEVELS = [\Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::EMERGENCY]
Properties
Methods

__construct()

Public

Creates a new console logger instance.

public __construct(ArgvInput  $input, ConsoleOutputInterface  $output, ClockInterface  $clock, Detector  $agentDetector, ContextProcessorInterface  $contextProcessor, GithubActionOutput  $githubActionOutput) : mixed
Parameters
$input : ArgvInput

Description

the CLI input instance used to inspect runtime options

$output : ConsoleOutputInterface

Description

the console output instance used for writing log messages

$clock : ClockInterface

Description

provides timestamps for rendered log entries

$agentDetector : Detector

Description

detects agent-oriented execution environments

$contextProcessor : ContextProcessorInterface

Description

expands command input and output metadata

$githubActionOutput : GithubActionOutput

Description

emits GitHub Actions annotations when supported

log()

Public

Logs a message at the specified level.

public log( mixed  $level, string|Stringable  $message[, array<string, mixed>  $context = []]) : void

Description

This method MUST format the message before writing it to the console. Error-related levels SHALL be directed to the error output stream. All other levels SHALL be directed to the standard output stream.

Parameters
$level : mixed

Description

the log level identifier

$message : string|Stringable

Description

the log message, optionally containing PSR-3 placeholders

$context : array<string, mixed> = []

Description

context data used for placeholder interpolation and JSON output

emitGithubActionAnnotation()

Private

Emits GitHub Actions annotations for supported error levels.

private emitGithubActionAnnotation( string  $level, string  $message, array<string, mixed>  $context) : void
Parameters
$level : string

Description

the normalized log level

$message : string

Description

the original message template

$context : array<string, mixed>

Description

the processed log context

formatMessage()

Private

Formats a log entry for console output.

private formatMessage( string  $level, string  $message, array<string, mixed>  $context) : string

Description

When JSON output is enabled, the logger MUST return a JSON-encoded representation of the message, level, and context. Otherwise, the message SHALL be interpolated and wrapped with a console tag that uses the log level as both the style name and visual prefix.

Parameters
$level : string

Description

the normalized log level

$message : string

Description

the message template to format

$context : array<string, mixed>

Description

context values used during formatting

Return values
string

Description

the formatted message ready to be written to the console

interpolate()

Private

Interpolates context values into PSR-3-style message placeholders.

private interpolate( string  $message, array<string, mixed>  $context) : string

Description

Placeholders in the form "{key}" SHALL be replaced when a matching key exists in the context array and the associated value can be represented safely as text. Scalar values, null, and stringable objects MUST be inserted directly. DateTime values SHALL be formatted using RFC3339. Objects and arrays MUST be converted into descriptive string representations.

Parameters
$message : string

Description

the message containing optional placeholders

$context : array<string, mixed>

Description

the context map used for replacement values

Tags
author

Description

PHP Framework Interoperability Group

Return values
string

Description

the interpolated message

isJsonOutput()

Private

Determines whether structured JSON output has been requested.

private isJsonOutput() : bool

Description

The "--json" and "--pretty-json" options MAY be provided by the caller. When either is present, this method SHALL return true. Otherwise, detected agent environments SHOULD default to JSON output as well.

Return values
bool

Description

true when JSON output is enabled; otherwise, false

isPrettyJsonOutput()

Private

Determines whether pretty-printed JSON output has been requested.

private isPrettyJsonOutput() : bool
Return values
bool