From 25b8eeabc94b57e260cec757975b704d0369c4ac Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 6 Feb 2012 15:23:51 -0800 Subject: [PATCH] Use 10/20/... instead of 1/2/... for level constant values. --- CHANGES.md | 5 +++++ README.md | 12 ++++++------ TODO.md | 4 ---- bin/bunyan | 22 +++++++++++++--------- lib/bunyan.js | 13 ++++++------- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 99b44f2..612994a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,11 @@ ## bunyan 0.5.0 (not yet released) +- Use 10/20/... instead of 1/2/... for level constant values. Ostensibly this + allows for intermediary levels from the defined "trace/debug/..." set. + However, that is discouraged. I'd need a strong user argument to add + support for easily using alternative levels. Consider using a separate + JSON field instead. - s/service/name/ for Logger name field. "service" is unnecessarily tied to usage for a service. No need to differ from log4j Logger "name". - Add `log.level(...)` and `log.levels(...)` API for changing logger stream diff --git a/README.md b/README.md index b69611b..27a7e9a 100644 --- a/README.md +++ b/README.md @@ -203,12 +203,12 @@ in production.** # Levels -- "fatal" (6): the service/app is going to stop or become unusable now -- "error" (5): fatal for a particular request, but the service/app continues servicing other requests -- "warn" (4): a note on something that should probably be looked at by an operator -- "info" (3): detail on regular operation -- "debug" (2): anything else, i.e. too verbose to be included in "info" level. -- "trace" (1): logging from external libraries used by your app +- "fatal" (60): the service/app is going to stop or become unusable now +- "error" (50): fatal for a particular request, but the service/app continues servicing other requests +- "warn" (40): a note on something that should probably be looked at by an operator +- "info" (30): detail on regular operation +- "debug" (20): anything else, i.e. too verbose to be included in "info" level. +- "trace" (10): logging from external libraries used by your app "debug" should be used sparingly. Information that will be useful to debug errors *post mortem* should usually be included in "info" messages if it's diff --git a/TODO.md b/TODO.md index 0adc196..685be8f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,3 @@ -- Logger.setLevel()? How to change level for a given stream. Default all, - else, give an index... or type ... or support stream "names". Some positives - to stream names. -- service -> name - 10, 20,... - bunyan cli: more layouts (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html) Custom log formats (in config file? in '-f' arg) using printf or hogan.js diff --git a/bin/bunyan b/bin/bunyan index c6c6f0c..629cd7d 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -31,12 +31,12 @@ var OM_FROM_NAME = { // Levels -var TRACE = 1; -var DEBUG = 2; -var INFO = 3; -var WARN = 4; -var ERROR = 5; -var FATAL = 6; +var TRACE = 10; +var DEBUG = 20; +var INFO = 30; +var WARN = 40; +var ERROR = 50; +var FATAL = 60; var levelFromName = { 'trace': TRACE, @@ -46,9 +46,13 @@ var levelFromName = { 'error': ERROR, 'fatal': FATAL }; -var nameFromLevel = [undefined].concat(Object.keys(levelFromName)); -var upperNameFromLevel = [undefined].concat( - Object.keys(levelFromName).map(function (l) { return l.toUpperCase(); })); +var nameFromLevel = {}; +var upperNameFromLevel = {}; +Object.keys(levelFromName).forEach(function (name) { + var lvl = levelFromName[name]; + nameFromLevel[lvl] = name; + upperNameFromLevel[lvl] = name.toUpperCase(); +}); diff --git a/lib/bunyan.js b/lib/bunyan.js index d2dacfd..1032ede 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -112,12 +112,12 @@ function getCaller3Info() { //---- Levels -var TRACE = 1; -var DEBUG = 2; -var INFO = 3; -var WARN = 4; -var ERROR = 5; -var FATAL = 6; +var TRACE = 10; +var DEBUG = 20; +var INFO = 30; +var WARN = 40; +var ERROR = 50; +var FATAL = 60; var levelFromName = { 'trace': TRACE, @@ -127,7 +127,6 @@ var levelFromName = { 'error': ERROR, 'fatal': FATAL }; -var nameFromLevel = [undefined].concat(Object.keys(levelFromName)); function resolveLevel(nameOrNum) { var level = (typeof(nameOrNum) === 'string'