salak-logger
v1.0.6
Published
logger for salak
Downloads
352
Readme
salak-logger
Salak logger, base on winston.
Install
npm install --save salak-logger
Usage
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')
Options
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
options for capture
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
options for transports
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
options for transportsDefaultOptions
type: Map
transportsDefaultOptions: {
file: {
maxFiles: 30, // 30 files
maxsize: 100 * 1024 * 1024 // 100m
}
}
options for category
transports
{Array<String|Transport>} transport referred to transports which definedlevel
{String} log level, default${options.defaultLevel}
options for categories
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}
License
MIT