1.1.6 • Published 5 years ago

abstract-winston-json v1.1.6

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
5 years ago

Abstract Winston JSON Logging Tool

A Simple JSON Logging Tool that is built on top of Winston

Installation

Yarn:

yarn add abstract-winston-json

NPM:

npm install abstract-winston-json

Output

{
  "type": "log.type",
  "message": {
    "data": {
      "more": "data",
    },  
  },
  "metadata": {
    "userId": "123ABC",
  },
}

API

Logger

Parameters

ParamTypeDescriptionDefault Value
metadataObjectMetadata Object{}
debugModeBooleanDebug Modefalse

Example

const Logger = require('abstract-winston-json');

// Metadata to include in every log.
const metadata = {
  userId: 'ABC123',
};

// Debug Mode Off
const logger = new Logger({ metadata });

// Debug Mode On
const logger = new Logger({
  metadata,
  debugMode: true,
});

addMetadata(key, value)

Add Metadata to include in every log.

Parameters

ParamTypeDescriptionDefault Value
keyStringMetadata Key
valueAnyMetadata Value

Example

logger.addMetadata('key', 'value');

removeMetadata(key)

Remove specific Metadata from logs from now on.

Parameters

ParamTypeDescriptionDefault Value
keyStringMetadata Key{}

Example

logger.removeMetadata('key');

log(type, message)

Log via the info level.

Parameters

ParamTypeDescriptionDefault Value
typeStringLog Type Key
messageAnyLog Message

Example

logger.log('log.type', {
  requestInfo: 'example',
  data: {},
});

warn(type, message)

Log via the warn level.

Parameters

ParamTypeDescriptionDefault Value
typeStringLog Type Key
messageAnyLog Message

Example

logger.warn('warn.type', {
  requestInfo: 'example',
  data: {},
});

error(type, message) || err(type, message)

Log via the error level.

Parameters

ParamTypeDescriptionDefault Value
typeStringLog Type Key
messageAnyLog Message

Example

logger.error('error.type', {
  requestInfo: 'example',
  data: {},
});
logger.err('error.type', {
  requestInfo: 'example',
  data: {},
});

debug(type, message)

Will only log when debug mode is set to true. Logs via the info level.

Parameters

ParamTypeDescriptionDefault Value
typeStringLog Type Key
messageAnyLog Message

Example

logger.debug('error.type', {
  requestInfo: 'example',
  data: {},
});

getLogger()

Gets the underlying Winston Logging Instance

Example

const winston = logger.getLogger();
1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago