My Log4js configure | based node.js
layout: {
type: 'pattern',
pattern: '%d - %m%n'
}
I user this method to record log
var duration = new Date() - t;
logger.info('Started', req.method, req.url, req.ip);
logger.info('Completed', req.url, res.statusCode, ('(' + duration + 'ms)').green);
Output to a log file
2016-07-13 14:24:37.188 - Started POST /findBalance ::ffff:127.0.0.1
2016-07-13 14:24:37.189 - Started POST /planadreport ::ffff:127.0.0.1
2016-07-13 14:24:37.278 - Completed /findBalance 200 [32m(90ms)[39m
2016-07-13 14:24:37.292 - Completed /planadreport 200 [32m(103ms)[39m
2016-07-13 14:26:38.028 - Started GET /advert ::ffff:127.0.0.1
2016-07-13 14:26:38.112 - [32mStarted GET / ::ffff:127.0.0.1[39m
2016-07-13 14:26:38.135 - [32mCompleted /advert 302 [32m(111ms)[39m[39m
2016-07-13 14:26:38.206 - [32mCompleted / 304 [32m(94ms)[39m[39m
2016-07-13 14:26:40.454 - [32mStarted GET /login ::ffff:127.0.0.1[39m
2016-07-13 14:26:40.549 - [32mCompleted /login 304 [32m(95ms)[39m[39m
Problems encountered
[32m and [39m =>it's the color start and end flag I do not record them to datafile.. However, any word I want to print color on the console
According to the doc of log4js, the color will effect via defining "%[ and %]" bloc. Get more details to ref https://github.com/nomiddlename/log4js-node/wiki/Layouts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.