12 Mar 2015

Using Pushover for issue logging and notifications

Things go wrong within applications, in production. A good thing to do is to build a way to automatically capture and log the issue and related data. This way, these issues don’t just go unnoticed. And the location of the issue is known too, which is like half problem solved.

Here is an example source:

db.collection('products').findOne({url : link}, function(err, doc) {
  if (err) {
    // Some unexpected error here. What could it be?

    // Log it!


    return;
  }

  // ...

});

There are a lot of ways to log application errors from file to sending an email. I have even used Mixpanel (in cases where I am already using Mixpanel for other events). Another trick is using Twitter. Register a twitter account, make it private, ‘tweet’ the logs and follow the account. Or send the logs to yourself as DM. Another interesting way I recently discovered is using Pushover.

Pushover works in two simple steps.

  1. You create register an application (and get an API key). You can start sending notifications via the API or any of the apps and plugins.
  2. You add a device to receive notifications on. This can be any of the Android, iOS and desktop clients. Costs a one time $5 fee that is absolutely worth it. Once there is a notification for any of your app, the device gets the notification via push. You can also create groups and allow multiple people receive notifications for any of your applications.

Back to our example source, we can use Pushover to log the issue and send a notification. For NodeJs, I use the module Pushover Notifications.

var push = require('pushover-notifications'),
   // other modules here

  ;

// My PushOver tokens (set in my environment)

var pusher = new push({
    user: process.env['PUSHOVER_USER'],
    token: process.env['PUSHOVER_TOKEN']
  });

db.collection('products').findOne({url : link}, function(err, doc) {
  if (err) {
    pusher.send({
      title: 'DB error',
      message: 'Link: '+link+'; Error: '+err
    });
    return;
  }

  // ...

});

Once there is an error, this will send a push notification to my device (I am using the Android app). Easy and works.

PS: If you are looking for a logging class for PHP, check out Monolog.

My name is Opeyemi Obembe. I build things for web and mobile. You should follow me on Twitter (@kehers).