@kevit/log4js-teams

1.0.5 • Public • Published

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 URL
  • layout - object (optional, defaults to patternLayout 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 filter LOG_LEVEL set in environment, if not set then all levels
  • teamsFilter: Push log in teams channel with filter ALERT_LOG_LEVEL set in environment, if not set then warn levels

For more configuration, see log4js

Package Sidebar

Install

npm i @kevit/log4js-teams

Weekly Downloads

3

Version

1.0.5

License

GPL-3.0

Unpacked Size

5.02 kB

Total Files

3

Last publish

Collaborators

  • parth.kevit
  • darshit.mehta
  • dkbhadeshiya
  • harpalsinh.gohil