Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I output Connect/Express's logger output to Winston?

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

like image 411
littlejim84 Avatar asked Feb 04 '12 13:02

littlejim84


People also ask

How do I set up a Winston logger?

Here's a guide that will help you understand NPM in detail. Install the Winston package using the command npm install winston . Logging with Winston is simple, with just four steps, as shown in the example below, and you have your log recorded. Add the Winston module with a require() function.

What is Winston logger?

winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs. Each winston logger can have multiple transports (see: Transports) configured at different levels (see: Logging levels).

Is Winston a middleware?

Usage. express-winston provides middlewares for request and error logging of your express. js application. It uses 'whitelists' to select properties from the request and (new in 0.2.

What is Winston in node JS?

Winston is the most popular logging library for Node. js. It aims to make logging more flexible and extensible by decoupling different aspects such as log levels, formatting, and storage so that each API is independent and many combinations are supported. It also uses Node.


1 Answers

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... 
like image 165
sethpollack Avatar answered Oct 18 '22 05:10

sethpollack