摩根印刷备用行日志为空白

时间:2017-06-06 03:31:35

标签: node.js winston morgan

我正在尝试将Morgan与winston transports和winston-daily-rotate-file包集成。我这样做的原因是winston用于其他记录器,我也试图将它用于此。

我在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}))

对于正在使用的流我从winston创建了一个记录器,每天都会创建一个日志:

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);
            }
        };

这个问题是有效的。但是日志以备用行显示为空白。这里的逻辑有什么问题,我该如何纠正它。以下是日志的来源:

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

0 个答案:

没有答案