klg-logger
log 工具,基于 tracer,简单,可以显示 log 的位置
配置
见 tracer 文档 https://www.npmjs.com/package/tracer
用法
简单版本
默认版本是把 log 输出到 console
import { Logger } from 'klg-logger'
const logger = new Logger({
level: config.get('log.level'),
dateformat: 'yyyy-mm-dd HH:MM:ss.L',
inspectOpt: {
showHidden: false,
depth: 5
}
})
logger.info('hello world')
logger.debug('hello %s', 'world')
logger.error('hello %s', 'error')
export default logger
自定义 transport
如果你需要把 log 输出到文件或者发送其他地方,可以自定义 transport function
const logger = new Logger({
level: 'log',
transport: function (data: Tracer.LogOutput) {
fs.write(data)
tcp.send(data)
assert(data)
assert(data.level === 0)
}
})
logger.log('hello world')