where is winston log file? #335

Closed
thanhthang20 opened this Issue Dec 13, 2013 · 4 comments

3 participants

@thanhthang20

I add this 4 lines in my server.js

var winston = require('winston');
winston.log('info', 'Hello distributed log files!');
winston.info('Hello again distributed logs');
winston.add(winston.transports.File, { filename: __dirname + '/debug.log' });

But I do not see debug.log in the directory with server.js?. Where is it stored?

Thanks!

@jcrugzz

@thanhthang20 you need to add the transport before you log anything. That should solve your problem!

@jcrugzz jcrugzz closed this Dec 13, 2013
@thanhthang20

"add the transport", this is what you mean:

var winston = require('winston'), logger = new (winston.Logger)({
transports: [
new (winston.transports.Console) (),
new (winston.transports.File) ({filename: 'test.log'})
]
});

logger.log('Hello world');

I have tried, but it is still not work

@jcrugzz

@thanhthang20 Does the code exit immediately after this log statement? Ensure the program stays running because it might not have enough time to flush the log to disk. Its essentially a race condition of writing to the filesystem and when your program exits if my assumption is correct.

@jcrugzz jcrugzz reopened this Dec 13, 2013
@thanhthang20

Yes,

I have found this http://stackoverflow.com/questions/18918896/in-winston-for-node-js-is-there-a-way-to-suppress-log-level-from-message?rq=1

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: __dirname + '/debug.log',
json: false,
timestamp: false
}
)
]
}
),
winstonStream = {
write: function(message, encoding) {
requestLogger.info(message.replace(/(\r?\n)$/, ''));
}
};
var app = express();
app.use(express.logger({stream: winstonStream}));

It is work, but the debug.log file just contain:

info: 127.0.0.1 - - [Fri, 13 Dec 2013 03:28:22 GMT] "GET /articles HTTP/1.1" 200 - "http://localhost/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"

I want to log everything (include socketIO receiving and writing) likely STDIN and STDOUT, what should I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment