OutputFormatLogger
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.
Interfaces
Constants
Lists the log levels that MUST be written to the error output stream.
Properties
Methods
Creates a new console logger instance.
Logs a message at the specified level.
Emits GitHub Actions annotations for supported error levels.
Formats a log entry for console output.
Interpolates context values into PSR-3-style message placeholders.
Determines whether structured JSON output has been requested.
Determines whether pretty-printed JSON output has been requested.
private
Detector
$agentDetector
private
ClockInterface
$clock
private
ContextProcessorInterface
$contextProcessor
private
GithubActionOutput
$githubActionOutput
private
ArgvInput
$input
private
ConsoleOutputInterface
$output
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
Description
expands command input and output metadata
Description
emits GitHub Actions annotations when supported
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
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
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
Description
the formatted message ready to be written to the console
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
Description
PHP Framework Interoperability Group
Return values
Description
the interpolated message
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
Description
true when JSON output is enabled; otherwise, false
Determines whether pretty-printed JSON output has been requested.
private
isPrettyJsonOutput() : bool