LogsCommandResults

Trait

Provides reusable helpers for logging command outcomes and returning exit codes.

Description

Consuming commands stay focused on orchestration while this trait keeps the success, notice, and failure logging shape consistent across the command surface.

Table of Contents

Properties

$logger

Caches the logger resolved for the consuming command.

 : LoggerInterface|null

Methods

getLogger()

Returns the logger configured for the consuming command.

 : LoggerInterface
failure()

Logs a failed command result and returns the failure exit code.

 : int
log()

Logs a non-terminal command message unless structured JSON output is active.

 : void
success()

Logs a successful command result and returns the success exit code.

 : int
Properties

$logger

Private

Caches the logger resolved for the consuming command.

private LoggerInterface|null $logger = null
Methods

getLogger()

Public

Returns the logger configured for the consuming command.

public getLogger() : LoggerInterface
Return values
LoggerInterface

failure()

Private

Logs a failed command result and returns the failure exit code.

private failure( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string|null  $file = null][, int|null  $line = null]) : int
Parameters
$message : string

Description

the failure message

$input : InputInterface

Description

the originating command input

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

Description

optional extra log context

$file : string|null = null

Description

the related file path when known

$line : int|null = null

Description

the related line when known

Return values
int

log()

Private

Logs a non-terminal command message unless structured JSON output is active.

private log( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : void
Parameters
$message : string

Description

the progress message

$input : InputInterface

Description

the originating command input

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

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the message

success()

Private

Logs a successful command result and returns the success exit code.

private success( string  $message, InputInterface  $input[, array<string, mixed>  $context = []][, string  $logLevel = LogLevel::INFO]) : int
Parameters
$message : string

Description

the success message

$input : InputInterface

Description

the originating command input

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

Description

optional extra log context

$logLevel : string = LogLevel::INFO

Description

the PSR-3 log level used for the successful result

Return values
int