mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
Save device logs to rethinkdb.
This commit is contained in:
parent
39989c6e7a
commit
389db73f08
8 changed files with 140 additions and 41 deletions
|
@ -6,20 +6,28 @@ var colors = require('colors')
|
|||
function Log(tag, stream) {
|
||||
this.tag = tag
|
||||
this.levels = {
|
||||
DEBUG: 'DBG'
|
||||
, VERBOSE: 'VRB'
|
||||
, INFO: 'INF'
|
||||
, WARNING: 'WRN'
|
||||
, ERROR: 'ERR'
|
||||
, FATAL: 'FTL'
|
||||
DEBUG: 1
|
||||
, VERBOSE: 2
|
||||
, INFO: 3
|
||||
, WARNING: 4
|
||||
, ERROR: 5
|
||||
, FATAL: 6
|
||||
}
|
||||
this.names = {
|
||||
1: 'DBG'
|
||||
, 2: 'VRB'
|
||||
, 3: 'INF'
|
||||
, 4: 'WRN'
|
||||
, 5: 'ERR'
|
||||
, 6: 'FTL'
|
||||
}
|
||||
this.colors = {
|
||||
DBG: 'grey'
|
||||
, VRB: 'cyan'
|
||||
, INF: 'green'
|
||||
, WRN: 'yellow'
|
||||
, ERR: 'red'
|
||||
, FTL: 'red'
|
||||
1: 'grey'
|
||||
, 2: 'cyan'
|
||||
, 3: 'green'
|
||||
, 4: 'yellow'
|
||||
, 5: 'red'
|
||||
, 6: 'red'
|
||||
}
|
||||
this.localIdentifier = null
|
||||
events.EventEmitter.call(this)
|
||||
|
@ -27,8 +35,8 @@ function Log(tag, stream) {
|
|||
|
||||
util.inherits(Log, events.EventEmitter)
|
||||
|
||||
Log.Entry = function(time, priority, tag, pid, identifier, message) {
|
||||
this.time = time
|
||||
Log.Entry = function(timestamp, priority, tag, pid, identifier, message) {
|
||||
this.timestamp = timestamp
|
||||
this.priority = priority
|
||||
this.tag = tag
|
||||
this.pid = pid
|
||||
|
@ -64,24 +72,20 @@ Log.prototype.fatal = function() {
|
|||
this._write(this._entry(this.levels.FATAL, arguments))
|
||||
}
|
||||
|
||||
Log.prototype._color = function(priority) {
|
||||
return priority[this.colors[priority]]
|
||||
}
|
||||
|
||||
Log.prototype._entry = function(priority, args) {
|
||||
return new Log.Entry(
|
||||
Date.now()
|
||||
, priority
|
||||
, this.tag
|
||||
, process.pid
|
||||
, this.localIdentifier || Log.globalIdentifier
|
||||
, this.localIdentifier || Logger.globalIdentifier
|
||||
, util.format.apply(util, args)
|
||||
)
|
||||
}
|
||||
|
||||
Log.prototype._format = function(entry) {
|
||||
return util.format('%s/%s %d [%s] %s'
|
||||
, this._color(entry.priority)
|
||||
, this._name(entry.priority)
|
||||
, entry.tag
|
||||
, entry.pid
|
||||
, entry.identifier
|
||||
|
@ -89,20 +93,27 @@ Log.prototype._format = function(entry) {
|
|||
)
|
||||
}
|
||||
|
||||
Log.prototype._name = function(priority) {
|
||||
return this.names[priority][this.colors[priority]]
|
||||
}
|
||||
|
||||
Log.prototype._write = function(entry) {
|
||||
console.error(this._format(entry))
|
||||
this.emit('entry', entry)
|
||||
Logger.emit('entry', entry)
|
||||
}
|
||||
|
||||
Log.globalIdentifier = '*'
|
||||
var Logger = new events.EventEmitter()
|
||||
|
||||
Log.createLogger = function(tag) {
|
||||
Logger.globalIdentifier = '*'
|
||||
|
||||
Logger.createLogger = function(tag) {
|
||||
return new Log(tag)
|
||||
}
|
||||
|
||||
Log.setGlobalIdentifier = function(identifier) {
|
||||
Log.globalIdentifier = identifier
|
||||
return Log
|
||||
Logger.setGlobalIdentifier = function(identifier) {
|
||||
Logger.globalIdentifier = identifier
|
||||
return Logger
|
||||
}
|
||||
|
||||
exports = module.exports = Log
|
||||
exports = module.exports = Logger
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue