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

Minimal start with a custom logger and device tracker.

This commit is contained in:
Simo Kinnunen 2014-01-07 10:55:41 +09:00
parent 971fcb8297
commit f67eb6dd25
7 changed files with 126 additions and 0 deletions

59
lib/util/logger.js Normal file
View file

@ -0,0 +1,59 @@
var util = require('util')
function Log(tag, stream) {
this.tag = tag
this.stream = stream || process.stderr
this.levels = {
DEBUG: 'DBG'
, VERBOSE: 'VRB'
, INFO: 'INF'
, WARNING: 'WRN'
, ERROR: 'ERR'
, FATAL: 'FTL'
}
}
Log.prototype.debug = function() {
this._write(this._format(this.levels.DEBUG, arguments))
}
Log.prototype.verbose = function() {
this._write(this._format(this.levels.VERBOSE, arguments))
}
Log.prototype.info = function() {
this._write(this._format(this.levels.INFO, arguments))
}
Log.prototype.warn = function() {
this._write(this._format(this.levels.WARNING, arguments))
}
Log.prototype.error = function() {
this._write(this._format(this.levels.ERROR, arguments))
}
Log.prototype.fatal = function() {
this._write(this._format(this.levels.FATAL, arguments))
}
Log.prototype._format = function(priority, args) {
return util.format('%s %s/%s %d %s\n',
Log.prefix, priority, this.tag, process.pid, util.format.apply(util, args))
}
Log.prototype._write = function(out) {
this.stream.write(out)
}
Log.prefix = '*'
Log.createLogger = function(tag) {
return new Log(tag)
}
Log.setPrefix = function(prefix) {
Log.prefix = prefix
}
exports = module.exports = Log