@kevit/log4js-teams
v1.0.5
Published
Log4js teams appender
Downloads
12
Readme
Log4js Node Teams Appender
Sends log events to a MS Teams channel. This is an appender for use with log4js.
Instructions:
Install the package:
npm i @kevit/log4js-teams
Configuration
type
-@kevit/log4js-teams
webhookURL
- Your channel's incoming webhhok URLlayout
-object
(optional, defaults topatternLayout
with pattern`%p` %c%n%m
) - the layout to use for the message (see layouts).
Example
With webhook url
log4js.configure({
appenders: {
teamsAlert: {
type: '@kevit/log4js-teams',
webhookUrl: 'https://outlook.office.com/webhook/***/IncomingWebhook/***/***'
}
},
categories: {default: {appenders: ['teamsAlert'], level: 'warn'}}
});
This configuration will send all warn (and above) messages to the respective teams channel.
With multiple appenders
log4js.configure({
appenders: {
out: {type: 'stdout'},
allLogs: {type: 'file', filename: 'all.log', maxLogSize: 10485760, backups: 10, compress: true},
outFilter: {
type: 'logLevelFilter', appender: 'out', level: process.env.LOG_LEVEL || 'all'
},
teamsAlert: {
type: '@kevit/log4js-teams',
webhookUrl: 'https://outlook.office.com/webhook/***/IncomingWebhook/***/***'
},
teamsFilter: {
type: 'logLevelFilter', appender: 'teamsAlert', level: process.env.ALERT_LOG_LEVEL || 'warn'
}
},
categories: {
default: {appenders: ['allLogs','outFilter', 'teamsFilter'], level: process.env.LOG_LEVEL || 'all'}
}
});
This configuration displays use of multiple appenders.
outFilter
: Push log in stdout with filterLOG_LEVEL
set in environment, if not set thenall
levelsteamsFilter
: Push log in teams channel with filterALERT_LOG_LEVEL
set in environment, if not set thenwarn
levels
For more configuration, see log4js