log4js-node

A port of log4js to node.js

View the Project on GitHub

No-Log Filter

The no log filter allows you to exclude the log events that an appender will record. The log events will be excluded depending on the regular expressions provided in the configuration. This can be useful when you debug your application and you want to exclude some noisily logs that are irrelevant to your investigation. You can stop to log them through a regular expression.

Configuration

Example

log4js.configure({
  appenders: {
    everything: { type: "file", filename: "all-the-logs.log" },
    filtered: {
      type: "noLogFilter",
      exclude: "not",
      appender: "everything",
    },
  },
  categories: {
    default: { appenders: ["filtered"], level: "debug" },
  },
});

const logger = log4js.getLogger();
logger.debug("I will be logged in all-the-logs.log");
logger.debug("I will be not logged in all-the-logs.log");

Note that:

log4js.configure({
  appenders: {
    everything: { type: "file", filename: "all-the-logs.log" },
    filtered: {
      type: "noLogFilter",
      exclude: ["NOT", "\\d", ""],
      appender: "everything",
    },
  },
  categories: {
    default: { appenders: ["filtered"], level: "debug" },
  },
});

const logger = log4js.getLogger();
logger.debug("I will be logged in all-the-logs.log");
logger.debug("I will be not logged in all-the-logs.log");
logger.debug("A 2nd message that will be excluded in all-the-logs.log");