uci-utils-logger/src/logger.js

35 lines
858 B
JavaScript

import pino from 'pino'
let pretty = false
if(process.env.UCI_DEV) {
pretty = process.env.UCI_LOG_PRETTY || {translateTime:true, colorize:true, levelFirst:true }
pretty.search = process.env.UCI_LOG_SEARCH
}
let LOG = process.env.UCI_LOG || process.env.UCI_DEV
const logger = pino({
name: 'UCI',
enabled: !!LOG,
safe: true,
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res
},
prettyPrint: 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