CategoryLogger
A PSR-3 logger bound to a single category.
The 8 level methods come from LoggerTrait and funnel into CategoryLogger::log(); CategoryLogger::isEnabled() is the cheap hot-path guard for callers to skip expensive message construction. The category threshold is resolved via LogRegistry and cached on the instance, along with the per-level isEnabled() answers.
Those caches are keyed to LogRegistry::generation(), which every configuration change bumps. Instances are shared per category and live for the worker’s lifetime, so a level rule or sink registered after one was handed out would otherwise never be seen by it — the hot path pays one integer comparison to make reconfiguration actually take effect.
Synopsis
Section titled “Synopsis”final class CategoryLogger implements LoggerInterface
| Implements | LoggerInterface |
| Uses | LoggerTrait |
| Source | Logging/CategoryLogger.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(string $category): mixed
| Parameter | Type | Description |
|---|---|---|
$category | string |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
| [`alert(Stringable | string $message, array $context = []): void`](#alert) |
category(): string | Returns the category name this logger is bound to. |
| [`critical(Stringable | string $message, array $context = []): void`](#critical) |
| [`debug(Stringable | string $message, array $context = []): void`](#debug) |
debugWith(callable(): string $build): void | Emit a debug message built by $build, but only when debug logging is on, and never let building it affect the caller. |
| [`emergency(Stringable | string $message, array $context = []): void`](#emergency) |
| [`error(Stringable | string $message, array $context = []): void`](#error) |
| [`info(Stringable | string $message, array $context = []): void`](#info) |
isEnabled(Level $level): bool | Whether an event at $level for this category would be emitted by at least one sink: passes the category threshold AND some sink accepts it. |
| [`log(mixed $level, Stringable | string $message, array<string, mixed> $context = []): void`](#log) |
| [`notice(Stringable | string $message, array $context = []): void`](#notice) |
| [`warning(Stringable | string $message, array $context = []): void`](#warning) |
alert()
Section titled “alert()”public function alert(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Action must be taken immediately.
Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
category()
Section titled “category()”public function category(): string
Returns the category name this logger is bound to.
Returns string
critical()
Section titled “critical()”public function critical(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Critical conditions.
Example: Application component unavailable, unexpected exception.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
debug()
Section titled “debug()”public function debug(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Detailed debug information.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
debugWith()
Section titled “debugWith()”public function debugWith(callable(): string $build): void
Emit a debug message built by $build, but only when debug logging is on, and never let building it affect the caller.
Returns the message; the empty string emits nothing.
| Parameter | Type | Description |
|---|---|---|
$build | callable(): string | Returns the message; the empty string emits nothing. |
emergency()
Section titled “emergency()”public function emergency(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
System is unusable.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
error()
Section titled “error()”public function error(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Runtime errors that do not require immediate action but should typically be logged and monitored.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
info()
Section titled “info()”public function info(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Interesting events.
Example: User logs in, SQL logs.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
isEnabled()
Section titled “isEnabled()”public function isEnabled(Level $level): bool
Whether an event at $level for this category would be emitted by at least one sink: passes the category threshold AND some sink accepts it.
Allocates nothing; safe to call per request on the hot path.
| Parameter | Type | Description |
|---|---|---|
$level | Level |
Returns bool
public function log(mixed $level, Stringable|string $message, array<string, mixed> $context = []): void
Composed in from LoggerTrait.
Logs with an arbitrary level.
| Parameter | Type | Description |
|---|---|---|
$level | mixed | A PSR-3 level string or a Level. |
$message | Stringable` | “string` |
$context | array``<``string``, ``mixed``> |
| Throws | When |
|---|---|
InvalidArgumentException |
notice()
Section titled “notice()”public function notice(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Normal but significant events.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |
warning()
Section titled “warning()”public function warning(Stringable|string $message, array $context = []): void
Composed in from LoggerTrait.
Exceptional occurrences that are not errors.
Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
| Parameter | Type | Description |
|---|---|---|
$message | Stringable` | “string` |
$context | array |