metallic-logger
JSON logging library for CARTO services
Last updated a year ago by dgaubert .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metallic-logger 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.11.1                                ...           latest (a year ago)

17 Versions

  • 0.11.1                                ...           a year ago
  • 0.11.0                                ...           a year ago
  • 0.10.0                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.3                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 18
Dependencies (5)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |