wo-core-coco/index.js

43 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
var colors = require('colors') // require后字符串被添加了一系列方法 str.white, str.inverse, ...
// colors.styles: bold,italic,underline,inverse,yellow,cyan,white,magenta,green,red,grey,blue,rainbow,zebra,random
// 自定义的 themes
colors.setTheme({
logprompt: 'inverse',
logok:'green',
logerror: 'red',
logwarn: 'magenta',
logtitle: 'cyan'
})
*/
const bunyan = require('bunyan')
const PrettyStream = require('bunyan-pretty-colors')
const path = require('path')
var prettyStdOut = new PrettyStream()
prettyStdOut.pipe(process.stdout)
var logger = function (option) {
option = option || {}
return bunyan.createLogger({
name: 'log',
src: false,
streams: [
{
level: 'info',
stream: prettyStdOut,
},
{
level: 'info',
type: 'rotating-file',
path: path.join(option.root || 'logbase/', '/', option.file || 'info.log'),
period: '1d', // daily rotation
count: 30, // keep 30 days
},
],
})
}
module.exports = logger // trace, debug, info, warn, error, fatal