0.0.0-dev.2 • Published 1 year ago

@yaupon/logger v0.0.0-dev.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

🪵 Logger

Well-designed abstraction for logging compatible with major HTTP frameworks and logging libraries, including: winston, pino, bunyan and log4js. It provides a simple and consistent API for logging in yaupon ecosystem.

Features

  • Various formats of logs including: pretty, ndjson, syslog
  • Easy integration into existing apps with OOB support for log metadata such as User's ID, Request ID, etc.

API

  • Logger(options?: LoggerOptions): Logger - creates a new logger instance.
  • createLogger(options?: LoggerOptions): Logger - creates a new logger instance.
  • each logger instance has the following methods:
    • trace(message: string, meta?: Record<string, any>): void
    • debug(message: string, meta?: Record<string, any>): void
    • info(message: string, meta?: Record<string, any>): void
    • warn(message: string, meta?: Record<string, any>): void
    • error(message: string, meta?: Record<string, any>): void
    • fatal(message: string, meta?: Record<string, any>): void
    • child(meta: Record<string, any>): Logger - creates a child logger with the provided metadata.
  • setContext(meta: Record<string, any>): void - sets the global context for the logger.
  • setGlobalLogger(logger: Logger): void - sets the global logger for the application. (Overrides console.log and console.error)
  • @logthis - decorator for logging class methods and fuctions for debugging purposes, in future this will be replaced with @yaupon/debug package with @debug decorator.
  • log.<level>('message') - logs a message with the global logger.

Tasklist

  • Replaceable structure of logs metadata which would provide type-safety and consistency for produced logs.
  • Add easy interface to integrate popular tools such as NewRelic, OpenTelemetry and so on, all this should be provided as separate package which will be imported into LoggerOptions.integrations field by using default export from integration package ex. import newrelic from '@yaupon/logger-provider-newrelic'.
  • Self-linting which will include warnings for every log message that was malformed or have insufficient information (and such linting shouldn't apply to logs from global logger which replaced console.log and console.error).
  • @yaupon/logger-provider-native-yaupon library which will provide native integration with yaupon ecosystem, this will apply additional overrides which will allow parsing information from structures in application like Request, Response, Context and so on, leading to more simplified and consistent logging. Eventually usage would look like logger.info(event) and the detailed logs will be automatically mapped and structured.

  • Add support for @yaupon/debug package.

  • Add support for @yaupon/audit package.
  • Add support for @yaupon/monitoring package.
  • Add support for @yaupon/telemetry package.
  • Add support for @yaupon/tracing package.

Usage

import { Logger, createLogger, log } from '@yaupon/logger';

const logger: Logger = createLogger();

logger.info('Hello, world!');
logger.child({requestId: '123' }).info('Hello, world!');

log("Smth, happended")
log("Look this is a function", createLogger)

@logthis
class MyClass {
  @logthis
  public myMethod() {
    return 'Hello, world!';
  }
}
0.0.0-dev.2

1 year ago

0.0.0-dev.1

1 year ago

0.0.0-dev.0

1 year ago