I\'m working on an node.js application with several dozen modules and using bunyan for logging (JSON output, multiple configurable streams). I\'ve been looking for good e
Singleton pattern in nodejs - is it needed? Actually, singleton is perhaps not needed in Node's environment. All you need to do is to create a logger in a separate file say, logger.js:
var bunyan = require("bunyan"); // Bunyan dependency var logger = bunyan.createLogger({name: "myLogger"}); module.exports = logger;
Then, retrieve this logger from another module:
var logger = require("./logger"); logger.info("Anything you like");
if you are using express with node.js then you can try this. By default, logging is disabled in Express. You have to do certain stuff to get logs working for your app. For access logs, we need to use the Logger middleware; for error logs we will use Forever.Hope it will help you.. Here is a good example How to Logging Access and Errors in node.js