Skip to content

altipla-consulting/logging

Repository files navigation

logging

JSON logger with an opinionated default configuration.

Install

npm install @altipla/logging

Usage

import { logger } from '@altipla/logging'

logger.info('Log this')
logger.error('Log an error')
logger.info({
  msg: 'foo',
  field1: 'bar',
  field2: 3,
})

Log common fields

Create a custom logger to group fields common to all log messages. It can be useful for example to add the current user inside all messages.

import { logger } from '@altipla/logging'

let userLogger = logger.child({ user: 'user' })

userLogger.info('my message')
userLogger.error('other message')

Change log level

By default log level is set to debug. It can be changed creating a new child logger with a level field configured:

import { logger } from '@altipla/logging'

let traceLogger = logger.child({ level: 'trace' })
traceLogger.trace('trace message')

About

JSON logger with an opinionated default configuration.

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •