<commit_before>var util = require('util');
var winston = require('winston');
var pushbullet = require('pushbullet');
var async = require('async');

var Pushbullet  = exports.Pushbullet = function (options) {

  this.name = 'pushbullet';
  this.level = options.level || 'warn';
  this.title = options.title || 'Winston Notification';
  this.apikey = options.apikey;
  this.devices = options.devices || '';
};

//
// Inherit from `winston.Transport` so you can take advantage
// of the base functionality and `.handleExceptions()`.
//
util.inherits(Pushbullet, winston.Transport);
winston.transports.Pushbullet = Pushbullet;

Pushbullet.prototype.log = function (level, msg, meta, callback) {
  var pusher = new pushbullet(this.apikey);
  if(!this.devices) {
    pusher.note('', this.title, msg, function(error, response) {
      if(error) callback(error,false);
      else callback(null,true);
    });
  } else {
    async.each(this.devices, function(device,callback){
      pusher.note(device, this.title, msg, function(error, response) {
        if(!error) callback();
        else callback(error);
      });
    }, function(err){
      if(!err) callback(null,true);
      else callback(error,false);
    });
  }
};<commit_msg>Add the option of letting winston-pushbullet handle exceptions by sending a Pushbullet.<commit_after>var util = require('util');
var winston = require('winston');
var pushbullet = require('pushbullet');
var async = require('async');

var Pushbullet  = exports.Pushbullet = function (options) {

  this.name = 'pushbullet';
  this.level = options.level || 'warn';
  this.title = options.title || 'Winston Notification';
  this.apikey = options.apikey;
  this.devices = options.devices || '';
  this.handleExceptions = options.handleExceptions || false;
};

//
// Inherit from `winston.Transport` so you can take advantage
// of the base functionality and `.handleExceptions()`.
//
util.inherits(Pushbullet, winston.Transport);
winston.transports.Pushbullet = Pushbullet;

Pushbullet.prototype.log = function (level, msg, meta, callback) {
  var pusher = new pushbullet(this.apikey);
  if(!this.devices) {
    pusher.note('', this.title, msg, function(error, response) {
      if(error) callback(error,false);
      else callback(null,true);
    });
  } else {
    async.each(this.devices, function(device,callback){
      pusher.note(device, this.title, msg, function(error, response) {
        if(!error) callback();
        else callback(error);
      });
    }, function(err){
      if(!err) callback(null,true);
      else callback(error,false);
    });
  }
};
{'fraction_non_alphanumeric': 0.1520648398301814, 'fraction_numerical': 0.0, 'mean_word_length': 3.956022944550669, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7117568', 'n_tokens_mistral': 794, 'n_tokens_neox': 778, 'n_words': 184}