2018-05-16 07:17:49 -07:00
|
|
|
import pino from 'pino'
|
|
|
|
|
2018-12-04 09:52:45 -08:00
|
|
|
let pretty = false
|
2018-07-31 08:05:46 -07:00
|
|
|
if(process.env.UCI_DEV) {
|
2018-12-04 09:52:45 -08:00
|
|
|
pretty = process.env.UCI_LOG_PRETTY || {translateTime:true, colorize:true, levelFirst:true }
|
|
|
|
pretty.search = process.env.UCI_LOG_SEARCH
|
2018-05-16 07:17:49 -07:00
|
|
|
}
|
|
|
|
|
2018-07-31 08:05:46 -07:00
|
|
|
let LOG = process.env.UCI_LOG || process.env.UCI_DEV
|
2018-05-16 07:17:49 -07:00
|
|
|
|
|
|
|
const logger = pino({
|
|
|
|
name: 'UCI',
|
|
|
|
enabled: !!LOG,
|
|
|
|
safe: true,
|
|
|
|
serializers: {
|
|
|
|
req: pino.stdSerializers.req,
|
|
|
|
res: pino.stdSerializers.res
|
2018-12-04 09:52:45 -08:00
|
|
|
},
|
|
|
|
prettyPrint: pretty
|
|
|
|
})
|
2018-05-16 07:17:49 -07:00
|
|
|
|
|
|
|
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
|