> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/logger/contracts.md).

# Contracts

The Logger package is small, but a few runtime contracts matter when you build on top of it.

## `Logger` is PSR-3-shaped, but not strict PSR-3 validation

`Quantum\Logger\Logger` implements `Psr\Log\LoggerInterface` and exposes the standard methods:

* `emergency()`
* `alert()`
* `critical()`
* `error()`
* `warning()`
* `notice()`
* `info()`
* `debug()`
* `log()`

But the package does not validate arbitrary custom level strings in `log()`.

Instead:

* threshold comparison falls back to the package's default `error` numeric value for unknown levels
* the original level string is still forwarded to the adapter

For predictable behavior, use the built-in PSR log levels only.

## Threshold changes are global, not per logger

`LoggerConfig` keeps the active threshold in static state.

That means the threshold is shared across all logger instances in the same process.

If one part of the app resolves a logger whose config level is `debug`, and another later resolves one whose config level is `error`, the later resolution updates the threshold used from then on.

## The `message` adapter has a hard environment gate

`LoggerFactory::resolve()` rejects `message` outside debug mode.

In debug mode, the opposite happens: the factory forces `message` even when you requested another adapter.

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

## File logging uses only one special context key

For file adapters, the only context key that changes output is:

* `trace`

It is appended verbatim after the formatted message.

No placeholder interpolation or structured context rendering happens.

## Debugger logging uses one routing key

For the `message` adapter, the special context key is:

* `tab`

It chooses the debugger store cell that receives the message.

If you omit it, the package uses the default messages tab.

## Adapter implementations must satisfy `ReportableInterface`

Custom adapters resolved through the factory must implement:

```php
public function report(string $level, string $message, ?array $context = []): void;
```

If the resolved adapter instance does not implement that contract, the factory throws an adapter-not-supported exception.

## Invalid configured thresholds fail soft

`LoggerConfig::setAppLogLevel()` only updates the threshold when the provided level exists in the internal map.

If the configured level is unknown, the previous threshold stays in place.

That means a bad config value does not raise an exception here; it leaves logging on the last valid threshold.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/logger/contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
