mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
1.3 KiB
1.3 KiB
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-logLevelFilterappender-string- the name of an appender, defined in the same configuration, that you want to filterlevel-string- the minimum level of event to allow through the filtermaxLevel-string(optional, defaults toFATAL) - 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
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.