log4js-node

A port of log4js to node.js

View the Project on GitHub

Log Level Filter

The log level filter allows you to restrict the log events that an appender will record based on the level of those events. This is useful when you want most logs to go to a file, but errors to be sent as emails, for example. The filter works by wrapping around another appender and controlling which events get sent to it.

Configuration

If an event’s level is greater than or equal to level and less than or equal to maxLevel then it will be sent to the appender.

Example

log4js.configure({
  appenders: {
    everything: { type: "file", filename: "all-the-logs.log" },
    emergencies: { type: "file", filename: "panic-now.log" },
    "just-errors": {
      type: "logLevelFilter",
      appender: "emergencies",
      level: "error",
    },
  },
  categories: {
    default: { appenders: ["just-errors", "everything"], level: "debug" },
  },
});

Log events of debug, info, error, and fatal will go to all-the-logs.log. Events of error and fatal will also go to panic-now.log.