Fork me on GitHub

How to send notification mails from glog

The another feature of Glog is to trigger mail system to send a mail including log entry. Glog filters log messages and catch up only allow to send mail with selected levels in chosen channels. Let's examine our config first:

'notification' => ['blog-post' => ['ERROR', 'NOTICE']],

First, we must enter channel for filtering our log entries. Later we need to select log level. So if your application logs a message in blog-post channel in error level, glog will send it to the email address. Glog will ignore any messages in other levels or channels.

So if you log as follow, it will send mail:

Log::error('blog-post', ['message' => 'This is an error log and will trigger notification service']);

Because we want to receive a mail when an erro has thrown in blog-post channel. Hoeever this is not work:

Log::info('blog-post', ['message' => 'this is will not work!']);

This log is in 'blog-post' channel, but log level is wrong, it is only information level and we ignore it.

This will also not work:

Log::notice('blog-home', ['message' => 'this is will not work!']);

Yes, we have put a log level in notice, but it's not in 'blog-post' channel, it's in 'blog-home' which will be ignored.

Let's see some extended notification array with a lot of levels and channels:

'notification' => [
        'blog-post' => ['ERROR', 'NOTICE'],
        'blog-home' => ['EMERGENCY'],
        'blog-category' => ['ALERT', 'INFO', 'DEBUG'],
        'user-login' => ['ALERT', 'EMERGENCY'],
],

This feature can be run standalone without logging to the database. You may use notification standalone.

Posted in Glog on Jun 23, 2017