1

我正在尝试将 Morgan 与 winston 传输和 winston-daily-rotate-file 包集成。我这样做的原因是winston被用于其他一些记录器,我也在尝试使用它。

我正在 ExpressJS 中为 morgan 创建一个流,如下所示:

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
4

0 回答 0