3.1.1 • Published 2 years ago

drm-logger v3.1.1

Weekly downloads
33
License
ISC
Repository
-
Last release
2 years ago

DRM Logger

Logger module, based on Winston.

Usage

The module exports a winston object called log. To import the logger module in a new project, just import log from this package.

import { log } from 'drm-logger';

log.info('hello', 'world!');

// output: info: [YYYY-MM-DD hh:mm:ss:SSS] hello world!

Configuration

This logger works via a configuration file. The file should be named default.yml and should contain configuration in this format:

winston:
  level: debug
  transports:
  - type: Console
  - type: File
    filename: "./winston.log"
  - type: Sentry
    level: debug
    dsn: https://abcdef0123456789@sentry.io/123456

Each of the transports is optional. The Sentry one requires the redundant level property.

Sentry DSN should be in the new format instead of the deprecated one. If you read this and you don't see a deprecation warning in your settings->client keys->dsn page it means that the new format has become the standard one and the deprecated format has been completely removed, so you can ignore this message.

If no configuration file is found, a console appender will be created by default, and a message will be printed in console:

WARNING: No configurations found in configuration directory:[your project's root dir]/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.

As the message says, this warning can be ignored or suppressed by setting the proper environment variable.

Adding custom logging transports

To add custom logging transports, go to index.ts and import your transport, then add it to the transportMap:

import { MyNewTransport } from 'my-new-transport';
const transportMap = {
  'MyNewTransport': MyNewTransport,
};

Note: MyNewTransport must have a constructor with an options object as argument.

In the yaml configuration file, add a transport that way:

winston:
  level: debug
  transports:
  - type: Console
  - type: File
    filename: "./winston.log"
  - type: Sentry
    level: debug
    dsn: https://abcdef0123456789@sentry.io/123456
  - type: MyNewTransport # must match the key inside transportMap!
    myOption1: OPTION 1
    myOption2: OPTION 1
    # etc.

Options will be passed as json object to the defined transport, so this configuration file will generate this call:

MyNewTransport(
  {
    myOption1: 'OPTION 1',
    myOption2: 'OPTION 2',
  }
);

This means that yaml configuration should have the exact same structure as the configuration object expected by the new transport.

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.4.0

3 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.3

4 years ago

2.3.0

4 years ago

2.2.3

4 years ago