Context data
Every logging method accepts a second argument: an array of context data.
use GT\Logger\Log;
Log::warning("Unable to send welcome email", [
"userId" => 42,
"email" => "new.user@example.com",
]);
By default, that context is appended to the line in a bracketed key/value format:
2026-05-08 12:34:56 WARNING Unable to send welcome email [userId = 42] [email = new.user@example.com]
Nested arrays
Nested arrays are unwrapped recursively:
Log::error("Form validation failed", [
"user" => [
"id" => 42,
"role" => "admin",
],
]);
Output:
[user = {[id = 42] [role = admin]}]
Non-scalar values
Scalars and null are written directly.
If a context value is an object or another non-scalar type, the logger writes its type name rather than trying to serialise the whole thing.
That keeps the default output safe and predictable.
A useful habit
Context is most helpful when the message stays short and the changing details move into the array:
Log::error("Unable to save order", [
"orderId" => $orderId,
"userId" => $userId,
"retry" => $retryCount,
]);
This tends to age better than building one large string with every value interpolated into it.
What context does not do
This library does not implement PSR-3 placeholder interpolation such as:
Log::info("User {id} signed in", ["id" => 42]);
In this library, that message remains exactly as written and the context is appended separately.
If we want the ID in the message itself, we should add it explicitly:
Log::info("User 42 signed in", ["id" => 42]);
Next: Custom log handlers