Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions v3.0/packages/logger/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ Both file adapters use the same line format:
[YYYY-MM-DD HH:MM:SS] Level: message
```

If you pass `['trace' => $trace]`, the trace is appended on the next line before the final newline.
When the call passes a context, it follows the message on the same line as one line of JSON:

If you pass an array message, the package JSON-encodes it with pretty printing before writing.
```php
logger()->info('Order paid', ['order' => 1042, 'status' => 'paid']);
```

```text
[2026-11-23 14:02:11] Info: Order paid {"order":1042,"status":"paid"}
```

A few keys and values are written in their own way:

- `trace` that is text (a string or a `Stringable` object, such as `$exception->getTraceAsString()`) goes on the next lines, after the message and its context, instead of into the JSON. A `trace` that is not text, such as the array of `$exception->getTrace()`, stays in the JSON.
- An exception at the top level of the context is written as its `class`, `message`, `file` and `line`, and a `Stringable` value as its text.
- Slashes and non-ASCII characters are written as they are, invalid UTF-8 becomes `�`, and a value JSON cannot encode, such as a resource, becomes `null`.
- When a context value throws while it is converted, `{"context":"not encodable"}` replaces the context, so the log call still writes its line.

Without a context, the line is only the message. Everything you put in the context reaches the log file, so leave passwords and tokens out of it.
6 changes: 3 additions & 3 deletions v3.0/packages/logger/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ This matters because the threshold is not stored per logger instance.
File adapters use a shared formatter that:

1. prepends a timestamp and capitalized level
2. JSON-encodes array messages
3. appends `context['trace']` when present
2. appends the context as one line of JSON, without a `trace` that is text
3. appends a `trace` that is text on its own lines
4. appends the final string to the target file

All other context keys are ignored by file adapters.
The JSON conversion catches its own errors, so a context value that fails to convert replaces the context with a marker instead of stopping the log call. See [File output format](adapters.md#file-output-format).

## Message adapter flow

Expand Down
10 changes: 3 additions & 7 deletions v3.0/packages/logger/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ In debug mode, the opposite happens in the web app: the factory forces `message`

So adapter selection is environment-sensitive, not purely call-driven.

## File logging uses only one special context key
## File logging writes the context

For file adapters, the only context key that changes output is:
The message is `string|Stringable`, as PSR-3 defines; an array message throws a `TypeError`. Structured data goes in the context: the file adapters write it after the message as one line of JSON, and a `trace` that is text on the following lines. A context value that cannot be converted never makes the log call fail. See [File output format](adapters.md#file-output-format) for the exact format.

- `trace`

It is appended verbatim after the formatted message.

No placeholder interpolation or structured context rendering happens.
No placeholder interpolation happens: `{key}` in the message is written as it is.

## The `message` adapter ignores the context

Expand Down
4 changes: 2 additions & 2 deletions v3.0/packages/logger/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A few limits are easy to miss:

- the convenience helpers do not let you choose an adapter
- there are no global helpers for `critical`, `alert`, or `emergency`
- the convenience helpers accept string messages, while `logger()` also lets you send array payloads through the PSR-3 methods
- the convenience helpers and `logger()` both take a string message and a context; structured data goes in the context
- every helper call goes back through the shared factory

Use `logger()` when you need the full PSR-3 surface, adapter selection, or structured array messages.
Use `logger()` when you need the full PSR-3 surface or adapter selection.
2 changes: 1 addition & 1 deletion v3.0/packages/logger/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ In debug mode, `Logger::log()` bypasses threshold filtering and reports every ca
- The active log threshold is stored in static `LoggerConfig` state, so resolving a logger updates process-wide logging behavior.
- `LoggerFactory` caches one `Logger` instance per adapter name inside the factory service.
- The `message` adapter is not available outside debug mode.
- File adapters only use the `trace` context key for output formatting. Other context values are ignored by file logging.
- File adapters write the context after the message as JSON, and a `trace` that is text on its own lines; see [File output format](adapters.md#file-output-format). Everything in the context reaches the log file.
- The package does not validate arbitrary custom level strings. Stick to standard PSR log levels for predictable filtering and output.
- The `daily` adapter picks its `<YYYY-MM-DD>.log` file when the adapter is created. In long-running workers, recreate/re-resolve the logger after midnight if you need strict daily rollover.
13 changes: 9 additions & 4 deletions v3.0/packages/logger/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ That writes the formatted message first and then appends the trace block.

## Log a structured payload

When you want file logs to capture structured data, call the logger instance directly:
Say what happened in the message and put the data in the context:

```php
logger()->info([
logger()->info('Catalog sync queued', [
'job' => 'catalog-sync',
'status' => 'queued',
'items' => 48,
]);
```

File adapters JSON-format array messages before writing them. The global level helpers accept string messages, so `logger()` is the better fit for this style.
A file adapter writes the context as JSON after the message:

```text
[2026-11-23 14:02:11] Info: Catalog sync queued {"job":"catalog-sync","items":48}
```

The message must be text, as PSR-3 defines: `logger()->info([...])` throws a `TypeError`. The global helpers take a context too, for example `info('Catalog sync queued', ['items' => 48])`. See [File output format](adapters.md#file-output-format) for how exceptions, a `trace` and other values are written.

## Check what was logged in debug mode

Expand Down
17 changes: 16 additions & 1 deletion v3.0/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,22 @@ The starter project's tests run on PHPUnit 11.5. If your project keeps them, req

- replace `@dataProvider` doc comments with the `#[DataProvider('...')]` attribute (`use PHPUnit\Framework\Attributes\DataProvider;`); PHPUnit 12 no longer reads doc comments.

### 8. Check the upgrade
### 8. Log lines carry the context

The `single` and `daily` log adapters write the context of a log call after the message, as one line of JSON; they ignored it before:

```text
[2026-11-23 14:02:11] Info: Order paid {"order":1042}
```

- A line without a context is unchanged. A tool that parses your log lines with a fixed pattern must allow the JSON at the end.
- Everything you pass in the context reaches the log file: check your log calls for passwords, tokens or full request payloads.
- The message stays text: `logger()->info([...])` throws a `TypeError`, as in 3.1. Put structured data in the context.
- A log adapter of your own that uses `Quantum\Logger\Traits\LoggerTrait` and passes an array to `formatMessage()` gets a `TypeError`: pass a string.

See [File output format](packages/logger/adapters.md#file-output-format).

### 9. Check the upgrade

Update the dependencies and run the checks you already use:

Expand Down
Loading