jj-log
jj-log is a JSON logger that's as extendable as you want it to be.
Installation
$ npm install jj-log
Usage
Logging Strings
var jjLog = require( 'jj-log' )
var log = jjLog()
log( 'something happened!' )
Logging Objects
var jjLog = require( 'jj-log' )
var log = jjLog()
log({
type: 'user_created',
user: 'billbob@bill.com'
})
Without Timestamps
var jjLog = require( 'jj-log' )
var log = jjLog({
timestamps: false
})
log({
message: 'hello'
})
With Default Data
var jjLog = require( 'jj-log' )
var log = jjLog({
timestamps: false,
defaults: {
level: 'info',
package: 'jj-log'
}
})
log({
message: 'hello'
})
With Additional Methods
var jjLog = require( 'jj-log' )
var log = jjLog({
timestamps: false,
methods: {
fatal: {
level: 'fatal',
shouldWePanic: 'absolutely'
},
warn: {
level: 'warn',
shouldWePanic: 'probably not'
}
}
})
log.warn({
message: 'hello'
})
log.fatal({
message: 'hello'
})
Attributes May Be Functions
var fatalErrorsSoFar = 0
var jjLog = require( 'jj-log' )
var log = jjLog({
timestamps: false,
methods: {
fatal: {
level: 'fatal',
errorNumber: function(){
return fatalErrorsSoFar++
}
}
}
})
log.fatal({
message: 'oops'
})
log.fatal({
message: 'oops again'
})
Default May be Overriden at Any Level
var jjLog = require( 'jj-log' )
var log = jjLog({
timestamps: false,
defaults: {
level: 'info'
},
methods: {
warn: {
level: 'warn'
}
}
})
log()
log({
level: 'uh oh'
})
log.warn()
log.warn({
level: 'a bit worse this time'
})
jj-log May be Silenced for Debugging
var jjLog = require( 'jj-log' )
var log = jjLog({
silent: true
})
log()
This can also be acheived by setting the SILENCE_JJ_LOG
environment variable to true