Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 |
|
---|
2 |
|
---|
3 | const debug = require('debug')('log4js:noLogFilter');
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * The function removes empty or null regexp from the array
|
---|
7 | * @param {string[]} regexp
|
---|
8 | * @returns {string[]} a filtered string array with not empty or null regexp
|
---|
9 | */
|
---|
10 | function removeNullOrEmptyRegexp(regexp) {
|
---|
11 | const filtered = regexp.filter(el => ((el != null) && (el !== '')));
|
---|
12 | return filtered;
|
---|
13 | }
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Returns a function that will exclude the events in case they match
|
---|
17 | * with the regular expressions provided
|
---|
18 | * @param {(string|string[])} filters contains the regexp that will be used for the evaluation
|
---|
19 | * @param {*} appender
|
---|
20 | * @returns {function}
|
---|
21 | */
|
---|
22 | function noLogFilter(filters, appender) {
|
---|
23 | return (logEvent) => {
|
---|
24 | debug(`Checking data: ${logEvent.data} against filters: ${filters}`);
|
---|
25 | if (typeof filters === 'string') {
|
---|
26 | filters = [filters];
|
---|
27 | }
|
---|
28 | filters = removeNullOrEmptyRegexp(filters);
|
---|
29 | const regex = new RegExp(filters.join('|'), 'i');
|
---|
30 | if (filters.length === 0
|
---|
31 | || logEvent.data.findIndex(value => regex.test(value)) < 0) {
|
---|
32 | debug('Not excluded, sending to appender');
|
---|
33 | appender(logEvent);
|
---|
34 | }
|
---|
35 | };
|
---|
36 | }
|
---|
37 |
|
---|
38 | function configure(config, layouts, findAppender) {
|
---|
39 | const appender = findAppender(config.appender);
|
---|
40 | return noLogFilter(config.exclude, appender);
|
---|
41 | }
|
---|
42 |
|
---|
43 | module.exports.configure = configure;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.