lazywithclass/winston-cloudwatch

The `logging` event never fires

Opened this issue · 3 comments

According to documentation of winston logger emits logging events

https://www.npmjs.com/package/winston#events-and-callbacks-in-winston

Is this functionality missing?

log.ts

import * as winston from 'winston';
import * as WinstonCloudWatch from 'winston-cloudwatch';

winston.add(WinstonCloudWatch, {
	name: 'someLogger',
	logGroupName:  'someGroup',
	logStreamName: 'someStream',
	errorHandler: function(err) {
		console.log('err', err);
	}
});

winston.loggers.get('someLogger').on('logging', function() {
	// This one never fires
});

export default winston;

Logging itself works fine, entries appear in the CloudWatch UI.

This library doesn't have that feature, honestly I didn't know it existed in Winston :)

Is this important for you? I could have a look how difficult it would be to add it.

I wanted to use this event to expose information if logging works

log.ts

import * as winston from 'winston';
import {TransportInstance} from 'winston';
import * as WinstonCloudWatch from 'winston-cloudwatch';

let isHealthy = true;

try {
	winston.add(WinstonCloudWatch as TransportInstance, {
		name: 'someLogger',
		errorHandler: function(err) {
			console.log('err', err);
			isHealthy = false;
		}
	});
} catch (error) {
	isHealthy = false;
}

winston.loggers.get('someLogger').on('logging', function() {
	isHealthy = true;
});

winston.loggers.get('someLogger').on('error', function() {
	isHealthy = false;
});

export function isItHealthy() {
	return isHealthy;
}

export default winston;

Maybe there is a simpler way to do this.

Ok I understand your use case, let me think about it.