Skip to content

3axap4eHko/loggry

Repository files navigation

LOGGRY

Lightweight 0-dependency, transport agnostic, ESM and CommonJS logger bus for Node.js applications, enabling structured logging and event handling with customizable listeners and various log levels.

Build Status NPM version Downloads Coverage Status Maintainability Snyk

Instalation

PNPM

pnpm add loggry

YARN

yarn add loggry

NPM

npm install --save loggry

Usage

In the main script

import { addListener, LogEvent } from 'loggry';

addListener((log: LogEvent) => console.log(log.level, log.message, 'at', log.timestamp));

In some other place

import { debug } from 'loggry';

function myFunction() {
  debug('myFunction', 'executed!');
}

Built-in log levels

enum LogLevel {
  silent,
  fatal,
  error,
  warn,
  info,
  debug,
  trace,
}

Pino integration

import createPino from 'pino';
import { addListener, LogEvent } from 'loggry';

const pinoLogger = createPino();

addListener(({ level, message, details }: LogEvent) => pinoLogger[level]({ details }, message));

License

License Apache-2.0 Copyright (c) 2023 Ivan Zakharchanka