mimmi20 / monolog-factory
提供构建 Monolog 日志记录器的工厂。
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-mbstring: *
- monolog/monolog: ^3.7.0
- psr/container: ^1.1.2 || ^2.0.2
- psr/log: ^3.0.0
Requires (Dev)
- ext-ctype: *
- ext-dom: *
- ext-simplexml: *
- ext-tokenizer: *
- ext-xml: *
- ext-xmlwriter: *
- actived/microsoft-teams-notifier: ^1.3.0
- aws/aws-sdk-php: ^3.321.11
- doctrine/couchdb: 1.0.0-beta4
- elasticsearch/elasticsearch: ^7.17.2 || ^8.7.0
- ezimuel/ringphp: ^1.2.2
- graylog2/gelf-php: ^2.0.1
- guzzlehttp/guzzle: ^7.9.2
- guzzlehttp/psr7: ^2.7.0
- infection/infection: ^0.27.11 || ^0.28.1
- jk/monolog-request-header-processor: ^1.0.0
- laminas/laminas-config: ^3.9.0
- laminas/laminas-eventmanager: ^3.13.1
- laminas/laminas-modulemanager: ^2.16.0
- laminas/laminas-servicemanager: ^3.22.1 || ^4.0.0
- mikey179/vfsstream: ^1.6.12
- mimmi20/coding-standard: ^5.2.43
- mimmi20/monolog-callbackfilterhandler: ^3.0.7
- mimmi20/monolog-streamformatter: ^3.1.4
- nikic/php-parser: ^4.19.1 || ^5.0.2
- php-console/php-console: ^3.1.8
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^1.12.3
- phpstan/phpstan-deprecation-rules: ^1.2.1
- phpstan/phpstan-phpunit: ^1.4.0
- phpunit/phpunit: ^10.5.25
- predis/predis: ^1.1.10 || ^2.1.2
- rector/rector: ^1.2.5
- rector/type-perfect: ^0.2.0
- ruflin/elastica: ^8.0.0
- symfony/mailer: ^6.4.9
- symfony/mime: ^6.4.9
- symplify/phpstan-rules: ^13.0.1
- tomasvotruba/cognitive-complexity: ^0.2.3
- tomasvotruba/type-coverage: ^0.3.1
- tomasvotruba/unused-public: ^0.3.11
Suggests
- ext-amqp: Allow sending log messages to an AMQP server (1.0+ required)
- ext-curl: Allow sending log messages to some handlers
- ext-json: Allow sending log messages to the ChromePHP Handler
- ext-mongodb: Allow sending log messages to a MongoDB server (via driver)
- ext-openssl: Allow sending log messages to some handlers
- ext-sockets: Allow sending log messages to a Syslog server (via UDP driver)
- actived/microsoft-teams-notifier: Allow sending log messages to Microsoft Teams
- aws/aws-sdk-php: Allow sending log messages to AWS services like DynamoDB
- bartlett/monolog-callbackfilterhandler: Allow filtering log messages based on a callback function
- cmdisp/monolog-microsoft-teams: Allow sending log messages to Microsoft Teams
- doctrine/couchdb: Allow sending log messages to a CouchDB server
- elasticsearch/elasticsearch: Allow sending log messages to an Elasticsearch server via official client
- graylog2/gelf-php: Allow sending log messages to a GrayLog2 server
- jk/monolog-request-header-processor: Allow to add request headers to the log message
- laminas/laminas-modulemanager: Required for the module configuration
- laminas/laminas-servicemanager: Required for the Factories
- mongodb/mongodb: Allow sending log messages to a MongoDB server (via library)
- php-amqplib/php-amqplib: Allow sending log messages to an AMQP server using php-amqplib
- rollbar/rollbar: Allow sending log messages to Rollbar
- ruflin/elastica: Allow sending log messages to an Elastic Search server
README
Monolog 的 Laminas 和 Mezzio 工厂
此库受到了 psr11-monolog 和 monolog-factory 的启发。
代码状态
目录
- 安装
- 与 Laminas 和 Mezzio 一起使用
- 配置
安装
运行
composer require mimmi20/monolog-factory
与 Laminas 和 Mezzio 一起使用
您需要添加配置并注册您希望使用的服务。有几种方法可以实现,但推荐的方法是创建一个新的配置文件 config/autoload/logger.config.php
配置
config/autoload/logger.config.php
<?php return [ 'log' => [ 'default' => [ 'name' => 'name', 'errorLevelMap' => false, // optional: map of php errors to monolog levels, use an empty array if the default map should be used, defaults to false which disables the error handling 'exceptionLevelMap' => false, // optional: map of exceptions to monolog levels, use an empty array if the default map should be used, defaults to false which disables the exception handling 'fatalLevel' => false, // optional: monolog level used to log fatal errors, use null if the default level should be used, defaults to false which disables the handling of fatal errors 'handlers' => [ // Handlers for Monolog // At the bare minimum you must include a default handler config. // Otherwise log entries will be sent to the void. 'default' => [ 'type' => 'stream', 'enabled' => true, 'options' => [ 'stream' => '/var/log/some-log-file.txt', ], ], // Another Handler 'myOtherHandler' => [ 'type' => 'stream', 'enabled' => false, 'options' => [ 'stream' => '/var/log/someother-log-file.txt', ], ], ], 'processors' => [], ], ], ];
最小配置
最小配置至少应包括一个默认处理器和一个命名服务。请注意,如果您未指定默认处理器,则当您连接默认日志记录器时将使用 NullHandler。
最小示例(使用 Mezzio 作为示例)
<?php return [ 'log' => [ 'default' => [ 'name' => 'name', 'handlers' => [ 'default' => [ 'type' => 'stream', 'options' => [ 'stream' => '/var/log/some-log-file.txt', ], ], ], ], ], ];
完整配置
完整示例
<?php return [ 'log' => [ 'default' => [ 'name' => 'name', 'handlers' => [ 'default' => [ // A Handler type or pre-configured service from the container 'type' => 'stream', // Handler specific options. See handlers below 'options' => [ 'stream' => '/tmp/log_one.txt', // Optional: Formatter for the handler. 'formatter' => [ 'type' => 'line', // formatter specific options. See formatters below 'options' => [], ], // Optional: Processor for the handler 'processors' => [ [ // A processor type or pre-configured service from the container 'type' => 'psrLogMessage', // processor specific options. See processors below 'options' => [], ], ], ], ], ], 'processors' => [ // Array Keys are the names used for the processors 'processorOne' => [ // A processor type or pre-configured service from the container 'type' => 'psrLogMessage', // processor specific options. See processors below 'options' => [], ], ], ], ], ];
处理器
记录到文件和系统日志
StreamHandler
将日志记录到任何 PHP 流中,用于日志文件。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'stream', 'options' => [ 'stream' => '/tmp/stream_test.txt', // Required: File Path | Resource | Service Name 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'filePermission' => null, // Optional: file permissions (default (0644) are only for owner read/write) 'useLocking' => false, // Optional: Try to lock log file before doing any writes 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: StreamHandler
RotatingFileHandler
将日志记录到文件,并为每天创建一个日志文件。它还将删除超过 $maxFiles 的文件。尽管如此,您应该为高配置使用 [logrotate],这只是一个快速且不完美的解决方案。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'rotating', 'options' => [ 'filename' => '/tmp/stream_test.txt', // Required: File Path 'maxFiles' => 0, // Optional: The maximal amount of files to keep (0 means unlimited) 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'filePermission' => null, // Optional: file permissions (default (0644) are only for owner read/write) 'useLocking' => false, // Optional: Try to lock log file before doing any writes 'filenameFormat' => '{filename}-{date}', // Optional 'dateFormat' => 'Y-m-d', // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: RotatingFileHandler
SyslogHandler
将日志记录到系统日志。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'syslog', 'options' => [ 'ident' => '/tmp/stream_test.txt', // Required: The string ident is added to each message. 'facility' => LOG_USER, // Optional: The facility argument is used to specify what type of program is logging the message. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'logOpts' => LOG_PID, // Optional: Option flags for the openlog() call, defaults to LOG_PID 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SyslogHandler PHP openlog(): openlog
ErrorLogHandler
将日志记录到 PHP 的 error_log() 函数。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'errorlog', 'options' => [ 'messageType' => \Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, // Optional: Says where the error should go. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'expandNewlines' => false, // Optional: If set to true, newlines in the message will be expanded to be take multiple log entries 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: ErrorLogHandler
ProcessHandler
将日志记录到任何进程的标准输入(STDIN),通过命令指定。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'process', 'options' => [ 'command' => 'some-command', // Command for the process to start. Absolute paths are recommended, especially if you do not use the $cwd parameter. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'cwd' => __DIR__, // Optional: "Current working directory" (CWD) for the process to be executed in. 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: ProcessHandler
发送警报和电子邮件
NativeMailerHandler
使用 PHP 的 mail() 函数发送电子邮件。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'nativeMailer', 'options' => [ 'to' => ['email1@test.com', 'email2@test.com'], // The receiver of the mail. Can be an array or string 'subject' => 'Error Log', // The subject of the mail 'from' => 'sender@test.com', // The sender of the mail 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'maxColumnWidth' => 80, // Optional: The maximum column width that the message lines will have 'contentType' => 'text/html', // Optional 'encoding' => 'utf-8', // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: NativeMailerHandler
SymfonyMailerHandler
使用 symfony/mailer 实例发送电子邮件。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'symfonyMailer', 'options' => [ 'mailer' => 'my-service', // The mailer to use. Must be a valid service name in the container 'email-template' => 'my-template', // An email template, the subject/body will be replaced 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SymfonyMailerHandler
PushoverHandler
通过 Pushover API 发送移动通知。需要 sockets 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'pushover', 'options' => [ 'token' => 'sometokenhere', // Pushover api token 'users' => ['email1@test.com', 'email2@test.com'], // Pushover user id or array of ids the message will be sent to 'title' => 'Error Log', // Optional: Title sent to the Pushover API 'level' => \Psr\Log\LogLevel::INFO, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => false, // Optional: Whether the messages that are handled can bubble up the stack or not 'useSSL' => false, // Optional: Whether to connect via SSL. Required when pushing messages to users that are not the pushover.net app owner. OpenSSL is required for this option. 'highPriorityLevel' => \Psr\Log\LogLevel::WARNING, // Optional: The minimum logging level at which this handler will start sending "high priority" requests to the Pushover API 'emergencyLevel' => \Psr\Log\LogLevel::ERROR, // Optional: The minimum logging level at which this handler will start sending "emergency" requests to the Pushover API 'retry' => 22, // Optional: The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user. 'expire' => 300, // Optional: The expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds). 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: PushoverHandler
FlowdockHandler
将日志记录到 Flowdock 账户。需要 openssl 和 sockets 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'flowdock', 'options' => [ 'apiToken' => 'sometokenhere', // HipChat API Token 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: FlowdockHandler
SlackWebhookHandler
使用 Slack Webhooks 将日志记录到 Slack 账户。需要 curl 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'slackWebhook', 'options' => [ 'webhookUrl' => 'webhook.slack.com', // Slack Webhook URL 'channel' => 'channel', // Slack channel (encoded ID or name) 'userName' => 'log', // Name of a bot 'useAttachment' => false, // Optional: Whether the message should be added to Slack as attachment (plain text otherwise) 'iconEmoji' => null, // Optional: The emoji name to use (or null) 'useShortAttachment' => true, // Optional: Whether the the context/extra messages added to Slack as attachments are in a short style 'includeContextAndExtra' => true, // Optional: Whether the attachment should include context and extra data 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => false, // Optional: Whether the messages that are handled can bubble up the stack or not 'excludeFields' => ['context.field1', 'extra.field2'], // Optional: Dot separated list of fields to exclude from slack message. 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SlackWebhookHandler
SlackHandler
使用 Slack API(复杂配置)将日志记录到 Slack 账户。需要 openssl 和 sockets 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'slack', 'options' => [ 'token' => 'apiToken', // Slack API token 'channel' => 'channel', // Slack channel (encoded ID or name) 'userName' => 'log', // Name of a bot 'useAttachment' => false, // Optional: Whether the message should be added to Slack as attachment (plain text otherwise) 'iconEmoji' => null, // Optional: The emoji name to use (or null) 'useShortAttachment' => true, // Optional: Whether the the context/extra messages added to Slack as attachments are in a short style 'includeContextAndExtra' => true, // Optional: Whether the attachment should include context and extra data 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => false, // Optional: Whether the messages that are handled can bubble up the stack or not 'excludeFields' => ['context.field1', 'extra.field2'], // Optional: Dot separated list of fields to exclude from slack message. 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SlackHandler
SendGridHandler
通过 SendGrid API 发送电子邮件。需要 curl 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'sendgrid', 'options' => [ 'apiUser' => 'apiUser', // The SendGrid API User 'apiKey' => 'apiKey', // The SendGrid API Key 'from' => 'from', // The sender of the email 'to' => 'to', // string or array of recipients 'subject' => 'subject', // The subject of the mail 'level' => \Psr\Log\LogLevel::INFO, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => false, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SendGridHandler
MandrillHandler
使用 Mandrill API 通过 Swift_Message 实例发送电子邮件。需要 curl 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'mandrill', 'options' => [ 'apiKey' => 'my-service', // A valid Mandrill API key 'message' => 'my-message', // An example \Swiftmail message for real messages, only the body will be replaced. Must be a valid service name or callable 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: MandrillHandler
FleepHookHandler
使用 Webhooks 将日志记录到 Fleep 对话。需要 openssl 和 sockets 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'fleepHook', 'options' => [ 'token' => 'sometokenhere', // Webhook token 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: FleepHookHandler
IFTTTHandler
IFTTTHandler 使用 cURL 触发 IFTTT Maker 动作。需要 curl 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'ifttt', 'options' => [ 'eventName' => 'eventName', // name of an event 'secretKey' => 'secretKey', 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: IFTTTHandler
TelegramBotHandler
将日志记录到 Telegram 机器人账户。需要 curl 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'telegrambot', 'options' => [ 'apiKey' => 'api-key', // Api Key 'channel' => 'channel', // Channel 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'parseMode' => null, // Optional: null or one of 'HTML', 'MarkdownV2', 'Markdown' 'disableWebPagePreview' => null, // Optional: null or boolean 'disableNotification' => null, // Optional: null or boolean 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: TelegramBotHandler
记录特定服务器和网络日志
SocketHandler
将日志记录到 套接字,适用于 UNIX 和 TCP 套接字。查看一个 示例。需要套接字扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'socket', 'options' => [ 'connectionString' => 'unix:///var/log/httpd_app_log.socket', // Socket connection string. You can use a unix:// prefix to access unix sockets and udp:// to open UDP sockets instead of the default TCP. 'timeout' => 30.0, // Optional: The connection timeout, in seconds. 'writeTimeout' => 90.0, // Optional: Set timeout period on a stream. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SocketHandler
AmqpHandler
将日志记录到一个兼容 AMQP 服务器。需要 php-amqp 扩展(1.0+)或 php-amqplib 库。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'amqp', 'options' => [ 'exchange' => 'my-service', // AMQPExchange (php AMQP ext) or PHP AMQP lib channel. Must be a valid service. 'exchangeName' => 'log-name', // Optional: Exchange name, for AMQPChannel (PhpAmqpLib) only 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: AmqpHandler
GelfHandler
将日志记录到一个 Graylog 服务器。需要 graylog2/gelf-php 包。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'gelf', 'options' => [ 'publisher' => 'my-service', // A Gelf\PublisherInterface object. Must be a valid service. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: GelfHandler
ZendMonitorHandler
将日志记录到存在于 Zend Server 中的 Zend Monitor。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'zend', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: ZendMonitorHandler
NewRelicHandler
将日志记录到一个 NewRelic 应用程序。需要 newrelic 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'newRelic', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'appName' => 'my-app', // Optional: Application name 'explodeArrays' => false, // Optional: Explode Arrays 'transactionName' => 'my-transaction', // Optional: Explode Arrays 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: NewRelicHandler
LogglyHandler
将日志记录到一个 Loggly 账户。需要 cURL 扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'loggly', 'options' => [ 'token' => 'sometokenhere', // Webhook token 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: LogglyHandler
RollbarHandler
将日志记录到一个 Rollbar 账户。
注意:RollbarHandler 与上游更改脱节。此外,Rollbar 库建议使用 PsrHandler。有关如何设置此内容的说明,请参阅 Rollbar 文档。
Monolog 文档: RollbarHandler
SyslogUdpHandler
将日志记录到一个远程 Syslogd 服务器。需要套接字扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'syslogUdp', 'options' => [ 'host' => 'somewhere.com', // Host 'port' => 513, // Optional: Port 'facility' => 'Me', // Optional: Facility 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'ident' => 'me-too', // Optional: Program name or tag for each log message. 'rfc' => '', // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SyslogUdpHandler
LogEntriesHandler
将日志记录到一个 LogEntries 账户。需要 openssl 和套接字扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'logEntries', 'options' => [ 'token' => 'sometokenhere', // Log token supplied by LogEntries 'useSSL' => true, // Optional: Whether or not SSL encryption should be used. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'host' => 'data.logentries.com', // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: LogEntriesHandler
InsightOpsHandler
将日志记录到一个 InsightOps 账户。需要 openssl 和套接字扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'insightops', 'options' => [ 'token' => 'sometokenhere', // Log token supplied by InsightOps 'region' => 'region', // Region where InsightOps account is hosted. Could be 'us' or 'eu'. 'useSSL' => true, // Optional: Whether or not SSL encryption should be used. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: InsightOpsHandler
LogmaticHandler
将日志记录到一个 Logmatic 账户。需要 openssl 和套接字扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'logmatic', 'options' => [ 'token' => 'sometokenhere', // Log token supplied by Logmatic. 'hostname' => 'region', // Optional: Host name supplied by Logmatic. 'appname' => 'region', // Optional: Application name supplied by Logmatic. 'useSSL' => true, // Optional: Whether or not SSL encryption should be used. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'timeout' => 10.0, // Optional 'writeTimeout' => 5.0, // Optional 'persistent' => false, // Optional 'chunkSize' => 100, // Optional 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: LogmaticHandler
SqsHandler
将日志记录到一个 AWS SQS 队列。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'sqs', 'options' => [ 'sqsClient' => 'my-service', // SQS Client. Must be a valid service name in the container. 'queueUrl' => 'url', // URL to SQS Queue 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: SqsHandler
开发中的日志记录
FirePHPHandler
FirePHP处理器,提供在FireBug中显示的行内控制台消息。
注意:Firebug扩展不再开发或维护。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'firePHP', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:FirePHPHandler
ChromePHPHandler
ChromePHP处理器,提供在Chrome中显示的行内控制台消息。需要json扩展。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'chromePHP', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:ChromePHPHandler
BrowserConsoleHandler
无需浏览器扩展即可将日志发送到浏览器的JavaScript控制台。支持大多数支持console API的浏览器。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'browserConsole', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:BrowserConsoleHandler
记录到数据库
RedisHandler
将日志记录到Redis服务器。需要php-redis扩展或Predis库。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'redis', 'options' => [ 'client' => 'my-redis-service-name', // The redis instance. Must be either a [Predis] client OR a Pecl Redis instance 'key' => 'my-service', // The key name to push records to 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'capSize' => true, // Optional: Number of entries to limit list size to, 0 = unlimited 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:RedisHandler
RedisPubSubHandler
将日志记录到Redis服务器。需要php-redis扩展或Predis库。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'redisPubSub', 'options' => [ 'client' => 'my-redis-service-name', // The redis instance. Must be either a [Predis] client OR a Pecl Redis instance 'key' => 'my-service', // The key name to push records to 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:RedisPubSubHandler
MongoDBHandler
通过Mongo扩展连接将记录写入MongoDB。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'mongo', 'options' => [ 'client' => 'my-mongo-service-name', // MongoDB library or driver instance. 'database' => 'my-db', // Database name 'collection' => 'collectionName', // Collection name 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:MongoDBHandler
CouchDBHandler
将日志记录到CouchDB服务器。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'couchDb', 'options' => [ 'host' => 'localhost', // Optional: Hostname/Ip address, Default: 'localhost' 'port' => 5984, // Optional: port, Default: 5984 'dbname' => 'db', // Optional: Database Name, Default: 'logger' 'username' => 'someuser', // Optional: Username, Default: null 'password' => 'somepass', // Optional: Password, Default: null 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:CouchDBHandler
DoctrineCouchDBHandler
通过Doctrine CouchDB ODM将记录发送到CouchDB服务器。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'doctrineCouchDb', 'options' => [ 'client' => 'my-service', // CouchDBClient service name. Must be a valid container service 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:DoctrineCouchDBHandler
ElasticaHandler
将记录发送到Elastic Search服务器。需要Elastica。
注意:客户端的版本应与服务器版本匹配,但实际上没有8.x版本。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'elastica', 'options' => [ 'client' => 'my-service', // Elastica Client object. Must be a valid container service 'index' => 'log', // Optional: Elastic index name 'type' => 'record', // Optional: Elastic document type 'ignoreError' => false, // Optional: Suppress Elastica exceptions 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:ElasticaHandler
ElasticsearchHandler
将记录发送到Elastic Search服务器。需要Elasticsearch PHP客户端。
注意:客户端的版本应与服务器版本匹配。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'elasticsearch', 'options' => [ 'client' => 'my-service', // Elastica Client object. Must be a valid container service 'index' => 'log', // Optional: Elastic index name 'dateFormat' => \Mimmi20\MonologFactory\Handler\ElasticsearchHandlerFactory::INDEX_PER_DAY, // Optional: possible Values are \Mimmi20\MonologFactory\Handler\ElasticsearchHandlerFactory::INDEX_PER_DAY, \Mimmi20\MonologFactory\Handler\ElasticsearchHandlerFactory::INDEX_PER_MONTH and \Mimmi20\MonologFactory\Handler\ElasticsearchHandlerFactory::INDEX_PER_YEAR 'indexNameFormat' => '{indexname}', // Optional: a string which must contain the string '{indexname}' (which is a placeholder for the `index`) and may contain the string '{date}' (which is a placeholder for the actual date formatted by `dateFormat`) 'type' => 'record', // Optional: Elastic document type 'ignoreError' => false, // Optional: Suppress Elastica exceptions 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:ElasticsearchHandler
DynamoDbHandler
使用AWS SDK将记录发送到DynamoDB表。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'dynamoDb', 'options' => [ 'client' => 'my-service', // DynamoDbClient object. Must be a valid container service 'table' => 'log', // Table name 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:DynamoDbHandler
包装器/特殊处理器
FingersCrossedHandler
一个非常有趣的包装器。它将日志记录器作为参数,将所有级别的日志记录累积,直到记录超过定义的严重性级别。在此之后,它将包括较低严重性的所有记录都发送到它所包装的处理程序。这意味着在错误实际发生之前,您将不会在日志中看到任何内容,但一旦发生,您将获得完整的信息,包括调试和info记录。这为您提供了所需的所有信息,但仅在需要时才提供。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'fingersCrossed', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'activationStrategy' => 'my-service', // Optional: Strategy which determines when this handler takes action. Must be either the error level or configured ActivationStrategyInterface service 'bufferSize' => 0, // Optional: How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'stopBuffering' => true, // Optional: Whether the handler should stop buffering after being triggered (default true) 'passthruLevel' => null, // Optional: Minimum level to always flush to handler on close, even if strategy not triggered 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog文档:FingersCrossedHandler
DeduplicationHandler
在发生关键错误时发送通知或电子邮件非常有用。它接受一个记录器作为参数,并会在请求结束(或调用flush())之前累积所有级别的日志记录。在那个时刻,它将所有记录传递给它包装的处理程序,但仅当记录在给定时间间隔内是唯一的(默认为60秒)。如果记录是重复的,则直接丢弃。这个处理程序的主要用途是在关键失败的情况下,例如如果数据库无法访问,所有请求都将失败,这可能导致发送大量通知。添加此处理程序可以减少通知的数量到可管理的水平。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'deduplication', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'deduplicationStore' => '/tmp/somestore', // Optional: The file/path where the deduplication log should be kept 'deduplicationLevel' => \Psr\Log\LogLevel::ERROR, // Optional:The minimum logging level for log records to be looked at for deduplication purposes 'time' => 60, // Optional: The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:DeduplicationHandler
WhatFailureGroupHandler
此处理程序扩展了GroupHandler,忽略每个子处理程序引发的异常。这允许你在远程TCP连接可能已死的情况下忽略问题,但你不想整个应用程序崩溃,可能希望继续向其他处理程序记录。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'whatFailureGroup', 'options' => [ 'handlers' => [], // Required: Array of Handlers to wrap 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:WhatFailureGroupHandler
FallbackGroupHandler
此处理程序扩展了GroupHandler,忽略每个子处理程序引发的异常,直到有一个没有引发异常的处理程序。这允许你在远程TCP连接可能已死的情况下忽略问题,但你不想整个应用程序崩溃,可能希望继续尝试向其他处理程序记录,直到没有引发异常的处理程序。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'fallbackgroup', 'options' => [ 'handlers' => [], // Required: Array of Registered Handlers to wrap 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:FallbackGroupHandler
BufferHandler
此处理程序将接收到的所有日志记录缓冲起来,直到调用close(),此时它将一次性调用包装处理程序的handleBatch(),将所有日志消息传递给它。例如,这对于一次性发送包含所有记录的电子邮件非常有用,而不是为每条日志记录发送一封电子邮件。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'buffer', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'bufferLimit' => 0, // Optional: How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'flushOnOverflow' => true, // Optional: If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:BufferHandler
GroupHandler
此处理程序将其他处理程序分组。每个接收到的记录都会发送到它配置的所有处理程序。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'group', 'options' => [ 'handlers' => [], // Required: Array of Registered Handlers to wrap 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:GroupHandler
FilterHandler
简单的处理程序包装器,根据级别列表过滤记录
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'filter', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'minLevelOrList' => \Psr\Log\LogLevel::DEBUG, // Optional: An array of levels to accept or a minimum level if maxLevel is provided 'maxLevel' => \Psr\Log\LogLevel::EMERGENCY, // Optional: Maximum level to accept, only used if $minLevelOrList is not an array 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:FilterHandler
SamplingHandler
采样事件流在生产环境中记录高频率事件非常有用,您只需要了解发生了什么,而不关心捕获每个发生的事件。由于处理或未处理特定事件的决策是随机决定的,因此生成的采样日志不保证包含应用程序中发生的1/N事件,但根据大数定律,在大规模尝试中,它将接近这个比例。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'sampling', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'factor' => 5, // Required: Sample factor 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档:SamplingHandler
NoopHandler
此处理程序通过什么都不做处理任何内容。它不会停止处理堆栈的其余部分。这可以用于测试,或在覆盖配置时禁用处理程序。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'noop', 'options' => [], ], ], ], ], ];
Monolog 文档:NoopHandler
NullHandler
它可以处理任何记录并将其丢弃。这可以用于在现有堆栈上临时覆盖它。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'null', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered ], ], ], ], ], ];
Monolog 文档:NullHandler
PsrHandler
可以用于将日志记录转发到现有的PSR-3记录器
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'psr', 'options' => [ 'logger' => 'loggerService', // Required: Logger Service to wrap from the container 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. ], ], ], ], ], ];
Monolog 文档:PsrHandler
TestHandler
用于测试,它记录发送给它的所有内容,并提供访问器来读取信息。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'test', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: TestHandler
OverflowHandler
此处理程序将缓冲接收到的所有日志消息,直到达到配置的消息数量阈值,之后将所有日志消息传递给包装的处理程序。在您只对重大失败感兴趣而不是对较小、单个错误事件感兴趣时,适用于批量处理。
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'overflow', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'thresholdMap' => [ // Optional: threshold map 'debug' => 0, // Optional: debug threshold. Default: 0 'info' => 0, // Optional: info threshold. Default: 0 'notice' => 0, // Optional: notice threshold. Default: 0 'warning' => 0, // Optional: warning threshold. Default: 0 'error' => 0, // Optional: error threshold. Default: 0 'critical' => 0, // Optional: critical threshold. Default: 0 'alert' => 0, // Optional: alert threshold. Default: 0 'emergency' => 0, // Optional: emergency threshold. Default: 0 ], 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
Monolog 文档: OverflowHandler
第三方处理器
MicrosoftTeamsHandler
将记录发送到 Microsoft Teams Webhook。需要包 actived/microsoft-teams-notifier
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'microsoft-teams', 'options' => [ 'url' => '', // Required: Url of the MS Teams Webhook 'title' => '', // Optional: Default Message Title 'subject' => '', // Optional: Message Subject 'emoji' => '', // Optional: custom emoji for the Message (added to the title) 'color' => '', // Optional: custom color for the Message 'format' => '', // Optional: Message format (only used in the default formatter) 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
TeamsLogHandler
将记录发送到 Microsoft Teams Webhook。需要包 cmdisp/monolog-microsoft-teams
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'teams', 'options' => [ 'url' => '', // Required: Url of the MS Teams Webhook 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'formatter' => [], // Optional: Formatter for the handler. 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
CallbackFilterHandler
使用回调函数过滤记录。需要 bartlett/monolog-callbackfilterhandler
<?php return [ 'log' => [ 'default' => [ 'handlers' => [ 'myHandlerName' => [ 'type' => 'callbackfilter', 'options' => [ 'handler' => [], // Required: Registered Handler to wrap 'filters' => [], // Optional: An array of callback functions 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this handler will be triggered 'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not 'processors' => [], // Optional: Processors for the handler. ], ], ], ], ], ];
格式化器
LineFomatter
将日志记录格式化为单行字符串。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'line', 'options' => [ 'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n", // Optional 'dateFormat' => "c", // Optional : The format of the timestamp: one supported by DateTime::format 'allowInlineLineBreaks' => false, // Optional : Whether to allow inline line breaks in log entries 'ignoreEmptyContextAndExtra' => false, // Optional 'includeStacktraces' => false, // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: LineFormatter
HtmlFormatter
用于将日志记录格式化为人类可读的 HTML 表格,主要适用于电子邮件。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'html', 'options' => [ 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: HtmlFormatter
NormalizerFormatter
将对象/资源规范化为字符串,以便轻松序列化/编码。需要 json 扩展。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'normalizer', 'options' => [ 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: NormalizerFormatter
ScalarFormatter
用于将日志记录格式化为标量值的关联数组。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'scalar', 'options' => [ 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: ScalarFormatter
JsonFormatter
将日志记录编码为 json。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'json', 'options' => [ 'batchMode' => \Monolog\Formatter\JsonFormatter::BATCH_MODE_JSON, // Optional 'appendNewline' => true, // Optional 'ignoreEmptyContextAndExtra' => false, // Optional 'includeStacktraces' => false, // Optional 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: JsonFormatter
WildfireFormatter
用于将日志记录格式化为 Wildfire/FirePHP 协议,仅适用于 FirePHPHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'wildfire', 'options' => [ 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: WildfireFormatter
ChromePHPFormatter
用于将日志记录格式化为 ChromePHP 格式,仅适用于 ChromePHPHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'chromePHP', 'options' => [], // No options available ], ], ], ], ];
Monolog 文档: ChromePHPFormatter
GelfMessageFormatter
用于将日志记录格式化为 Gelf 消息实例,仅适用于 GelfHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'gelf', 'options' => [ 'systemName' => "my-system", // Optional : the name of the system for the Gelf log message, defaults to the hostname of the machine 'extraPrefix' => "extra_", // Optional : a prefix for 'extra' fields from the Monolog record 'contextPrefix' => 'ctxt_', // Optional : a prefix for 'context' fields from the Monolog record 'maxLength' => 32766, // Optional : Length per field 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: GelfMessageFormatter
LogstashFormatter
用于将日志记录格式化为 Logstash 事件 json,对于此处列出的任何输入处理程序都很有用。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'logstash', 'options' => [ 'applicationName' => 'app-name', // the application that sends the data, used as the "type" field of logstash 'systemName' => "my-system", // Optional : the system/machine name, used as the "source" field of logstash, defaults to the hostname of the machine 'extraPrefix' => "extra_", // Optional : prefix for extra keys inside logstash "fields" 'contextPrefix' => 'ctxt_', // Optional : prefix for context keys inside logstash "fields", defaults to ctxt_ 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: LogstashFormatter
ElasticaFormatter
用于将日志记录格式化为 Elastica 文档。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'ElasticaFormatter' => [ 'type' => 'elastica', 'options' => [ 'index' => 'some-index', // Elastic search index name 'type' => "doc-type", // Elastic search document type 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: ElasticaFormatter
ElasticsearchFormatter
用于将日志记录格式化为 Elasticsearch 文档。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'ElasticsearchFormatter' => [ 'type' => 'elasticsearch', 'options' => [ 'index' => 'some-index', // Elastic search index name 'type' => "doc-type", // Elastic search document type 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: ElasticsearchFormatter
LogglyFormatter
用于将日志记录格式化为 Loggly 消息,仅适用于 LogglyHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'loggly', 'options' => [ 'batchMode' => \Monolog\Formatter\JsonFormatter::BATCH_MODE_NEWLINES, // Optional 'appendNewline' => false, // Optional 'includeStacktraces' => false, // Optional 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档: LogglyFormatter
FlowdockFormatter
用于将日志记录格式化为 Flowdock 消息,仅适用于 FlowdockHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'flowdock', 'options' => [ 'source' => 'Some Source', 'sourceEmail' => 'source@email.com' ], ], ], ], ], ];
Monolog 文档: FlowdockFormatter
MongoDBFormatter
将 \DateTime 实例转换为 \MongoDate,并将对象递归转换为数组,仅适用于 MongoDBHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'mongodb', 'options' => [ 'maxNestingLevel' => 3, // optional : 0 means infinite nesting, the $record itself is level 1, $record['context'] is 2 'exceptionTraceAsString' => true, // optional : set to false to log exception traces as a sub documents instead of strings ], ], ], ], ], ];
Monolog 文档: MongoDBFormatter
LogmaticFormatter
用户将日志记录格式化为Logmatic消息,仅适用于LogmaticHandler。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'logmatic', 'options' => [ 'batchMode' => \Monolog\Formatter\LogmaticFormatter::BATCH_MODE_JSON, // Optional 'appendNewline' => true, // Optional 'ignoreEmptyContextAndExtra' => false, // Optional 'includeStacktraces' => false, // Optional 'dateFormat' => "c", // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
Monolog 文档:LogmaticFormatter
FluentdFormatter
将日志消息序列化为Fluentd的Unix套接字协议。需要json扩展。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'fluentd', 'options' => [ 'levelTag' => false, // Optional ], ], ], ], ], ];
Monolog 文档:FluentdFormatter
StreamFormatter
使用symfony表格格式化消息。需要StreamFormatter。
<?php return [ 'log' => [ 'default' => [ 'formatters' => [ 'myFormatterName' => [ 'type' => 'stream', 'options' => [ 'format' => "%message%", // Optional 'tableStyle' => 'box', // Optional 'dateFormat' => "c", // Optional : The format of the timestamp: one supported by DateTime::format 'allowInlineLineBreaks' => false, // Optional : Whether to allow inline line breaks in log entries 'includeStacktraces' => false, // Optional 'maxNormalizeDepth' => 9, // Optional 'maxNormalizeItemCount' => 1000, // Optional 'prettyPrint' => false, // Optional ], ], ], ], ], ];
处理器
PsrLogMessageProcessor
根据PSR-3规则处理日志记录的消息,将{foo}替换为$context['foo']中的值。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'psrLogMessage', 'options' => [ 'dateFormat' => "c", // Optional 'removeUsedContextFields' => false, // Optional ], ], ], ], ], ];
Monolog 文档:PsrLogMessageProcessor
IntrospectionProcessor
添加日志调用来源的行、文件、类和方法。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'introspection', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this processor will be triggered 'skipClassesPartials' => [], // Optional 'skipStackFramesCount' => 0, // Optional ], ], ], ], ], ];
Monolog 文档:IntrospectionProcessor
WebProcessor
将当前请求URI、请求方法和客户端IP添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'web', 'options' => [ 'serverData' => 'my-service', // Optional: Array, object w/ ArrayAccess, or valid service name that provides access to the $_SERVER data 'extraFields' => [], // Optional: Field names and the related key inside $serverData to be added. If not provided it defaults to: url, ip, http_method, server, referrer ], ], ], ], ], ];
Monolog 文档:WebProcessor
MemoryUsageProcessor
将当前内存使用情况添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'memoryUsage', 'options' => [ 'realUsage' => true, 'useFormatting' => true, ], ], ], ], ], ];
Monolog 文档:MemoryUsageProcessor
MemoryPeakUsageProcessor
将峰值内存使用情况添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'memoryPeak', 'options' => [ 'realUsage' => true, 'useFormatting' => true, ], ], ], ], ], ];
Monolog 文档:MemoryPeakUsageProcessor
ProcessIdProcessor
将进程ID添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'processId', 'options' => [], // No options ], ], ], ], ];
Monolog 文档:ProcessIdProcessor
UidProcessor
将唯一标识符添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'uid', 'options' => [ 'length' => 7, // Optional: The uid length. Must be an integer between 1 and 32 ], ], ], ], ], ];
Monolog 文档:UidProcessor
GitProcessor
将当前git分支和提交添加到日志记录中。
注意:只有当git可执行文件在您的当前工作路径中时才有效。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'git', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this processor will be triggered ], ], ], ], ], ];
Monolog 文档:GitProcessor
MercurialProcessor
将当前hg分支和提交添加到日志记录中。
注意:只有当hg可执行文件在您的当前工作路径中时才有效。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'mercurial', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this processor will be triggered ], ], ], ], ], ];
Monolog 文档:MercurialProcessor
TagProcessor
将预定义的标签数组添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'tags', 'options' => [ 'tags' => [], // Optional: Array of tags to add to records ], ], ], ], ], ];
Monolog 文档:TagProcessor
HostnameProcessor
将当前主机名添加到日志记录中。
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'hostname', 'options' => [], // No options ], ], ], ], ];
Monolog 文档:HostnameProcessor
RequestHeaderProcessor
将请求头添加到日志记录中。需要jk/monolog-request-header-processor
<?php return [ 'log' => [ 'default' => [ 'processors' => [ 'myProcessorsName' => [ 'type' => 'requestheader', 'options' => [ 'level' => \Psr\Log\LogLevel::DEBUG, // Optional: The minimum logging level at which this processor will be triggered ], ], ], ], ], ];
许可证
本软件包使用MIT许可证授权。
请参阅LICENSE.md
。