hmpo-logger
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -22,5 +22,5 @@ var _ = require('underscore'); | ||
interpolate.getTokenValue = function (sources, key, arg, context) { | ||
interpolate.getTokenValue = function (sources, key, context) { | ||
if (!_.isArray(sources)) { sources = [ sources ]; } | ||
if (arg) { key = key + '.' + arg; } | ||
if (_.isArray(key)) { key = _.compact(key).join('.'); } | ||
if (!key) { return; } | ||
@@ -27,0 +27,0 @@ |
@@ -21,2 +21,12 @@ var winston = require('winston'), | ||
Logger.prototype._addMetaData = function (dest, definitions, tokenSources) { | ||
_.each(definitions, function (metaPath, metaName) { | ||
var val = interpolate.getTokenValue(tokenSources, metaPath, dest); | ||
val = interpolate.cleanValue(val); | ||
if (val !== undefined) { | ||
dest[metaName] = val; | ||
} | ||
}); | ||
}; | ||
Logger.prototype.log = function () { | ||
@@ -57,3 +67,3 @@ var args = Array.prototype.slice.call(arguments); | ||
// tokens are searched for tokens in this order: | ||
// tokens are searched in this order: | ||
var tokens = [ | ||
@@ -68,20 +78,8 @@ Logger.tokens, | ||
if (options.meta) { | ||
_.each(options.meta, function (metaPath, metaName) { | ||
var val = interpolate.getTokenValue(tokens, metaPath, null, meta); | ||
val = interpolate.cleanValue(val); | ||
if (val !== undefined) { | ||
meta[metaName] = val; | ||
} | ||
}); | ||
this._addMetaData(meta, options.meta, tokens); | ||
} | ||
// add request and outbound specific meta | ||
if (options.requestMeta && (level === 'request' || level === 'outbound')) { | ||
_.each(options.requestMeta, function (metaPath, metaName) { | ||
var val = interpolate.getTokenValue(tokens, metaPath, null, meta); | ||
val = interpolate.cleanValue(val); | ||
if (val !== undefined) { | ||
meta[metaName] = val; | ||
} | ||
}); | ||
// add request specific meta | ||
if (options.requestMeta && level === 'request') { | ||
this._addMetaData(meta, options.requestMeta, tokens); | ||
} | ||
@@ -91,3 +89,3 @@ | ||
msg = msg.replace(Logger.reToken(), function (match, key, hasArg, arg) { | ||
var val = interpolate.getTokenValue(tokens, key, arg, meta); | ||
var val = interpolate.getTokenValue(tokens, [key, arg], meta); | ||
return val !== undefined ? interpolate.cleanValue(val) : '-'; | ||
@@ -94,0 +92,0 @@ }); |
@@ -30,3 +30,3 @@ var winston = require('winston'), | ||
host: 'host', | ||
pm: 'env[pm_id]', | ||
pm: 'env.pm_id', | ||
sessionID: 'sessionID', | ||
@@ -38,3 +38,3 @@ verb: 'method', | ||
clientip: 'clientip', | ||
uniqueID: 'x-uniq-id', | ||
uniqueID: 'req.x-uniq-id', | ||
remoteAddress: 'connection.remoteAddress', | ||
@@ -41,0 +41,0 @@ hostname: 'hostname', |
{ | ||
"name": "hmpo-logger", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Consistent logging for hmpo apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,3 +66,3 @@ # hmpo-logger | ||
host: 'host', | ||
pm: 'env[pm_id]', | ||
pm: 'env.pm_id', | ||
sessionID: 'sessionID', | ||
@@ -74,3 +74,3 @@ verb: 'method', | ||
clientip: 'clientip', | ||
uniqueID: 'x-uniq-id', | ||
uniqueID: 'req.x-uniq-id', | ||
remoteAddress: 'connection.remoteAddress', | ||
@@ -77,0 +77,0 @@ hostname: 'hostname', |
@@ -64,5 +64,6 @@ | ||
}); | ||
it('should return value specified by dotted path', function () { | ||
interpolate.getTokenValue(source, 'value2', 'subvalue2').should.equal('2'); | ||
interpolate.getTokenValue(source, 'value3.subvalue3', 'subsubvalue3').should.equal(3); | ||
it('should return value specified by array of paths', function () { | ||
interpolate.getTokenValue(source, ['value2', 'subvalue2']).should.equal('2'); | ||
interpolate.getTokenValue(source, ['value3.subvalue3', 'subsubvalue3']).should.equal(3); | ||
interpolate.getTokenValue(source, ['value3.subvalue3', null, 'subsubvalue3']).should.equal(3); | ||
}); | ||
@@ -69,0 +70,0 @@ it('should return undefined for a nonexistant primative path', function () { |
@@ -28,2 +28,51 @@ | ||
describe('_addMeta', function () { | ||
var logger = new Logger('testname'); | ||
var sources = [ | ||
{ | ||
source: { | ||
name: 'value' | ||
} | ||
}, | ||
{ | ||
source: { | ||
name: 'notvalue' | ||
}, | ||
source2: { | ||
name: 'notvalue' | ||
} | ||
} | ||
]; | ||
it('should add first value found in sources', function () { | ||
var dest = { | ||
original: 'dest' | ||
}; | ||
logger._addMetaData(dest, { | ||
destName: 'source.name' | ||
}, sources); | ||
dest.should.deep.equal({ | ||
original: 'dest', | ||
destName: 'value' | ||
}); | ||
}); | ||
it('should ignore values not found in sources', function () { | ||
var dest = { | ||
original: 'dest' | ||
}; | ||
logger._addMetaData(dest, { | ||
destName: 'source.name.not.present' | ||
}, sources); | ||
dest.should.deep.equal({ | ||
original: 'dest' | ||
}); | ||
}); | ||
}); | ||
describe('log', function () { | ||
@@ -30,0 +79,0 @@ var logger; |
@@ -96,3 +96,3 @@ | ||
manager._options.meta.should.deep.equal({ | ||
pm: 'env[pm_id]', | ||
pm: 'env.pm_id', | ||
sessionID: 'sessionID', | ||
@@ -99,0 +99,0 @@ extra: 'extravalue' |
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
38251
882