README
sme-log
A lovely logger
install
yarn install sme-log
or
npm install sme-log
usage
- Base
import logSome from 'sme-log'
// 只在 dev 环境打印 only log when NODE_ENV: 'development' or 'dev'
window.ilog = logSome(process.env.NODE_ENV)
ilog('hallo world')
// Always log if force equal true 当 force 为 true 时,总是会打印
const force = true
ilog('hallo world~~', force)
// or
ilog('hallo world~~', 'force')
ilog({name: 'hwen', mes: 'halloooooooooooooooooo world'})
ilog.info({name: 'hwen', mes: 'halloooooooooooooooooo world'})
ilog.warn({name: 'hwen', mes: 'halloooooooooooooooooo world'})
ilog.error({name: 'hwen', mes: 'halloooooooooooooooooo world'})
- Set log level
level: 'info' || 'warn' || 'error'
// window.ilog = logSome(process.env.NODE_ENV, 'info')
window.ilog = logSome(process.env.NODE_ENV, 'warn')
// window.ilog = logSome(process.env.NODE_ENV, 'error')
// or
ilog.setLevel('error')
- Add name to log mes
only work for ilog.info
, ilog.warn
, ilog.error
const listErr = new Error('request list 403')
ilog.error('request get list error', listErr)
const params = {}
ilog.info('request params', params)
Note: if you want to assign window, you have better change your eslint config
globals: {
'ilog': false
}
Contributors
Thanks goes to these wonderful people (emoji key):
hwen 🤔 💻 🎨 📖 💡 |
---|
License
Copyright (c) 2017-present, hwen hwenleung@gmail.com