-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactors logging to make it easier to turn up and down logging without having to redploy, standardizes on single quotes over double. Signed-off-by: Dan Cunningham <[email protected]> * change entry to debug Signed-off-by: Dan Cunningham <[email protected]> * Fix order of log levels Signed-off-by: Dan Cunningham <[email protected]> * set default to debug Signed-off-by: Dan Cunningham <[email protected]>
- Loading branch information
1 parent
dd00c1a
commit 3c3d0df
Showing
4 changed files
with
146 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Logging helpers for lambda | ||
* Set enviroment variable LOG_LEVEL to one of the following LEVELS to control | ||
* verbosity of logging. | ||
*/ | ||
|
||
var LEVELS = [ | ||
'TRACE', | ||
'DEBUG', | ||
'INFO', | ||
'WARN', | ||
'ERROR', | ||
]; | ||
|
||
var DEFAULT = 'DEBUG'; | ||
|
||
function log(level, message) { | ||
var setLevel = LEVELS.indexOf(process.env.LOG_LEVEL ? | ||
process.env.LOG_LEVEL : DEFAULT); | ||
if (LEVELS.indexOf(level) < setLevel) { | ||
return; | ||
} | ||
switch (level) { | ||
case 'INFO': | ||
console.info(message); | ||
break; | ||
case 'WARN': | ||
console.warn(message); | ||
break; | ||
case 'ERROR': | ||
console.error(message); | ||
break; | ||
default: // debug, trace | ||
console.log(message); | ||
break; | ||
} | ||
} | ||
module.exports.trace = function (message) { | ||
log('TRACE', message); | ||
}; | ||
module.exports.debug = function (message) { | ||
log('DEBUG', message); | ||
}; | ||
module.exports.info = function (message) { | ||
log('INFO', message); | ||
}; | ||
module.exports.warn = function (message) { | ||
log('WARN', message); | ||
}; | ||
module.exports.error = function (message) { | ||
log('ERROR', message); | ||
}; |
Oops, something went wrong.