File: logLevelFilter.md

package info (click to toggle)
node-log4js 6.9.1%2B~cs8.4.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,468 kB
  • sloc: javascript: 12,965; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

- `type` - `logLevelFilter`
- `appender` - `string` - the name of an appender, defined in the same configuration, that you want to filter
- `level` - `string` - the minimum level of event to allow through the filter
- `maxLevel` - `string` (optional, defaults to `FATAL`) - the maximum level of event to allow through the filter

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

```javascript
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`.