A small Node library that determines your current log level.
Most logging libraries are just that - logging libraries. This one is different. It doesn't try to log your messages or connect to some fancy cloud-based aggregation service.
Instead - it provides you an API that allows you to determine, in code, what your current level is - based on process.evn.LOG_LEVEL
environmental variable.
This way you can align your various logging modules (morgan, winston and custom, for instance) to the same value.
npm install --save-dev levelog
The API is very simple - provided you required the levelog
module in the following manner:
const LOG_LEVEL = require('levelog');
LOG_LEVEL
provides the following immutable properties:
TRACE
DEBUG
INFO
WARNING
ERROR
FATAL
each corresponding to the current log level as set by process.env.LOG_LEVEL
.
You can, alternatively, override the function that determines the log level and the default log level (INFO
instead of TRACE
, in example below):
const init = require('levelog/lib/custom');
LOG_LEVEL = init(function(level) {
return (process.env.LOG_LEVEL === level.toLowerCase());
}, 'INFO');
which would then allow you to call the same API:
if (LOG_LEVEL.INFO) {
// do something when the log level is set to INFO
}
In addition to the current API, there will be a comparative API that would look something like this:
if (LOG_LEVEL.greaterOrEqual(INFO)) {
// do something when the log level is set to INFO
}