mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-24 23:05:22 +02:00
More control over logger colors.
This commit is contained in:
@@ -4,12 +4,20 @@ var colors = require('colors')
|
||||
function Log(tag, stream) {
|
||||
this.tag = tag
|
||||
this.levels = {
|
||||
DEBUG: 'DBG'.grey
|
||||
, VERBOSE: 'VRB'.cyan
|
||||
, INFO: 'INF'.green
|
||||
, WARNING: 'WRN'.yellow
|
||||
, ERROR: 'ERR'.red
|
||||
, FATAL: 'FTL'.red
|
||||
DEBUG: 'DBG'
|
||||
, VERBOSE: 'VRB'
|
||||
, INFO: 'INF'
|
||||
, WARNING: 'WRN'
|
||||
, ERROR: 'ERR'
|
||||
, FATAL: 'FTL'
|
||||
}
|
||||
this.colors = {
|
||||
DBG: 'grey'
|
||||
, VRB: 'cyan'
|
||||
, INF: 'green'
|
||||
, WRN: 'yellow'
|
||||
, ERR: 'red'
|
||||
, FTL: 'red'
|
||||
}
|
||||
this.localIdentifier = null
|
||||
}
|
||||
@@ -42,9 +50,13 @@ Log.prototype.fatal = function() {
|
||||
this._write(this._format(this.levels.FATAL, arguments))
|
||||
}
|
||||
|
||||
Log.prototype._color = function(priority) {
|
||||
return priority[this.colors[priority]]
|
||||
}
|
||||
|
||||
Log.prototype._format = function(priority, args) {
|
||||
return util.format('%s/%s %d [%s] %s'
|
||||
, priority
|
||||
, this._color(priority)
|
||||
, this.tag
|
||||
, process.pid
|
||||
, this.localIdentifier || Log.globalIdentifier
|
||||
|
||||
Reference in New Issue
Block a user