/structured-messaging

config-core extension providing integration with Winston.

Primary LanguageTypeScriptMIT LicenseMIT

structured-messaging

NOTE: In Beta.

GitHub license npm codecov

Fully configurable structured messaging and logging tool wrapping Winston. Recommended to be used in conjunction with config-core.

Motivation

Quickly get up and running with structured logging/messaging without being too opinionated.

We highly suggest using this library in conjunction with config-core.

Quick Start

Checkout the typescript examples.

Usage

import StructuredMessaging from 'structured-messaging';

let currentMessage = 0;

const logger = new StructuredMessaging(
  // use any winston parameters
  // see (https://github.com/winstonjs/winston#creating-your-own-logger)
  {
    level: 'info',
    // configure transports
    transport: [
      { type: 'console' },
      {
        type: 'file',
        // use any winston transport options for the given transport
        options: { filename: 'error_01.log', level: 'error' },
      },
    ],
    sharedData: {
      count: () => {
        currentMessage += 1;
        return currentMessage;
      },
    },
  },
).loggers();

logger.info('This is log message number %{count}.');
logger.info('This is log message number %{count}.');

// setup the logger