0

I'm trying to have the winston logging output logger.debug for a node.js/socket.io project I'm working on but I can't get the debug to show up in the console.

I create logger with:

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)()
        ]
    });

On connection I'm trying to get the the debug to say it has connected

io.on('connection', function (socket) {

    socket.emit('init','init-yes');

    logger.debug("Socket.on has connected");
    logger.log('debug', 'This is the debug');

    ...

but nothing appears in the console. I checked out the git page but still seem to be not understanding something.

EDIT As was suggested I updated the logger creation to:

var logger = new winston.Logger({
  transports: [
    new winston.transports.Console({ level : 'debug' })
  ]
});

but I'm still not getting the logger.debug("Message here") to work.

Any help would be greatly appreciated. Thank you for your time!

mario
  • 1,503
  • 4
  • 22
  • 42

1 Answers1

2

The fine manual states: "note that the default level of a transport is info".

Since you don't set the log level for your transport, any messages with a level below info (like debug) won't get shown.

To fix this:

var logger = new winston.Logger({
  transports: [
    new winston.transports.Console({ level : 'debug' })
  ]
});
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Would that be new (winston.transports.Console)({ level: 'debug' }) ? – mario Jun 04 '15 at 18:35
  • 1
    @mario that would also work, but I find that notation pretty horrible so I left out the parentheses. – robertklep Jun 04 '15 at 18:36
  • I tried it and got a net::ERR_CONNECTION_REFUSED error. Any clue why? – mario Jun 04 '15 at 18:38
  • 1
    @mario that doesn't sound like it's caused by Winston. – robertklep Jun 04 '15 at 18:39
  • Okay awesome. Thanks for the help! – mario Jun 04 '15 at 18:41
  • I got the error to go away but nothing is being outputted still. – mario Jun 08 '15 at 20:31
  • 1
    And you're not redirecting/piping the output of your app? Or, to rephrase: how are you running your app? Do you see anything when you replace the calls to `logger.*()` with `console.log(...)`? Are you sure your logging statements are actually being reached? – robertklep Jun 08 '15 at 20:33
  • No, at least I don't believe I am. And console.log() did not output anything either. – mario Jun 08 '15 at 20:35
  • 1
    If `console.log()` isn't showing either, then either that code path isn't getting reached or you start your app in such a way that console output is just not being shown. – robertklep Jun 08 '15 at 20:40
  • The weird thing is that some of the code works. But when I get to certain parts it dies on me as I described here: http://stackoverflow.com/questions/30648727/node-js-with-socket-io-winston-logger-not-outputting-debug/30651473?noredirect=1#comment49494647_30651473 – mario Jun 08 '15 at 20:41
  • I was hoping to use the debugging to get some better answers but no luck so far. – mario Jun 08 '15 at 20:42
  • 1
    You don't happen to have `process.on('uncaughtException', ...)` somewhere in your code so any errors that are occurring are being ignored? – robertklep Jun 08 '15 at 20:44
  • No sir, just checked. – mario Jun 08 '15 at 20:45
  • Opps, I meant I had described it here - http://stackoverflow.com/questions/30713635/node-js-with-socket-io-long-polling-fails-and-throws-code1-messagesessi – mario Jun 09 '15 at 12:54
  • 1
    @mario I have zero knowledge about IIS so can't help you there I'm afraid. – robertklep Jun 09 '15 at 12:57