Logger
config/packages/logger.php wires the Monolog logger and binds it to LoggerInterface.
What it does
- Creates a
StreamHandlerwriting tologger.path. - Wraps the stream handler in a
FingersCrossedHandlerthat buffers log records and only flushes them when a record at or above the configured level is emitted. - Derives the minimum log
Levelfromapp.debug:Level::Debugin debug mode,Level::Warningin production. - Creates a
Loggernamed afterapp.nameand binds it toLoggerInterface.
Configuration parameters
| Key | Default | Description |
|---|---|---|
logger.path | php://stderr (from services.php) | Log output destination. Accepts any PHP stream wrapper or a file path. |
logger.handlers | [FingersCrossedHandler] (from services.php) | Monolog handlers attached to the logger. Other packages or services.php can append additional handlers via add([...]). |
Log levels by environment
app.debug | Minimum level |
|---|---|
true (dev) | Debug — all messages are written. |
false (prod) | Warning — only warnings and above trigger a flush. |
Writing logs to a file
// services.php
'logger.path' => string('{app.project_root}/var/log/app.log'),
Adding a handler
// services.php
use Monolog\Handler\SlackWebhookHandler;
use function DI\add;
use function DI\create;
'logger.handlers' => add([
create(SlackWebhookHandler::class)->constructor('https://hooks.slack.com/...'),
]),
Dependencies
| Package | Description |
|---|---|
monolog/monolog | The logging library. |