, (*1)
PSR-11 Monolog
This repository has moved and is no longer maintained. Please visit the new repo here: https://gitlab.com/blazon/psr11-monolog, (*2)
Monolog Factories for PSR-11, (*3)
Table of Contents
Installation
composer require wshafer/psr11-monolog
Usage
<?php
# Get the Channel Changer
$channel = $container->get('my-channel');
# Write to log
$channel->debug('Hi There');
Additional info can be found in the documentation, (*4)
Containers
Any PSR-11 container wil work. In order to do that you will need to add configuration
and register a new service that points to WShafer\PSR11MonoLog\MonologFactory
, (*5)
Below are some specific container examples to get you started, (*6)
Pimple
// Create Container
$container = new \Xtreamwayz\Pimple\Container([
// Logger using the default keys.
'logger' => new \WShafer\PSR11MonoLog\MonologFactory(),
// Another logger using a different channel configuration
'other' => function($c) {
return \WShafer\PSR11MonoLog\MonologFactory::channelTwo($c);
},
'config' => [
'monolog' => [
'handlers' => [
// At the bare minimum you must include a default handler config.
// Otherwise log entries will be sent to the void.
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
// Another Handler
'myOtherHandler' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/someother-log-file.txt',
],
],
],
'channels' => [
// Configure a second channel
'channelTwo' => [
'name' => 'MyOtherChannel',
'handlers' => [
'myOtherHandler',
],
],
],
],
],
]);
// Get the default channel
/** @var \Monolog\Logger $defaultChannel */
$defaultChannel = $container->get('logger');
// Write to the default channel
$defaultChannel->debug('Write to log');
// Get the second channel
/** @var \Monolog\Logger $channelTwo */
$channelTwo = $container->get('channelTwo');
// Write to the second channel
$channelTwo->debug('Write to log');
Zend Service Manager
<?php
// Create the container and define the services you'd like to use
$container = new \Zend\ServiceManager\ServiceManager([
'factories' => [
// Logger using the default keys.
'logger' => \WShafer\PSR11MonoLog\MonologFactory::class,
// Another logger using a different channel configuration
'channelTwo' => [\WShafer\PSR11MonoLog\MonologFactory::class, 'channelTwo']
]
]);
$container->setService(
'config',
[
'monolog' => [
'handlers' => [
// At the bare minimum you must include a default handler config.
// Otherwise log entries will be sent to the void.
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
// Another Handler
'myOtherHandler' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/someother-log-file.txt',
],
],
],
'channels' => [
// Configure a second channel
'channelTwo' => [
'name' => 'MyOtherChannel',
'handlers' => [
'myOtherHandler',
],
],
],
],
]
);
// Get the default channel
/** @var \Monolog\Logger $defaultChannel */
$defaultChannel = $container->get('logger');
// Write to the default channel
$defaultChannel->debug('Write to log');
// Get the second channel
/** @var \Monolog\Logger $channelTwo */
$channelTwo = $container->get('channelTwo');
// Write to the second channel
$channelTwo->debug('Write to log');
Frameworks
Any framework that use a PSR-11 should work fine. Below are some specific framework examples to get you started, (*7)
Zend Expressive
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/monolog.global.php
, (*8)
Configuration
config/autoload/monolog.global.php, (*9)
<?php
return [
'dependencies' => [
'factories' => [
// Logger using the default keys.
'logger' => \WShafer\PSR11MonoLog\MonologFactory::class,
// Another logger using a different channel configuration
'channelTwo' => [\WShafer\PSR11MonoLog\MonologFactory::class, 'channelTwo']
]
],
'monolog' => [
'handlers' => [
// At the bare minimum you must include a default handler config.
// Otherwise log entries will be sent to the void.
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
// Another Handler
'myOtherHandler' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/someother-log-file.txt',
],
],
],
'channels' => [
// Configure a second channel
'channelTwo' => [
'name' => 'MyOtherChannel',
'handlers' => [
'myOtherHandler',
],
],
],
],
];
Zend Framework 3
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/monolog.global.php
, (*10)
Configuration
config/autoload/monolog.global.php, (*11)
<?php
return [
'service_manager' => [
'factories' => [
// Logger using the default keys.
'logger' => \WShafer\PSR11MonoLog\MonologFactory::class,
// Another logger using a different channel configuration
'channelTwo' => [\WShafer\PSR11MonoLog\MonologFactory::class, 'channelTwo']
]
],
'monolog' => [
'handlers' => [
// At the bare minimum you must include a default handler config.
// Otherwise log entries will be sent to the void.
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
// Another Handler
'myOtherHandler' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/someother-log-file.txt',
],
],
],
'channels' => [
// Configure a second channel
'channelTwo' => [
'name' => 'MyOtherChannel',
'handlers' => [
'myOtherHandler',
],
],
],
],
];
Module Config
If you're not using the Zend Component Installer you will
also need to register the Module., (*12)
config/modules.config.php (ZF 3 skeleton), (*13)
<?php
return [
// ... Previously registered modules here
'WShafer\\PSR11MonoLog',
];
config/application.config.php (ZF 2 skeleton), (*14)
<?php
return [
'modules' => [
// ... Previously registered modules here
'WShafer\\PSR11MonoLog',
]
];
Configuration
Monolog uses four types of services that will each need to be configured for your application.
In addition you will need to create a named service that maps to the \WShafer\PSR11MonoLog\MonologFactory
based on the container you are using., (*15)
-
Named Services : These are services names wired up to a factory. The configuration will differ
based on the type of container / framework in use., (*16)
-
Channels : Channels are a great way to identify to which part of the application a record
is related. This is useful in big applications and is leveraged here., (*17)
Picture two loggers sharing a handler that writes to a single log file. Channels allow you to
identify the logger that issued every record. You can easily grep through the log files filtering
this or that channel., (*18)
-
Handlers : These services do all the heavy lifting and log your message to
the wired up system. There are many different handlers available to you, but he one
you will most likely want to use for basic file logging is the StreamHandler.
Tip: You can use the same handler for multiple channels., (*19)
-
Formatters : (Optional) Formatters are in charge of formatting the message
for the handler. Generally you can use the defualt formatter for the handler you are using, in
some circumstances you may however want to change the formatting of the message. Configuring
a formatter will let you customize the message being sent to the log., (*20)
-
Processors : (Optional) Processors can be used to add data, change the message, filter,
you name it. Monolog provides some built-in processors that can be used in your project. Look at the
Processors section for the list., (*21)
Minimal Configuration
A minimal configuration would consist of at least one default handler and one named service.
Please note that if you don't specify a default handler a NullHandler will be used
when you wire up the default logger., (*22)
Minimal Example (using Zend Expressive for the example):
<?php
return [
'dependencies' => [
'factories' => [
// Logger using the default keys.
'logger' => \WShafer\PSR11MonoLog\MonologFactory::class,
]
],
'monolog' => [
'handlers' => [
'default' => [
'type' => 'stream',
'options' => [
'stream' => '/var/log/some-log-file.txt',
],
],
],
],
];
Full Configuration
Full Example
<?php
return [
'dependencies' => [
'factories' => [
// Logger using the default keys.
'logger' => \WShafer\PSR11MonoLog\MonologFactory::class,
// Another logger using a different channel configuration
'channelTwo' => [\WShafer\PSR11MonoLog\MonologFactory::class, 'channelTwo']
]
],
'monolog' => [
'formatters' => [
// Array Keys are the names used for the formatters
'formatterOne' => [
// A formatter type or pre-configured service from the container
'type' => 'line',
// Formatter specific options. See formatters below
'options' => [
'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
'dateFormat' => "c",
'allowInlineLineBreaks' => true,
'ignoreEmptyContextAndExtra' => false,
],
],
'formatterTwo' => [
// A formatter type or pre-configured service from the container
'type' => 'line',
// Formatter specific options. See formatters below
'options' => [
'format' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
'dateFormat' => "c",
'allowInlineLineBreaks' => false,
'ignoreEmptyContextAndExtra' => true,
],
],
],
'handlers' => [
// Array Keys are the names used for the handlers
'default' => [
// A Handler type or pre-configured service from the container
'type' => 'stream',
// Optional: Formatter for the handler. Default for the handler will be used if not supplied
'formatter' => 'formatterOne',
// Handler specific options. See handlers below
'options' => [
'stream' => '/tmp/log_one.txt',
],
'processors' => [
'my-handler-processor',
],
],
'handlerTwo' => [
// A Handler type or pre-configured service from the container
'type' => 'stream',
// Optional: Formatter for the handler. Default for the handler will be used if not supplied
'formatter' => 'formatterTwo',
// Adaptor specific options. See adaptors below
'options' => [
'stream' => '/tmp/log_two.txt',
],
],
],
'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' => [],
],
'processorTwo' => [
// A processor type or pre-configured service from the container
'type' => 'uid',
// processor specific options. See processors below
'options' => [
'length' => 7,
],
],
'my-handler-processor' => [
// A processor type or pre-configured service from the container
'type' => 'psrLogMessage',
// processor specific options. See processors below
'options' => [],
],
],
'channels' => [
// Array Keys are the names used for the channels
//
// Note: You can specify "default" here to overwrite the default settings for the
// default channel. If no handler is defined for default then the default
// handler will be used.
'default' => [
// Optional: Name of channel to show in logs. Defaults to the array key
'name' => 'MyAppChannel',
// array of handlers to attach to the channel. Can use multiple handlers if needed.
'handlers' => ['handlerOne', 'handlerTwo'],
// optional array of processors to attach to the channel. Can use multiple processors if needed.
'processors' => ['processorOne', 'processorTwo'],
],
'channelTwo' => [
// Optional: Name of channel to show in logs. Defaults to the array key
'name' => 'MyOtherChannel',
// array of handlers to attach to the channel. Can use multiple handlers if needed.
'handlers' => ['handlerTwo'],
// optional array of processors to attach to the channel. Can use multiple processors if needed.
'processors' => ['processorTwo'],
],
],
],
];
Channels
<?php
return [
'monolog' => [
'channels' => [
// Array Keys are the channel identifiers
'myChannelName' => [
// Optional: Name of channel to show in logs. Defaults to the array key
'name' => 'MyChannelLogName',
// Array of configured handlers. See handlers for more info
'handlers' => [
'myHandler',
],
// Array of configured processors. See processors for more info
'processors' => [
'myProcessor',
],
],
],
],
];
Handlers
Log to files and syslog
StreamHandler
Logs records into any PHP stream, use this for log files., (*23)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'stream',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'stream' => '/tmp/stream_test.txt', // Required: File Path | Resource | Service Name
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: StreamHandler, (*24)
RotatingFileHandler
Logs records to a file and creates one logfile per day. It will also delete files older than $maxFiles.
You should use logrotate for high profile setups though,
this is just meant as a quick and dirty solution., (*25)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'rotating',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'filename' => '/tmp/stream_test.txt', // Required: File Path
'maxFiles' => 0, // Optional: The maximal amount of files to keep (0 means unlimited)
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: RotatingFileHandler, (*26)
SyslogHandler
Logs records to the syslog., (*27)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'syslog',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: SyslogHandler
PHP openlog(): openlog, (*28)
ErrorLogHandler
Logs records to PHP's error_log() function., (*29)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'errorlog',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'messageType' => \Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, // Optional: Says where the error should go.
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: ErrorLogHandler, (*30)
ProcessHandler
Logs records to the STDIN of any process, specified by a command., (*31)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'errorlog',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'command' => 'some-command', // Command for the process to start. Absolute paths are recommended, especially if you do not use the $cwd parameter.
'level' => \Monolog\Logger::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.
],
],
],
],
];
Monolog Docs: ProcessHandler, (*32)
Send alerts and emails
NativeMailerHandler
Sends emails using PHP's mail() function., (*33)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'nativeMailer',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: NativeMailerHandler, (*34)
SwiftMailerHandler
Sends emails using a Swift_Mailer instance., (*35)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'swiftMailer',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'mailer' => 'my-service', // The mailer to use. Must be a valid service name in the container
'message' => 'my-message', // An example message for real messages, only the body will be replaced. Must be a valid service name or callable
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: SwiftMailerHandler, (*36)
PushoverHandler
Sends mobile notifications via the Pushover API., (*37)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'pushover',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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' => \Monolog\Logger::WARNING, // Optional: The minimum logging level at which this handler will start sending "high priority" requests to the Pushover API
'emergencyLevel' => \Monolog\Logger::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).
],
],
],
],
];
Monolog Docs: PushoverHandler, (*38)
FlowdockHandler
Logs records to a Flowdock account., (*39)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'flowdock',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'apiToken' => 'sometokenhere', // HipChat API Token
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: FlowdockHandler, (*40)
SlackWebhookHandler
Logs records to a Slack account using Slack Webhooks., (*41)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'slackWebhook',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'webhookUrl' => 'webhook.slack.com', // Slack Webhook URL
'channel' => 'channel', // Slack channel (encoded ID or name)
'userName' => 'Monolog', // 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' => \Monolog\Logger::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
'excludeFields' => ['context.field1', 'extra.field2'], // Optional: Dot separated list of fields to exclude from slack message.
],
],
],
],
];
Monolog Docs: SlackWebhookHandler, (*42)
SlackHandler
Logs records to a SlackHandler account using the Slack API (complex setup)., (*43)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'slack',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'token ' => 'apiToken', // Slack API token
'channel' => 'channel', // Slack channel (encoded ID or name)
'userName' => 'Monolog', // 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' => \Monolog\Logger::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
'excludeFields' => ['context.field1', 'extra.field2'], // Optional: Dot separated list of fields to exclude from slack message.
],
],
],
],
];
Monolog Docs: SlackHandler, (*44)
SendGridHandler
Sends emails via the SendGrid API., (*45)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'sendgrid',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: SendGridHandler, (*46)
MandrillHandler
Sends emails via the Mandrill API using a Swift_Message instance., (*47)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'mandrill',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: MandrillHandler, (*48)
FleepHookHandler
Logs records to a Fleep conversation using Webhooks., (*49)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'fleepHook',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'token' => 'sometokenhere', // Webhook token
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: FleepHookHandler, (*50)
TelegramBotHandler
Logs records to a Telegram bot account., (*51)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'telegrambot',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'apiKey' => 'api-key', // Api Key
'channel' => 'api-key', // Channel
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: TelegramBotHandler, (*52)
Log specific servers and networked logging
SocketHandler
Logs records to sockets, use this for UNIX and TCP sockets. See an example., (*53)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'socket',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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, // Optional: The connection timeout, in seconds.
'writeTimeout' => 90, // Optional: Set timeout period on a stream.
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: SocketHandler, (*54)
AmqpHandler
Logs records to an AMQP compatible server. Requires the php-amqp extension (1.0+) or the php-amqplib library., (*55)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'amqp',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: AmqpHandler, (*56)
GelfHandler
Logs records to a Graylog2 server. Requires package graylog2/gelf-php., (*57)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'gelf',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'publisher' => 'my-service', // A Gelf\PublisherInterface object. Must be a valid service.
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: GelfHandler, (*58)
CubeHandler
Logs records to a Cube server., (*59)
Note: Cube is not under active development, maintenance or support by
Square (or by its original author Mike Bostock). It has been deprecated
internally for over a year., (*60)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'cube',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'url' => 'http://test.com:80', // A valid url. Must consist of three parts : protocol://host:port
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: CubeHandler, (*61)
ZendMonitorHandler
Logs records to the Zend Monitor present in Zend Server., (*62)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'zend',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: ZendMonitorHandler, (*63)
NewRelicHandler
Logs records to a NewRelic application., (*64)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'newRelic',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: NewRelicHandler, (*65)
LogglyHandler
Logs records to a Loggly account., (*66)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'loggly',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'token' => 'sometokenhere', // Webhook token
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: LogglyHandler, (*67)
RollbarHandler:
Logs records to a Rollbar account., (*68)
_Note: RollerbarHandler is out of date with upstream changes. In addition the Rollerbar library suggests using
the PsrHandler instead. See Rollerbar Docs for how to set this up., (*69)
Monolog Docs: RollbarHandler, (*70)
SyslogUdpHandler
Logs records to a remote Syslogd server., (*71)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'syslogUdp',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'host' => 'somewhere.com', // Host
'port' => 513, // Optional: Port
'facility' => 'Me', // Optional: Facility
'level' => \Monolog\Logger::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.
],
],
],
],
];
Monolog Docs: SyslogUdpHandler, (*72)
LogEntriesHandler
Logs records to a LogEntries account., (*73)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'logEntries',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'token' => 'sometokenhere', // Log token supplied by LogEntries
'useSSL' => true, // Optional: Whether or not SSL encryption should be used.
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: LogEntriesHandler, (*74)
InsightOpsHandler
Logs records to an InsightOps account., (*75)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'insightops',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: InsightOpsHandler, (*76)
LogmaticHandler
Logs records to a Logmatic account., (*77)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'logmatic',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: LogmaticHandler, (*78)
SqsHandler
Logs records to an AWS SQS queue., (*79)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'sqs',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'sqsClient' => 'my-service', // SQS Client. Must be a valid service name in the container.
'queueUrl' => 'url', // URL to SQS Queue
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: SqsHandler, (*80)
Logging in development
FirePHPHandler
Handler for FirePHP, providing inline console messages within FireBug., (*81)
Note: The Firebug extension isn't being developed or maintained any longer., (*82)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'firePHP',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: FirePHPHandler, (*83)
ChromePHPHandler
Handler for ChromePHP, providing inline console messages within Chrome., (*84)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'chromePHP',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: ChromePHPHandler, (*85)
BrowserConsoleHandler
Handler to send logs to browser's Javascript console with no browser extension required. Most browsers supporting
console API are supported., (*86)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'browserConsole',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: BrowserConsoleHandler, (*87)
PHPConsoleHandler
Handler for PHP Console,
providing inline console and notification popup messages within Chrome., (*88)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'phpConsole',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'options' => [], // Optional: See \Monolog\Handler\PHPConsoleHandler::$options for more details
'connector' => 'my-service', // Optional: Instance of \PhpConsole\Connector class. Must be a valid service.
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: PHPConsoleHandler, (*89)
Logging in development
RedisHandler
Logs records to a Redis server. Requires the php-redis
extension or the Predis library., (*90)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'redis',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: RedisHandler, (*91)
MongoDBHandler
Handler to write records in MongoDB via a Mongo extension connection., (*92)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'mongo',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'client' => 'my-mongo-service-name', // MongoDB library or driver instance.
'database' => 'my-db', // Database name
'collection' => 'collectionName', // Collection name
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: MongoDBHandler, (*93)
CouchDBHandler
Logs records to a CouchDB server., (*94)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'couchDb',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'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' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: CouchDBHandler, (*95)
DoctrineCouchDBHandler
Logs records to a CouchDB server via the Doctrine CouchDB ODM., (*96)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'doctrineCouchDb',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'client' => 'my-service', // CouchDBClient service name. Must be a valid container service
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: DoctrineCouchDBHandler, (*97)
ElasticaHandler
Logs records to an Elastic Search server., (*98)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'elastica',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'client' => 'my-service', // Elastica Client object. Must be a valid container service
'index' => 'monolog', // Optional: Elastic index name
'type' => 'record', // Optional: Elastic document type
'ignoreError' => false, // Optional: Suppress Elastica exceptions
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: ElasticSearchHandler, (*99)
DynamoDbHandler
Logs records to a DynamoDB table with the AWS SDK., (*100)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'dynamoDb',
'formatter' => 'formatterName', // Optional: Formatter for the handler. Default for the handler will be used if not supplied
'options' => [
'client' => 'my-service', // DynamoDbClient object. Must be a valid container service
'table' => 'monolog', // Table name
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: DynamoDbHandler, (*101)
Wrappers / Special Handlers
FingersCrossedHandler
A very interesting wrapper. It takes a logger as parameter and will accumulate log
records of all levels until a record exceeds the defined severity level. At which
point it delivers all records, including those of lower severity, to the handler it
wraps. This means that until an error actually happens you will not see anything in
your logs, but when it happens you will have the full information, including debug and
info records. This provides you with all the information you need, but only when you
need it., (*102)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'fingersCrossed',
'options' => [
'handler' => 'my-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
],
],
],
],
];
Monolog Docs: FingersCrossedHandler, (*103)
DeduplicationHandler
Useful if you are sending notifications or emails when critical errors occur. It takes
a logger as parameter and will accumulate log records of all levels until the end
of the request (or flush() is called). At that point it delivers all records to
the handler it wraps, but only if the records are unique over a given time
period (60 seconds by default). If the records are duplicates they are simply
discarded. The main use of this is in case of critical failure like if your database
is unreachable for example all your requests will fail and that can result in a lot
of notifications being sent. Adding this handler reduces the amount of notifications
to a manageable level., (*104)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'deduplication',
'options' => [
'handler' => 'my-handler', // Required: Registered Handler to wrap
'deduplicationStore' => '/tmp/somestore', // Optional: The file/path where the deduplication log should be kept
'deduplicationLevel' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: DeduplicationHandler, (*105)
WhatFailureGroupHandler
This handler extends the GroupHandler ignoring exceptions raised by each child handler.
This allows you to ignore issues where a remote tcp connection may have died but you
do not want your entire application to crash and may wish to continue to log to other handlers., (*106)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'whatFailureGroup',
'options' => [
'handlers' => ['my-handler-one'. 'my-handler-two'], // Required: Array of Registered Handlers to wrap
'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not
],
],
],
],
];
Monolog Docs: WhatFailureGroupHandler, (*107)
FallbackGroupHandler
This handler extends the GroupHandler ignoring exceptions raised by
each child handler, until one has handled without throwing. This allows
you to ignore issues where a remote tcp connection may have died but you
do not want your entire application to crash and may wish to continue to
attempt log to other handlers, until one does not throw., (*108)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'fallbackgroup',
'options' => [
'handlers' => ['my-handler-one'. 'my-handler-two'], // Required: Array of Registered Handlers to wrap
'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not
],
],
],
],
];
Monolog Docs: FallbackGroupHandler, (*109)
BufferHandler
This handler will buffer all the log records it receives until close() is called at which point it
will call handleBatch() on the handler it wraps with all the log messages at once. This is very
useful to send an email with all records at once for example instead of having one mail for
every log record., (*110)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'buffer',
'options' => [
'handler' => 'my-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' => \Monolog\Logger::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' => false, // Optional: If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded
],
],
],
],
];
Monolog Docs: BufferHandler, (*111)
GroupHandler
This handler groups other handlers. Every record received is sent to all the handlers it is configured with., (*112)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'group',
'options' => [
'handlers' => ['my-handler-one'. 'my-handler-two'], // Required: Array of Registered Handlers to wrap
'bubble' => true, // Optional: Whether the messages that are handled can bubble up the stack or not
],
],
],
],
];
Monolog Docs: GroupHandler, (*113)
FilterHandler
Simple handler wrapper that filters records based on a list of levels, (*114)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'filter',
'options' => [
'handler' => 'my-handler', // Required: Registered Handler to wrap
'minLevelOrList' => \Monolog\Logger::DEBUG, // Optional: An array of levels to accept or a minimum level if maxLevel is provided
'maxLevel' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: FilterHandler, (*115)
SamplingHandler
A sampled event stream can be useful for logging high frequency events in
a production environment where you only need an idea of what is happening
and are not concerned with capturing every occurrence. Since the decision to
handle or not handle a particular event is determined randomly, the
resulting sampled log is not guaranteed to contain 1/N of the events that
occurred in the application, but based on the Law of large numbers, it will
tend to be close to this ratio with a large number of attempts., (*116)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'sampling',
'options' => [
'handler' => 'my-handler', // Required: Registered Handler to wrap
'factor' => 5, // Required: Sample factor
],
],
],
],
];
Monolog Docs: SamplingHandler, (*117)
NoopHandler
This handler handles anything by doing nothing. It does not stop
processing the rest of the stack. This can be used for testing, or to
disable a handler when overriding a configuration., (*118)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'noop',
'options' => [],
],
],
],
];
Monolog Docs: NoopHandler, (*119)
NullHandler
Any record it can handle will be thrown away. This can be used
to put on top of an existing stack to override it temporarily., (*120)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'noop',
'options' => [
'level' => \Monolog\Logger::DEBUG, // Optional: The minimum logging level at which this handler will be triggered
],
],
],
],
];
Monolog Docs: NullHandler, (*121)
PsrHandler
Can be used to forward log records to an existing PSR-3 logger, (*122)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'psr',
'options' => [
'logger' => 'loggerService', // Required: Logger Service to wrap from the container
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: PsrHandler, (*123)
TestHandler
Used for testing, it records everything that is sent to it and has accessors to read out the information., (*124)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'test',
'options' => [
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: TestHandler, (*125)
OverflowHandler
This handler will buffer all the log messages it receives, up until a
configured threshold of number of messages of a certain lever is
reached, after it will pass all log messages to the wrapped handler.
Useful for applying in batch processing when you're only interested in
significant failures instead of minor, single erroneous events., (*126)
<?php
return [
'monolog' => [
'handlers' => [
'myHandlerName' => [
'type' => 'overflow',
'options' => [
'handlers' => 'my-handler', // Required: Registered Handler to wrap
'thresholdMap' => [ // Optional: threshold map
'debug' => 2, // Optional: debug threshold. Default: 0
'info' => 2, // Optional: info threshold. Default: 0
'notice' => 2, // Optional: notice threshold. Default: 0
'warning' => 2, // Optional: warning threshold. Default: 0
'error' => 2, // Optional: error threshold. Default: 0
'critical' => 2, // Optional: critical threshold. Default: 0
'alert' => 2, // Optional: alert threshold. Default: 0
'emergency' => 2, // Optional: emergency threshold. Default: 0
],
'level' => \Monolog\Logger::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
],
],
],
],
];
Monolog Docs: OverflowHandler, (*127)
LineFomatter
Formats a log record into a one-line string., (*128)
<?php
return [
'monolog' => [
'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
],
],
],
],
];
Monolog Docs: LineFormatter, (*129)
Used to format log records into a human readable html table, mainly suitable for emails., (*130)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'html',
'options' => [
'dateFormat' => "c", // Optional
],
],
],
],
];
Monolog Docs: HtmlFormatter, (*131)
Normalizes objects/resources down to strings so a record can easily be serialized/encoded., (*132)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'normalizer',
'options' => [
'dateFormat' => "c", // Optional
],
],
],
],
];
Monolog Docs: NormalizerFormatter, (*133)
Used to format log records into an associative array of scalar values., (*134)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'scalar',
'options' => [], // No options available
],
],
],
];
Monolog Docs: ScalarFormatter, (*135)
Encodes a log record into json., (*136)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'json',
'options' => [
'batchMode' => \Monolog\Formatter\JsonFormatter::BATCH_MODE_JSON, //optional
'appendNewline' => true, //optional
],
],
],
],
];
Monolog Docs: JsonFormatter, (*137)
Used to format log records into the Wildfire/FirePHP protocol, only useful for the FirePHPHandler., (*138)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'wildfire',
'options' => [
'dateFormat' => "c", // Optional
],
],
],
],
];
Monolog Docs: WildfireFormatter, (*139)
Used to format log records into the ChromePHP format, only useful for the ChromePHPHandler., (*140)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'chromePHP',
'options' => [], // No options available
],
],
],
];
Monolog Docs: ChromePHPFormatter, (*141)
Used to format log records into Gelf message instances, only useful for the GelfHandler., (*142)
<?php
return [
'monolog' => [
'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
],
],
],
],
];
Monolog Docs: GelfMessageFormatter, (*143)
Used to format log records into logstash event json, useful for any handler listed under inputs here., (*144)
<?php
return [
'monolog' => [
'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_
],
],
],
],
];
Monolog Docs: LogstashFormatter, (*145)
Used to format log records into logstash event json, useful for any handler listed
under inputs here., (*146)
<?php
return [
'monolog' => [
'formatters' => [
'ElasticaFormatter' => [
'type' => 'elastica',
'options' => [
'index' => 'some-index', // Elastic search index name
'type' => "doc-type", // Elastic search document type
],
],
],
],
];
Monolog Docs: ElasticaFormatter, (*147)
Used to format log records into Loggly messages, only useful for the LogglyHandler., (*148)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'loggly',
'options' => [
'batchMode' => \Monolog\Formatter\JsonFormatter::BATCH_MODE_NEWLINES, //optional
'appendNewline' => false, //optional
],
],
],
],
];
Monolog Docs: LogglyFormatter, (*149)
Used to format log records into Flowdock messages, only useful for the FlowdockHandler., (*150)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'flowdock',
'options' => [
'source' => 'Some Source',
'sourceEmail' => 'source@email.com'
],
],
],
],
];
Monolog Docs: FlowdockFormatter, (*151)
Converts \DateTime instances to \MongoDate and objects recursively to arrays, only useful with the MongoDBHandler., (*152)
<?php
return [
'monolog' => [
'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 Docs: MongoDBFormatter, (*153)
User to format log records to Logmatic messages, only useful for the
LogmaticHandler., (*154)
<?php
return [
'monolog' => [
'formatters' => [
'myFormatterName' => [
'type' => 'json',
'options' => [
'batchMode' => \Monolog\Formatter\LogmaticFormatter::BATCH_MODE_JSON, //optional
'appendNewline' => true, //optional
'hostname' => 'my-host', //optional 'hostname' parameter for indexing by Logmatic
'appName' => 'app name', //optional 'appname' parameter for indexing by Logmatic
],
],
],
],
];
Monolog Docs: LogmaticFormatter, (*155)
Processors
PsrLogMessageProcessor
Processes a log record's message according to PSR-3 rules, replacing {foo} with the value from $context['foo']., (*156)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'psrLogMessage',
'options' => [], // No options
],
],
],
];
Monolog Docs: PsrLogMessageProcessor, (*157)
IntrospectionProcessor
Adds the line/file/class/method from which the log call originated., (*158)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'introspection',
'options' => [
'level' => \Monolog\Logger::DEBUG, // Optional: The minimum logging level at which this processor will be triggered
'skipClassesPartials' => [], // Optional
'skipStackFramesCount' => 0, // Optional
],
],
],
],
];
Monolog Docs: IntrospectionProcessor, (*159)
WebProcessor
Adds the current request URI, request method and client IP to a log record., (*160)
<?php
return [
'monolog' => [
'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 Docs: WebProcessor, (*161)
MemoryUsageProcessor
Adds the current memory usage to a log record., (*162)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'memoryUsage',
'options' => [], // No options
],
],
],
];
Monolog Docs: MemoryUsageProcessor, (*163)
MemoryPeakUsageProcessor
Adds the peak memory usage to a log record., (*164)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'memoryPeak',
'options' => [], // No options
],
],
],
];
Monolog Docs: MemoryPeakUsageProcessor, (*165)
ProcessIdProcessor
Adds the process id to a log record., (*166)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'processId',
'options' => [], // No options
],
],
],
];
Monolog Docs: ProcessIdProcessor, (*167)
UidProcessor
Adds a unique identifier to a log record., (*168)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'uid',
'options' => [
'length' => 7, // Optional: The uid length. Must be an integer between 1 and 32
],
],
],
],
];
Monolog Docs: UidProcessor, (*169)
GitProcessor
Adds the current git branch and commit to a log record., (*170)
Note: Only works if the git executable is in your working path., (*171)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'git',
'options' => [
'level' => \Monolog\Logger::DEBUG, // Optional: The minimum logging level at which this processor will be triggered
],
],
],
],
];
Monolog Docs: GitProcessor, (*172)
MercurialProcessor
Adds the current hg branch and commit to a log record., (*173)
Note: Only works if the hg executable is in your working path., (*174)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'mercurial',
'options' => [
'level' => \Monolog\Logger::DEBUG, // Optional: The minimum logging level at which this processor will be triggered
],
],
],
],
];
Monolog Docs: MercurialProcessor, (*175)
TagProcessor
Adds an array of predefined tags to a log record., (*176)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'tags',
'options' => [
'tags' => [], // Optional: Array of tags to add to records
],
],
],
],
];
Monolog Docs: TagProcessor, (*177)
HostnameProcessor
Adds the current hostname to a log record., (*178)
<?php
return [
'monolog' => [
'processors' => [
'myProcessorsName' => [
'type' => 'hostname',
'options' => [], // No options
],
],
],
];
Monolog Docs: HostnameProcessor, (*179)
Upgrades
Version 2 to Version 3
Version 3 upgrade the Monolog package from version 1 to version 2. This
has many breaking changes with it. Please see the UPGRADE.md
for a list changes upstream., (*180)
This package also now requires PHP 7.2., (*181)
Version 1 to Version 2
When upgrading from version 1 to version 2, there shouldn't be any changes needed. Please note
that using the ChannelChanger directly is no longer recommended. Named services
should be used instead. See above for more info., (*182)
Changes
- A "default" channel entry and handler is added automatically to the config. This default
channel requires you to either specify a configured handler for the channel
OR there must be a 'default' channel configured in order to use it. Most Version 1
users should not have an issue with this change and the factories should still function
normally.