uci-utils-logger/src/logger.js

35 lines
799 B
JavaScript
Raw Normal View History

import pino from 'pino'
let pretty = null
if(process.env.UCI_DEV || process.env.DEBUG) {
pretty = pino.pretty()
pretty.pipe(process.stdout)
}
let LOG = process.env.UCI_LOG || process.env.UCI_DEV || process.env.DEBUG
const logger = pino({
name: 'UCI',
enabled: !!LOG,
safe: true,
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res
}
},pretty)
function child (opts) {
const LOG_OPTS = {
repo: opts.repo || 'uci-'+ opts.name,
package: opts.package || '@uci/'+ opts.name,
file: opts.file || `src/${opts.name}.js`,
class: opts.class || (opts.name.charAt(0).toUpperCase() + opts.name.slice(1)),
id: opts.id || opts.name || 'none',
instance_created:new Date().getTime()
}
return logger.child(LOG_OPTS)
}
export default child