@magic/log
@magic/log
nodejs console.log with environment aware loglevels.
getting started
be in a nodejs project.
install
npm i --save-dev @magic/log
import
import log from '@magic/log'
usage:
log levels
all
set logLevel to all
log.setLevel('all')
log.setLevel(0)
warnings
only output warnings and errors
log.setLevel('warn')
log.setLevel(1)
errors
only log on error
log.setLevel('error')
log.setLevel(2)
log.resetLevel
if production, set logLevel to "warn", if development, "all"
log.resetLevel()
log.getLevel()
get current logLevel
log.getLevel()
log functions
log.info
only outputs if logLevel === 'all'
log.info('Some interesting yet useless information')
log.success
only outputs if logLevel === 'all'.
output of first argument is green.
log.success('yay', 'only the first', 'argument was green')
log.error
always outputs. first argument will be red
log.error('ERROR:', 'error messsage')
warn
outputs if logLevel === 'warn' || 'all'
log.warn('WARN:', 'warn message')
annotate
log.annotate('this message is subtle and greyed out')
hrtime
returns process.hrtime to use in log.timeTaken
const start = log.hrtime()
// get delta between one hrtime and another
const delta = log.hrtime(start)
timeTaken
print the s, ms or ns since start
const start = process.hrtime()
// full signature
log.timeTaken(start, 'before', 'after'),
// logs: 'before xxns after'
log.timeTaken(start)
// logs 'xxns' or xxms.
let [s, ns] = log.hrtime()
// simulate passing time, ~1ms here
ns -= 1000
log.timeTaken([s, ns], 'optional message will be prepended')
// logs 'optional message will be prepended xxms'
changelog
0.0.3
log.error now converts errors for better logging
0.1.0
use ecmascript modules
0.1.1
bump to get this version to be the default for install.
0.1.0-cjs was preferred, but is deprecated for a while now.
0.1.2
add log.hrtime and log.timeTaken
source
the source for this page is in the example directory and gets built and published to github using @magic/core