1.0.8 • Published 4 years ago

@mirekpluta/jg-logger v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

jg-logger

Small utility providing logger that configures winston logger for usage on local (dev) environment where readability of logs is critical as well as production, dockerized environments where logs are being processed by tools.

Installation

Simply execute

npm install @mirekpluta/jg-logger

Configuration

Logger is being configured with config npm package, therefore it requires json config files to be present in config directory.

Example config file:

{
  "logger": {
    "logLevel": "debug",
    "format": "pretty",
    "defaultMeta": {
        "serviceName": "test"
    }
  }
}

Explanation

  • logLevel - log level as specified in winston library (error, warn, info, verbose, debug, silly)
  • format
    • pretty - to be used when running locally, it displays colorized log with timestamps, padded levels and json stringified metadata + potential stacktrace in case of logged exception
    • json - it'll display each log entry as json object including timestamp and stacktrace in case of errors
  • defaultMeta - default metadata that will be included to all logs from the project

Functionality

  • both human friendly (pretty) and tools friendly (json) logs format (see Configuration above).
  • catches and logs all uncought errors (it will prevent application from exiting)
  • provides errorLoggingMiddleware express middleware to be registered at the very end with express app, that logs all rejected promises
  • uses express-async-errors package that will handle all rejected promises from middleware async functions
  • adds logger property to global object for easy access throughout entire application

Usage

Import early: - logger should be imported as early in the project as possible, so that it can be initialized

logger.errorLoggingMiddleware - express middleware that should be registered to express app as the last one

use like you would use winston logger - configured logger is just winston logger, so entire functionality of it is available.

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 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