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

More control over logger colors.

This commit is contained in:
Simo Kinnunen 2014-01-29 17:59:31 +09:00
parent 315418d790
commit 6fc2791ab2

View file

@ -4,12 +4,20 @@ var colors = require('colors')
function Log(tag, stream) { function Log(tag, stream) {
this.tag = tag this.tag = tag
this.levels = { this.levels = {
DEBUG: 'DBG'.grey DEBUG: 'DBG'
, VERBOSE: 'VRB'.cyan , VERBOSE: 'VRB'
, INFO: 'INF'.green , INFO: 'INF'
, WARNING: 'WRN'.yellow , WARNING: 'WRN'
, ERROR: 'ERR'.red , ERROR: 'ERR'
, FATAL: 'FTL'.red , FATAL: 'FTL'
}
this.colors = {
DBG: 'grey'
, VRB: 'cyan'
, INF: 'green'
, WRN: 'yellow'
, ERR: 'red'
, FTL: 'red'
} }
this.localIdentifier = null this.localIdentifier = null
} }
@ -42,9 +50,13 @@ Log.prototype.fatal = function() {
this._write(this._format(this.levels.FATAL, arguments)) this._write(this._format(this.levels.FATAL, arguments))
} }
Log.prototype._color = function(priority) {
return priority[this.colors[priority]]
}
Log.prototype._format = function(priority, args) { Log.prototype._format = function(priority, args) {
return util.format('%s/%s %d [%s] %s' return util.format('%s/%s %d [%s] %s'
, priority , this._color(priority)
, this.tag , this.tag
, process.pid , process.pid
, this.localIdentifier || Log.globalIdentifier , this.localIdentifier || Log.globalIdentifier