-
Notifications
You must be signed in to change notification settings - Fork 1
levels
The levels
option enables you to define custom level logging functions and levels.
{
fatal: 60,
error: 50,
warn: 40,
info: 30,
debug: 20,
trace: 10
}
The levels
option object is used to build the logger level functions. The key values, such as 'trace' become the function names. The Number
value is used in conjunction with the level
option.
Once the levels have been applied to the log object, you can call each level like so: log.warn('Don't do that!')
If you had a need to disable logging in your application you could add a { silent: Infinity }
log level. Once the level exists you could set it with log.level and all logging would cease. There would be a log.silent()
function however you just never use it.
This example changes the levels significantly:
import Perj from 'perj'
const levels = { silly: 100, crazy: 200, nuts: 300 }
const log = new Perj({ levels, level: 'silly' })
log.silly('This is a very silly log entry')
log.crazy('This log entry is just looney!')
log.nuts('And this one is a few screws loose')
// Standard out:
// {"level":"silly","lvl":100,"time":1525495702926,"msg":"This is a very silly log entry","data":""}
// {"level":"crazy","lvl":200,"time":1525495702930,"msg":"This log entry is just looney!","data":""}
// {"level":"nuts","lvl":300,"time":1525495702934,"msg":"And this one is a few screws loose","data":""}
Note: In the above example, the log
object will only have a silly
, crazy
, and nuts
log functions. The default levels such as info
do not get created.