File: noLogFilter.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 (61 lines) | stat: -rw-r--r-- 2,030 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

- `type` - `"noLogFilter"`
- `exclude` - `string | Array<string>` - the regular expression (or the regular expressions if you provide an array of values) will be used for evaluating the events to pass to the appender. The events, which will match the regular expression, will be excluded and so not logged.
- `appender` - `string` - the name of an appender, defined in the same configuration, that you want to filter.

## Example

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

- an array of strings can be specified in the configuration
- a case insensitive match will be done
- empty strings will be not considered and so removed from the array of values

```javascript
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");
```