In winston for Node.js is there a way to suppress log level from message?

早过忘川 提交于 2019-12-11 02:23:54

问题


I'm using winston to stream log messages from Express based on various comments elsewhere, my setup is essentially:

var express = require("express"),
    winston = require("winston");

// enable web server logging; pipe those log messages through winston
var requestLogger = new (winston.Logger)(
        {
            transports: [
                new (winston.transports.File)(
                    {
                        filename: "logs/request.log",
                        json: false,
                        timestamp: false
                    }
                )
            ]
        }
    ),
    winstonStream = {
        write: function(message, encoding) {
            requestLogger.info(message.replace(/(\r?\n)$/, ''));
        }
    };

this.use(express.logger({stream: winstonStream}));

But I'd like a way to suppress the output of the log level because I know for this particular logger it will always be "info". So rather than:

info: 127.0.0.1 - - [Fri, 20 Sep 2013 13:48:02 GMT] "POST /v1/submission HTTP/1.1" 200 261 "http://localhost:8887/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"

I would get:

127.0.0.1 - - [Fri, 20 Sep 2013 13:48:02 GMT] "POST /v1/submission HTTP/1.1" 200 261 "http://localhost:8887/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"

来源:https://stackoverflow.com/questions/18918896/in-winston-for-node-js-is-there-a-way-to-suppress-log-level-from-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!