0.11.1 • Published 6 years ago
metallic-logger v0.11.1
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 thedebug
level whenNODE_ENV
isdevelopment
orundefined
- File output is set to
file
at theinfo
level when neitherNODE_ENV
isdevelopment
norundefined
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