logwrangler
Advanced tools
Comparing version 0.0.6 to 0.0.8
@@ -34,2 +34,3 @@ var colors = require('colors'); | ||
logString.push('[' + data.ts.toString() + ']'); | ||
logString.push('(' + data.node + ')'); | ||
logString.push('(' + data.ns + ')'); | ||
@@ -48,3 +49,14 @@ logString.push('(' + data.ident + ')'); | ||
if(this.levelOrdering[data.level] >= this.levelOrdering[options.level]){ | ||
console.log(stringifyLogMessage(options, data)); | ||
var message = stringifyLogMessage(options, data); | ||
switch(data.level){ | ||
case 'WARN': | ||
console.warn(message); | ||
break; | ||
case 'ERROR': | ||
console.error(message); | ||
break; | ||
default: | ||
console.log(message); | ||
} | ||
} | ||
@@ -74,21 +86,26 @@ }; | ||
var fancyLog = function(options){ | ||
var logwrangler = function(options){ | ||
var self = this; | ||
self.levelToColor = levelToColor; | ||
self.levels = logLevels; | ||
self.levelOrdering = levelOrdering; | ||
self.types = extendedLevels; | ||
var outputs = []; | ||
self.overrides = {}; | ||
self.dfaults = { | ||
level: logLevels.INFO, | ||
ns: '', | ||
ident: '', | ||
message: '', | ||
node: '', | ||
data: {}, | ||
}; | ||
options = _.extend({ | ||
level: logLevels.INFO | ||
}, options); | ||
var log = self.log = function(data){ | ||
var log = function(data){ | ||
var dfaults = { | ||
level: logLevels.INFO, | ||
ns: '', | ||
ident: '', | ||
message: '', | ||
data: {}, | ||
}; | ||
data.data = parseDataObject(data.data); | ||
data = _.extend(dfaults, data); | ||
data = _.extend(_.cloneDeep(self.dfaults), data); | ||
data = _.extend(data, self.overrides); | ||
if(!data.type){ | ||
@@ -104,7 +121,7 @@ data.type = data.level; | ||
var use = function(output){ | ||
var use = self.use = function(output){ | ||
outputs.push(output); | ||
}; | ||
var useModule = function(moduleName, initParams){ | ||
var useModule = self.useModule = function(moduleName, initParams){ | ||
var mod; | ||
@@ -131,16 +148,18 @@ try { | ||
var setOverrides = self.setOverrides = function(overrides){ | ||
overrides = overrides || {}; | ||
var validOverridFields = ['ns', 'message', 'level', 'ident', 'node']; | ||
self.overrides = _.pick(overrides, validOverridFields); | ||
}; | ||
var copy = self.copy = function(){ | ||
return _.cloneDeep(self); | ||
}; | ||
setOverrides(options.overrides); | ||
use(consoleHandler); | ||
return _.extend(self, { | ||
levelToColor: levelToColor, | ||
levelOrdering: levelOrdering, | ||
levels: logLevels, | ||
types: extendedLevels, | ||
consoleHandler: consoleHandler, | ||
log: log, | ||
use: use, | ||
useModule: useModule | ||
}); | ||
}; | ||
var parentInst; | ||
var inst; | ||
@@ -153,3 +172,3 @@ module.exports = { | ||
inst = new fancyLog(options); | ||
inst = new logwrangler(options); | ||
return inst; | ||
@@ -156,0 +175,0 @@ }, |
{ | ||
"name": "logwrangler", | ||
"version": "0.0.6", | ||
"version": "0.0.8", | ||
"description": "Wrangle up your logging", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,12 +0,6 @@ | ||
var fancyLog = require('../index'); | ||
var logger = fancyLog.create({ | ||
level: fancyLog.levels.DEBUG, | ||
var logwrangler = require('../index'); | ||
var logger = logwrangler.create({ | ||
level: logwrangler.levels.DEBUG, | ||
}); | ||
logger.use(function(options, data){ | ||
//console.log(arguments); | ||
}); | ||
logger.useModule('myCoolMod', {}); | ||
@@ -60,2 +54,3 @@ | ||
ident: '123456', | ||
node: 'my test node', | ||
message: 'testing error', | ||
@@ -67,2 +62,26 @@ data: { | ||
logger.setOverrides({ | ||
ns: 'some default ns', | ||
level: logger.levels.INFO, | ||
node: 'datacenter-1' | ||
}); | ||
logger.log({ | ||
message: 'test' | ||
}); | ||
logger.use(function(options, data){ | ||
console.log(options); | ||
console.log('------------------------\ncustom handler') | ||
console.log(data); | ||
console.log('------------------------') | ||
}); | ||
var copy = logger.copy(); | ||
copy.log({ | ||
message: 'copy' | ||
}); | ||
logger.log({ | ||
message: 'original' | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9292
7
215
153
0