a log class
-
option
Object
class config optionoption.isErrorLog
Boolean
is save error log, iftrue
, when use logger.error('sth error') will write a log record in${logDir}/error.log
, default trueoption.isWarnLog
Boolean
is save warn log, iftrue
, when use logger.warn('sth warn') will write a log record in${logDir}/warn.log
, default trueoption.isStdout
Boolean
is str output stream, default trueoption.isPrd
Boolean
is production environment,iftrue
all the log level isinfo
, else level isall
, default falseoption.defaultLogType
String
default log4js appenders type, default is dateFileoption.defaultPattern
String
if defaultLogType isdateFile
, this option is effective, default is -yyyy-MM-dd.logoption.alwaysIncludePattern
Boolean
if defaultLogType isdateFile
, this option is effective, default is trueoption.logCategories
Array
, difference categories logger , requireoption.logDir
String
if defaultLogType isdateFile
orfile
, this option is effective, a dir string save the log files, default is logs -
-
category
String
which category logger the midware istype
String
a string indicate return which frame midware, supportkoa,koa2,koa1,express
,(koa = koa2) defaultkoa
return a midware function
-
category
String
which category logger is
-
-
// init const Log = require('g-log'); const log = new Log({ logCategories:['user', 'order'] }); const logMidware = log.getLogMidware('user') //koa app.use(logMidware); // business const logger = log.getLogger('user'); logger.info('log here'); // [2018-02-23T16:47:20.748] [INFO] user - log here // business midware app.use(async function(ctx,next) { ctx.logger.info('log here')// [2018-02-23T16:47:20.748] [INFO] user - log here })