diff --git a/lib/cli.js b/lib/cli.js index e8e197ab..ea667df5 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -354,6 +354,10 @@ program .option('-p, --priority ' , 'minimum log level' , Number + , logger.Level.IMPORTANT) + .option('-n, --notify-priority ' + , 'minimum log level to cause a notification' + , Number , logger.Level.WARNING) .option('-s, --connect-sub ' , 'sub endpoint' @@ -373,6 +377,7 @@ program token: options.token , room: options.room , priority: options.priority + , notifyPriority: options.notifyPriority , endpoints: { sub: options.connectSub } diff --git a/lib/roles/device/plugins/group.js b/lib/roles/device/plugins/group.js index 301062fe..7359fea2 100644 --- a/lib/roles/device/plugins/group.js +++ b/lib/roles/device/plugins/group.js @@ -41,7 +41,7 @@ module.exports = syrup.serial() .catch(grouputil.NoGroupError, function() { currentGroup = newGroup - log.info('Now owned by "%s"', currentGroup.email) + log.important('Now owned by "%s"', currentGroup.email) log.info('Subscribing to group channel "%s"', currentGroup.group) channels.register(currentGroup.group, timeout || options.groupTimeout) @@ -64,7 +64,7 @@ module.exports = syrup.serial() plugin.leave = function() { return plugin.get() .then(function(group) { - log.info('No longer owned by "%s"', group.email) + log.important('No longer owned by "%s"', group.email) log.info('Unsubscribing from group channel "%s"', group.group) channels.unregister(group.group) diff --git a/lib/roles/notify/hipchat.js b/lib/roles/notify/hipchat.js index c82c323a..3f909d47 100644 --- a/lib/roles/notify/hipchat.js +++ b/lib/roles/notify/hipchat.js @@ -10,6 +10,16 @@ var wirerouter = require('../../wire/router') var wireutil = require('../../wire/util') var lifecycle = require('../../util/lifecycle') +var COLORS = { + 1: 'gray' +, 2: 'gray' +, 3: 'green' +, 4: 'purple' +, 5: 'yellow' +, 6: 'red' +, 7: 'red' +} + module.exports = function(options) { var log = logger.createLogger('notify-hipchat') var client = Promise.promisifyAll(new Hipchatter(options.token)) @@ -40,25 +50,21 @@ module.exports = function(options) { .handler()) function push() { - var messages = buffer.splice(0).map(function(entry) { - return util.format( - '%s/%s %d [%s] %s' - , logger.LevelLabel[entry.priority] - , entry.tag - , entry.pid - , entry.identifier - , entry.message - ) - }) - - log.info('Sending %d message(s)', messages.length) - - return client.notifyAsync(options.room, { - message: messages.join('
') - , color: 'purple' - , notify: true - , 'message_format': 'html' - , token: options.token + buffer.splice(0).forEach(function(entry) { + client.notifyAsync(options.room, { + message: util.format( + '%s/%s %d [%s] %s' + , logger.LevelLabel[entry.priority] + , entry.tag + , entry.pid + , entry.identifier + , entry.message + ) + , color: COLORS[entry.priority] + , notify: entry.priority >= options.notifyPriority + , 'message_format': 'html' + , token: options.token + }) }) } diff --git a/lib/util/logger.js b/lib/util/logger.js index 624fe4ef..f8afb90f 100644 --- a/lib/util/logger.js +++ b/lib/util/logger.js @@ -9,18 +9,21 @@ Logger.Level = { DEBUG: 1 , VERBOSE: 2 , INFO: 3 -, WARNING: 4 -, ERROR: 5 -, FATAL: 6 +, IMPORTANT: 4 +, WARNING: 5 +, ERROR: 6 +, FATAL: 7 } +// Exposed for other modules Logger.LevelLabel = { 1: 'DBG' , 2: 'VRB' , 3: 'INF' -, 4: 'WRN' -, 5: 'ERR' -, 6: 'FTL' +, 4: 'IMP' +, 5: 'WRN' +, 6: 'ERR' +, 7: 'FTL' } Logger.globalIdentifier = '*' @@ -40,17 +43,19 @@ function Log(tag) { 1: 'DBG' , 2: 'VRB' , 3: 'INF' - , 4: 'WRN' - , 5: 'ERR' - , 6: 'FTL' + , 4: 'IMP' + , 5: 'WRN' + , 6: 'ERR' + , 7: 'FTL' } this.styles = { 1: 'grey' , 2: 'cyan' , 3: 'green' - , 4: 'yellow' - , 5: 'red' + , 4: 'magenta' + , 5: 'yellow' , 6: 'red' + , 7: 'red' } this.localIdentifier = null events.EventEmitter.call(this) @@ -83,6 +88,10 @@ Log.prototype.info = function() { this._write(this._entry(Logger.Level.INFO, arguments)) } +Log.prototype.important = function() { + this._write(this._entry(Logger.Level.IMPORTANT, arguments)) +} + Log.prototype.warn = function() { this._write(this._entry(Logger.Level.WARNING, arguments)) }