@apoyo/logger
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Apoyo - Logger

npm version

Warning: This package is still in development and is not recommended to use in production yet.

Installation

Install peer dependencies: npm install @apoyo/std

Install package: npm install @apoyo/logger

Documentation

This package contains utils around Pino loggers.

It adds once again the prettyPrint option to more easily enable pretty printing in development, with sensible defaults.

It also contains a LoggerContext that, using AsyncLocalStorage, allows us to add additional bindings to each logger in a same asynchronous scope easily.

import { createLogger, LogLevel, LoggerContext } from '@apoyo/logger'

const loggerContext = new LoggerContext()
const logger = createLogger(
  {
    level: LogLevel.INFO,
    prettyPrint: true
  }, 
  loggerContext // This parameter is optional
)

const featureLogger = logger.child({
  name: 'MyFeature',
  foo: 'bar' 
})

const reqLogger = logger.child({
  name: 'Http',
  foo: 'foo',
  req: {
    id: 'xxx-xxx-xxx'
  }
})

loggerContext.attachBindings(reqLogger.bindings(), async () => {
  /*
   * Logs the following custom properties (not including the message, level and other default pino properties):
   * ```
   * {
   *   name: 'MyFeature', 
   *   foo: 'bar', 
   *   req: { 
   *     id: 'xxx-xxx-xxx' 
   *   }
   * }
   * ```
   */
  featureLogger.info('hello world')
})

A more complete documentation will be written when the package becomes stable.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @apoyo/logger

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

11.8 kB

Total Files

7

Last publish

Collaborators

  • sascha245