class StdoutLogger implements StdoutLoggerInterface

Low-level PSR-3 logger that writes directly to stdout.

Used by Swoole server infrastructure that needs logging before the application log stack is available. Supports human-readable line and structured JSON output.

Traits

LoggerTrait

Constants

private JSON_FLAGS

private STANDARD_LEVELS

Methods

__construct(Repository $config, OutputInterface|null $output = null)

Create a new stdout logger instance.

void
reloadConfiguration()

Reload the cached stdout logger configuration.

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

Log a message at the given level.

string
getLineMessage(string $message, string $level = LogLevel::INFO, array $tags = [])

Format a human-readable log line with timestamp, colored level tag and context tags.

string
getJsonMessage(string $message, string $level, array $tags, array $context)

Format a structured JSON log line for log aggregators.

string|null
encodeJson(array $entry)

Encode a structured log entry without allowing user serializers to escape.

string
interpolate(string $message, array $context)

Interpolate context values into a message.

mixed
normalizeContextValue(mixed $value)

Normalize a top-level context value for structured output.

string
stringify(mixed $value)

Convert a log value to a safe string representation.

string
stringifyStringable(Stringable $value)

Convert a stringable object without allowing its failure to mask a log entry.

string
escapeLineValue(string $value)

Escape dynamic text that Symfony Console would otherwise interpret as markup.

Details

at line 59
__construct(Repository $config, OutputInterface|null $output = null)

Create a new stdout logger instance.

Parameters

Repository $config
OutputInterface|null $output

at line 71
void reloadConfiguration()

Reload the cached stdout logger configuration.

The cached format and enabled levels affect every subsequent log entry in the worker.

Return Value

void

at line 101
void log(mixed $level, string|Stringable $message, array $context = [])

Log a message at the given level.

Parameters

mixed $level
string|Stringable $message
array $context

Return Value

void

at line 142
protected string getLineMessage(string $message, string $level = LogLevel::INFO, array $tags = [])

Format a human-readable log line with timestamp, colored level tag and context tags.

Parameters

string $message
string $level
array $tags

Return Value

string

at line 164
protected string getJsonMessage(string $message, string $level, array $tags, array $context)

Format a structured JSON log line for log aggregators.

Parameters

string $message
string $level
array $tags
array $context

Return Value

string

at line 192
protected string|null encodeJson(array $entry)

Encode a structured log entry without allowing user serializers to escape.

Parameters

array $entry

Return Value

string|null

at line 210
protected string interpolate(string $message, array $context)

Interpolate context values into a message.

Parameters

string $message
array $context

Return Value

string

at line 224
protected mixed normalizeContextValue(mixed $value)

Normalize a top-level context value for structured output.

Parameters

mixed $value

Return Value

mixed

at line 238
protected string stringify(mixed $value)

Convert a log value to a safe string representation.

Parameters

mixed $value

Return Value

string

at line 257
protected string stringifyStringable(Stringable $value)

Convert a stringable object without allowing its failure to mask a log entry.

Parameters

Stringable $value

Return Value

string

at line 273
protected string escapeLineValue(string $value)

Escape dynamic text that Symfony Console would otherwise interpret as markup.

Parameters

string $value

Return Value

string