1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Add a new log priority: important. Should make it easier to display interesting non-error messages.

This commit is contained in:
Simo Kinnunen 2014-06-02 12:19:52 +09:00
parent 1095c1ba97
commit 97c4d24a7a
4 changed files with 52 additions and 32 deletions

View file

@ -354,6 +354,10 @@ program
.option('-p, --priority <level>' .option('-p, --priority <level>'
, 'minimum log level' , 'minimum log level'
, Number , Number
, logger.Level.IMPORTANT)
.option('-n, --notify-priority <level>'
, 'minimum log level to cause a notification'
, Number
, logger.Level.WARNING) , logger.Level.WARNING)
.option('-s, --connect-sub <endpoint>' .option('-s, --connect-sub <endpoint>'
, 'sub endpoint' , 'sub endpoint'
@ -373,6 +377,7 @@ program
token: options.token token: options.token
, room: options.room , room: options.room
, priority: options.priority , priority: options.priority
, notifyPriority: options.notifyPriority
, endpoints: { , endpoints: {
sub: options.connectSub sub: options.connectSub
} }

View file

@ -41,7 +41,7 @@ module.exports = syrup.serial()
.catch(grouputil.NoGroupError, function() { .catch(grouputil.NoGroupError, function() {
currentGroup = newGroup 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) log.info('Subscribing to group channel "%s"', currentGroup.group)
channels.register(currentGroup.group, timeout || options.groupTimeout) channels.register(currentGroup.group, timeout || options.groupTimeout)
@ -64,7 +64,7 @@ module.exports = syrup.serial()
plugin.leave = function() { plugin.leave = function() {
return plugin.get() return plugin.get()
.then(function(group) { .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) log.info('Unsubscribing from group channel "%s"', group.group)
channels.unregister(group.group) channels.unregister(group.group)

View file

@ -10,6 +10,16 @@ var wirerouter = require('../../wire/router')
var wireutil = require('../../wire/util') var wireutil = require('../../wire/util')
var lifecycle = require('../../util/lifecycle') 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) { module.exports = function(options) {
var log = logger.createLogger('notify-hipchat') var log = logger.createLogger('notify-hipchat')
var client = Promise.promisifyAll(new Hipchatter(options.token)) var client = Promise.promisifyAll(new Hipchatter(options.token))
@ -40,8 +50,9 @@ module.exports = function(options) {
.handler()) .handler())
function push() { function push() {
var messages = buffer.splice(0).map(function(entry) { buffer.splice(0).forEach(function(entry) {
return util.format( client.notifyAsync(options.room, {
message: util.format(
'<strong>%s</strong>/<strong>%s</strong> %d [<strong>%s</strong>] %s' '<strong>%s</strong>/<strong>%s</strong> %d [<strong>%s</strong>] %s'
, logger.LevelLabel[entry.priority] , logger.LevelLabel[entry.priority]
, entry.tag , entry.tag
@ -49,17 +60,12 @@ module.exports = function(options) {
, entry.identifier , entry.identifier
, entry.message , entry.message
) )
}) , color: COLORS[entry.priority]
, notify: entry.priority >= options.notifyPriority
log.info('Sending %d message(s)', messages.length)
return client.notifyAsync(options.room, {
message: messages.join('<br>')
, color: 'purple'
, notify: true
, 'message_format': 'html' , 'message_format': 'html'
, token: options.token , token: options.token
}) })
})
} }
log.info('Listening for %s (or higher) level log messages', log.info('Listening for %s (or higher) level log messages',

View file

@ -9,18 +9,21 @@ Logger.Level = {
DEBUG: 1 DEBUG: 1
, VERBOSE: 2 , VERBOSE: 2
, INFO: 3 , INFO: 3
, WARNING: 4 , IMPORTANT: 4
, ERROR: 5 , WARNING: 5
, FATAL: 6 , ERROR: 6
, FATAL: 7
} }
// Exposed for other modules
Logger.LevelLabel = { Logger.LevelLabel = {
1: 'DBG' 1: 'DBG'
, 2: 'VRB' , 2: 'VRB'
, 3: 'INF' , 3: 'INF'
, 4: 'WRN' , 4: 'IMP'
, 5: 'ERR' , 5: 'WRN'
, 6: 'FTL' , 6: 'ERR'
, 7: 'FTL'
} }
Logger.globalIdentifier = '*' Logger.globalIdentifier = '*'
@ -40,17 +43,19 @@ function Log(tag) {
1: 'DBG' 1: 'DBG'
, 2: 'VRB' , 2: 'VRB'
, 3: 'INF' , 3: 'INF'
, 4: 'WRN' , 4: 'IMP'
, 5: 'ERR' , 5: 'WRN'
, 6: 'FTL' , 6: 'ERR'
, 7: 'FTL'
} }
this.styles = { this.styles = {
1: 'grey' 1: 'grey'
, 2: 'cyan' , 2: 'cyan'
, 3: 'green' , 3: 'green'
, 4: 'yellow' , 4: 'magenta'
, 5: 'red' , 5: 'yellow'
, 6: 'red' , 6: 'red'
, 7: 'red'
} }
this.localIdentifier = null this.localIdentifier = null
events.EventEmitter.call(this) events.EventEmitter.call(this)
@ -83,6 +88,10 @@ Log.prototype.info = function() {
this._write(this._entry(Logger.Level.INFO, arguments)) this._write(this._entry(Logger.Level.INFO, arguments))
} }
Log.prototype.important = function() {
this._write(this._entry(Logger.Level.IMPORTANT, arguments))
}
Log.prototype.warn = function() { Log.prototype.warn = function() {
this._write(this._entry(Logger.Level.WARNING, arguments)) this._write(this._entry(Logger.Level.WARNING, arguments))
} }