1.1.1 • Published 2 years ago

winstonjs-fingers-crossed-transport v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Fingers Crossed Winston Transport

This library implements a transport for Winston loggers that works as a regular transport while the service is working normally but automatically switches to a verbose mode when an error occurs, in an attempt to provide more context to help diagnose the issue. In this verbose mode, the transport will print debugging messages that would normally be discarded.

Usage

import { FingersCrossedTransport } from '@kristijorgji/winstojns-transport-fingers-crossed'
import { createLogger, transports } from 'winston';

const transport = new FingersCrossedTransport(new transports.Console(), {
  // Prints all messages with level >= info and switches to verbose mode when a
  // message with level >= warn arrives
  standardLevel: 'info',
  activationLevel: 'warn',
});

const logger = createLogger({ transports: [transport] });

Configuration options

OptionDescription
standardLevelNormal logging threshold, i.e., messages with a lower level won't be printed and messages with level greater than or equal will be printed immediately. Typically info or warn.
activationLevelThreshold level at the transport will switch to verbose mode and print detailed logging messages that were not displayed before. Typically warn or error
maxItemsInBufferMaximum number of messages to keep in buffer in order to avoid memory leak if activation threshold is never reached. Defaults to undefined (no limit)
resetOnActivationIf set to true then when activationLevel is reached all logs are flushed(logged) then logger is reset. Will not print out anything until next activation level is reached Defaults to true

reset

When a message with logging level >= activationLevel arrives, the transport switches to verbose mode and starts logging all messages. To disable verbose mode call transport.reset(), as the following example shows:

import { FingersCrossedTransport } from '@kristijorgji/winstojns-transport-fingers-crossed'
import { createLogger, transports } from 'winston';

const transport = new FingersCrossedTransport(new transports.Console(), {
  standardLevel: 'info',
  activationLevel: 'warn',
});

const logger = createLogger({ transports: [transport] });

logger.debug('Debug message will not be printed immediately');

logger.warn('Warn message will be printed immediately, together with the debug message above');
logger.debug('This debug message will be printed immediately as well');

transport.reset();

logger.debug('This debug message will not be printed');