In general, there are two reasons for logging from your app: For debugging and for logging app activity (essentially, everything else). Using
console.error()to print log messages to the terminal is common practice in development. But these functions are synchronous when the destination is a terminal or a file, so they are not suitable for production, unless you pipe the output to another program.
If you’re logging for purposes of debugging, then instead of using
console.log(), use a special debugging module like debug. This module enables you to use the
DEBUGenvironment variable to control what debug messages are sent to
console.err(), if any. To keep your app purely asynchronous, you’d still want to pipe
console.err()to another program. But then, you’re not really going to debug in production, are you?
For app activity
If you’re logging app activity (for example, tracking traffic or API calls), instead of using
console.log(), use a logging library like Winston or Bunyan. For a detailed comparison of these two libraries, see the StrongLoop blog post Comparing Winston and Bunyan Node.js Logging.
This document describes the syslog protocol, which is used to convey event notification messages. This protocol utilizes a layered architecture, which allows the use of any number of transport protocols for transmission of syslog messages. It also provides a message format that allows vendor-specific extensions to be provided in a structured way.
This cheat sheet is focused on providing developers with concentrated guidance on building application logging mechanisms, especially related to security logging. (...) Application logging should be consistent within the application, consistent across an organization's application portfolio and use industry standards where relevant, so the logged event data can be consumed, correlated, analyzed and managed by a wide variety of systems.
A logger for just about everything.
winstonis designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs.