Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 16, 2026·3 min de lecture

Monolog — Comprehensive Logging Library for PHP

PSR-3 compliant logging library for PHP with handlers for files, databases, Slack, email, and third-party services.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Monolog Overview
Commande d'installation directe
npx -y tokrepo@latest install a9cdd8b3-8135-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Monolog is the standard logging library for PHP. It implements the PSR-3 LoggerInterface and ships with over 70 handlers that send log records to files, databases, email, Slack, Elasticsearch, and other destinations. It is the default logger in Laravel, Symfony, and most modern PHP frameworks.

What Monolog Does

  • Sends log records to files, syslog, stderr, databases, and external services
  • Supports PSR-3 log levels: debug, info, notice, warning, error, critical, alert, emergency
  • Formats log output as text, JSON, HTML, or custom formats via formatters
  • Processes log records through middleware-like processors that enrich context
  • Stacks multiple handlers with level-based filtering and bubble control

Architecture Overview

Monolog uses a channel-based architecture where each Logger instance holds a stack of handlers. When a log record is created, it passes through processors (which add data like memory usage, request ID, or stack traces), then flows through the handler stack. Each handler checks if it should handle the record based on its minimum level, formats it, and writes to its destination. Handlers can bubble records upward or stop propagation.

Setup & Configuration

  • Install via Composer: composer require monolog/monolog
  • Create a Logger with a channel name and push handlers onto it
  • Set handler levels to filter what gets written to each destination
  • Use processors like WebProcessor or MemoryUsageProcessor to enrich records
  • In Laravel use config/logging.php; in Symfony use monolog.yaml bundle config

Key Features

  • 70+ built-in handlers for files, databases, email, Slack, Telegram, and cloud services
  • PSR-3 compliant with drop-in compatibility across PHP frameworks
  • Processors add request context, memory stats, Git commit info, and unique IDs
  • Flexible formatter system with JSON, line, HTML, and custom output formats
  • Handler groups, fingers-crossed buffering, and deduplication for production use

Comparison with Similar Tools

  • Laravel Log — uses Monolog under the hood, adds Laravel-specific configuration
  • KLogger — simple file logger, Monolog offers far more handlers and flexibility
  • log4php — Apache project with XML config, Monolog is more PHP-idiomatic
  • Sentry SDK — error tracking service, Monolog can forward to Sentry via its handler

FAQ

Q: How does Monolog integrate with Laravel? A: Laravel uses Monolog as its logging backend. Configure channels in config/logging.php using the monolog driver.

Q: Can I send logs to multiple destinations simultaneously? A: Yes. Push multiple handlers onto the Logger. Each processes the record independently based on its level filter.

Q: What is the FingersCrossed handler? A: It buffers all log records and only flushes them when a record exceeds a threshold level, providing full context around errors without logging everything in normal operation.

Q: Is Monolog async? A: Monolog itself is synchronous. For async delivery, use handlers that write to fast local buffers (Redis, AMQP) and let workers forward logs asynchronously.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires