import SlackHook from 'winston-slack-webhook-transport'; import Transport from 'winston-transport'; import WinstonCloudwatch from 'winston-cloudwatch'; const crypto = require('crypto'); const { MESSAGE } = require('triple-beam'); export class LoggerTransportsFactory { static buildSlackTransport(webhookUrl: string, level?: string): Transport { return new SlackHook({ webhookUrl: webhookUrl, level }); } static buildCloudWatchTransport(logGroupName: string, level: string, awsRegion: string): Transport { const startTime = new Date().toISOString(); return new WinstonCloudwatch({ level, logGroupName: logGroupName, logStreamName: function() { // Spread log streams across dates as the server stays up const date = new Date().toISOString().split('T')[0]; return `${date}-` + crypto.createHash('md5').update(startTime).digest('hex'); }, awsRegion: awsRegion, messageFormatter(info) { return info[MESSAGE]; } }); } }