1.0.0 • Published 8 years ago

finciero-logger v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

Structured Logging

Winston wrapper that speaks GCE.

Usage

Constructor first argument is a persisted default metadata object that gets added to each logging message, and second arguments specifies the logger level (debug level as default).

The Logger instance has the following methods:

  • debug
  • info
  • warning
  • error
  • critical

Each method receives a message (string) as first argument, and the second argument is an optional object that gets merge to the default metadata (specified when instantiating the logger).

Examples

const { Logger } = require('finciero-logger')

const logger = new Logger({
  svc_tag: 'foo:1.0.0',
  grpc_address: ':13000',
  http_address: ':8080',
})

logger.info('foo', { custom: 'extra', data: { important: 'value' } })
// output: {"severity":"INFO","message":"foo","meta":{"custom":"extra","data":{"important":"value"},"svc_tag":"foo:1.0.0","grpc_address":":13000","http_address":":8080"}}
const { Logger } = require('finciero-logger')

const level = 'info' // 'debug', 'info', 'warning', 'error' and 'critical' are valid level values
const logger = new Logger({
  svc_tag: 'foo:1.0.0',
  grpc_address: ':13000',
  http_address: ':8080',
}, level) 
logger.info('foo', { custom: 'extra', data: { important: 'value' } })
// output: {"severity":"INFO","message":"foo","meta":{"custom":"extra","data":{"important":"value"},"svc_tag":"foo:1.0.0","grpc_address":":13000","http_address":":8080"}}

Most of the code was borrowed from https://github.com/dannydavidson/winston-gke