I am trying to integrate Morgan with winston transports and winston-daily-rotate-file package. The reason why I am doing it is winston is used for some other logger and I am trying to use it for this as well.
I am creating a stream for morgan like this in ExpressJS:
application.use(morgan(`${process.id} :id [:date[clf]] :remote-addr - :remote-user ":method :url HTTP/:http-version" :status ":referrer" ":user-agent" :res[content-length] - :response-time ms`,{stream: stream}))
For the stream that is being used I have created a logger from winston like this which creates a log every day:
let logger = new (winston.Logger)({
exitOnError: false,
transports: [
new winston.transports.DailyRotateFile({
"filename": './log/access.log',
"datePattern": 'yyyy-MM-dd.',
"prepend": true,
"timestamp": true,
"json": false,
"level": require('../config/domain.conf')['env'] === 'local' ? 'debug' : 'info'
})
]
});
let stream = {
write: function(message, encoding){
logger.info(message);
}
};
This issue is it works. But the logs are coming with alternate lines as blank. What is the issue with the logic here and how do I rectify it. Following is how the logs come:
2017-06-05T14:37:48.275Z - info: af6f0e4f-0639-4df4-99e2-3b35587562f2 [05/Jun/2017:14:37:48 +0000] 127.0.0.1 - - "GET / HTTP/1.1" 304 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 14.828 ms
2017-06-05T14:37:49.792Z - info: f7997211-8e52-458d-9e33-bfcaf7deea4e [05/Jun/2017:14:37:49 +0000] 127.0.0.1 - - "GET / HTTP/1.1" 304 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 1.669 ms
2017-06-05T14:37:50.325Z - info: 6272936c-6110-4eb3-9614-bc53dbe21ae5 [05/Jun/2017:14:37:50 +0000] 127.0.0.1 - - "GET / HTTP/1.1" 304 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 0.756 ms
2017-06-05T14:37:50.859Z - info: b750f713-d18e-44a6-8254-cb48b0623bc2 [05/Jun/2017:14:37:50 +0000] 127.0.0.1 - - "GET / HTTP/1.1" 304 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 0.956 ms
2017-06-05T14:37:51.365Z - info: 5cd71694-6be9-40ae-a401-ffa8112fbc0d [05/Jun/2017:14:37:51 +0000] 127.0.0.1 - - "GET / HTTP/1.1" 304 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 0.764 ms
via Gary
No comments:
Post a Comment