Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm making a Node.js app and I am using Winston for most of my logging purposes. I also aware of the Connect/Express logger function and know it has a stream option... Is it at all possible to output the stuff from Connect/Express's logger function to Winston? ...then I can have all the useful logging I need?

I find the logging that Connect/Express useful, but at the moment the two are sort of separate... I would must prefer to have it all running through Winston and it's transports.

How is that possible? Thanks, James

question from:https://stackoverflow.com/questions/9141358/how-do-i-output-connect-expresss-logger-output-to-winston

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is what i did to solve this very issue. Basically use the stream option in the connect/express logger module to pipe the messages through to winston. I chose to use winston.info logging level, use whatever level makes sense for you.

var winston = require('winston');
var express = require('express');

var app = express.createServer();

// enable web server logging; pipe those log messages through winston
var winstonStream = {
    write: function(message, encoding){
        winston.info(message);
    }
};
app.use(express.logger({stream:winstonStream}));

// now do the rest of your express configuration...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...