0.11.1 • Published 6 years ago

metallic-logger v0.11.1

Weekly downloads
2
License
BSD-3-Clause
Repository
github
Last release
6 years ago

metallic-logger

JSON logging library for CARTO's services, uses bunyan behind the scenes.

Quickstart

import Logger from 'metallic-logger'

const logger = Logger.create()

logger.info('Hi there!')
// -> {"name":"my-app","hostname":"localhost","pid":12018,"level":20,"msg":"Hi there!","time":"2017-02-13T13:47:32.521Z","v":0}

Features

  • Simple and fast JSON logging
  • Focus on CARTO's requirements
  • Log file rotation when process receives SIGHUP
  • Predefined outputs depending on the evironment

Installation

Use -S or --save to include it as dependency in package.json

$ npm install metallic-logger -S

Options

const options = {
  name: 'my-app',
  enabled: true,
  console: true,
  file: true,
  path: '/tmp/my-app.log'
  extra: {
    role: 'http-server'
  }
}
const logger = Logger.create({ options })

logger.info('Hi there!')
// -> {"name":"my-app","role":"http-server","hostname":"localhost","pid":12018,"level":20,"msg":"Hi there!","time":"2017-02-13T13:47:32.521Z","v":0}

See src/defaults.js to check structure and default values.

  • name: string, log identifier; default: name of dependent module
  • enabled: boolean, de/activate logging; default: true
  • console: boolean, de/activate console output; default: true
  • file: boolean, de/activate console output; default: true
  • path: string, path to place the log file; default: current working directory
  • extra: object, add more context for each log; default: undefined

Outputs

By default, there are two outputs available:

  • Console output is set to stdout at the debug level when NODE_ENV is development or undefined
  • File output is set to file at the info level when neither NODE_ENV is development nor undefined

Advanced

metallic-logger is meant to be used along metallic's modules. It exposes a common interface to encapsulate logging internals but it provides access to bunyan's object:

const logger = Logger.create({ options })

const bunyan = logger.provider

bunyan.info('Hi there!, I\'m bunyan')
// -> {"name":"my-app","hostname":"localhost","pid":12018,"level":20,"msg":"Hi there!, I'm bunyan","time":"2017-02-13T13:47:32.521Z","v":0}

For further configuration, please go to bunyan's repository

0.11.1

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago