Monolog is a logging library and provides a simple way to log to different logging means like to logstash, sentry, redis etc…

We need to configure Monolog handler as per our need.

Suppose we need to configure Monolog to send logs to Logstash. Check this blogCheck this blog (If you set up everything correctly, Monolog is sending the log message to Redis. Since Logstash is configured to listen to Redis, it will fetch the Message and send it to Elasticsearch. Open http://yourserver.tld:9292 and you should see the log message in Kibana.)
Here Monolog is configured to send logs using udp directly to a port to which logstash is configure to listen.
$socketHandler = new \Monolog\Handler\SocketHandler(
array_get($app, ‘config.logstash.connection_string’, ‘udp://’)
Since we are sending data to a port we are creating a socket connection to open a port.
In the above blog we are sending data to Redis Server, so we are using RedisHandler.

We can set the minimum level of error that should be sent to any handler when we setup the handler. Above handler sends all the logs as nothing is configured.

RavenHandler is for Sentry.
new \Monolog\Handler\RavenHandler(
new Raven_Client($app[‘config’][‘sentry.dsn’], [
‘environment’ => $app->environment(),
‘prefixes’ => [base_path()],
‘app_path’ => app_path(),
‘release’ => $app[‘config’][‘app.version’],
\Monolog\Logger::CRITICAL -> only critical errors sent to Sentry.

There’s a syslog handler which sends logs to syslog. This is generally used by the system admin.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s