Salak logger, base on winston.
npm install --save salak-logger
const Koa = require('koa')
const logger = require('salak-logger')
const app = new Koa()
app.baseDir = __dirname
app.logger = logger({
fileType: 'dateFile',
formatType: 'log4js',
defaultLevel: 'debug'
}, app)
app.logger.info('log')
root
{String} directory for storing logs, defaultpath.join(app.baseDir, 'logs')
injectConsole
{Boolean} inject console transport for logger,defaulttrue
removeConsoleAfterServerStart
{Boolean} remove console transport after server start,defaultapp.env === 'production'
formatType
{String} type for logger format, log4js or json, defaultlog4js
fileType
{String} file type for storing log, file or dateFile, defaultfile
category
{Object} optional, defaultundefined
categories
{Object} optional, be used when category was unsetcapture
{Object} options to pass to the http request logdefaultLevel
{String} log output level, defaultapp.env === 'production' ? 'info' : 'debug'
transports
{Object} transports for categorytransportsDefaultOptions
{Object} default options for transports, likefile
,dateFile
enable
{Boolean} log the http request, defaulttrue
level
{String} logger level, when set toauto
, the logger level will be seted by http status code, defaultauto
category
{String} logger category, defaulthttp
type: Map
default:
transports: {
console: { type: 'console' },
default: createFileTransport({ filename: 'default' }),
app: !isSingleCategory && createFileTransport({ filename: 'app' }),
http: !isSingleCategory && createFileTransport({ filename: 'access' }),
error: createFileTransport({ filename: 'error', level: 'error' })
}
key
{String} transport namevalue
{Object} transport optionsvalue.type
{String} can be set to 'console', 'file', 'http', 'stream', 'dateFile', refer transport options, dateFile options
type: Map
transportsDefaultOptions: {
file: {
maxFiles: 30, // 30 files
maxsize: 100 * 1024 * 1024 // 100m
}
}
transports
{Array<String|Transport>} transport referred to transports which definedlevel
{String} log level, default${options.defaultLevel}
type: Map
default:
categories: {
default: {
transports: [
'default',
'error'
]
},
app: {
transports: [
'app',
'error'
]
},
http: {
transports: [
'http'
]
}
}
key
{String} category namevalue
{Object} category optionsvalue.transports
{Array<String|Transport>} transport referred to transports which definedvalue.level
{String} log level, default${options.defaultLevel}
MIT