se-teams-winston-transport
v1.1.1
Published
Custom [Winston transport](https://github.com/winstonjs/winston) for [sending alert message](https://learn.microsoft.com/en-us/outlook/actionable-messages/message-card-reference) cards to Teams.
Downloads
257
Readme
Solution Engineering Teams Winstons Transport
Custom Winston transport for sending alert message cards to Teams.
Usage
import TeamsWinstonTransport from 'se-teams-winston-transport';
import * as package from '../package.json';
const TEAMS_WEBHOOK_URL = process.env['TEAMS_WEBHOOK_URL'];
const teamsTransport = new TeamsWinstonTransport({
appName: package.name,
header: 'MyApp\'s Alerts',
webhookUrl: TEAMS_WEBHOOK_URL,
level: 'info',
});
logger.add(teamsTransport);
Custom formatter
Additionally you can format the log info
to a message card by providing a custom formatter. e.g. you can use the additional metadata of the log object to emit to your Teams channel.
const createTeamsReportingBlocks = (info: any) => {
if (!info.report) return [info];
const { approvalRate, approved, rejected, amended } = info.report;
return [
info,
`**Approved:** ${approved}<br>**Rejected:** ${rejected}<br>**Amended:** ${amended}`,
`**Approval Rate:** ${approvalRate.toFixed(2)}`,
];
};
const teamsTransport = new TeamsWinstonTransport({
...,
formatter: createTeamsReportingBlocks,
});
logger.add(teamsTransport);
logger.info('Finished transaction process!', {
report: {
approved: statefulTransactions.approved().length,
rejected: statefulTransactions.rejected().length,
amended: statefulTransactions.amended().length,
approvalRate: approvedRate,
},
});