qcza-log
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

qcza-log

Simple logger with custom transports.

use

import { Logger, Levels } from 'qcza-log';

const qlog = new Logger();

if (process.env.NODE_ENV !== 'production') {
  qlog.level = Levels.ERROR;
} else {
  qlog.level = Levels.DEBUG;
}

export {qlog};
import {qlog} from './config';

qlog.debug('message');

// You can pass additional title in the second argument
qlog.debug('message', 'title')

levels

export enum Levels {
  DEBUG = 'debug',
  INFO = 'info',
  HTTP = 'http',
  WARN = 'warn',
  ERROR = 'error',
  PANIC = 'panic',
}

qlog.debug('message');
qlog.info('message');
qlog.http('message');
qlog.warn('message');
qlog.error('message');
qlog.panic('message');

config

You may pass config to the constructor, or set log level with setter.

const config: LoggerConfig = {
  level: Levels.DEBUG, // minimum shown log level 
  transport: ({message}: TransportData) => console.log(message), // transport function or array of functions
  ignore: [Levels.HTTP], // ignored log levels array
  settings: {
    showDateTime: false // show dateTime string
  }
}

You may also set the minimum log level and ignored log levels with setters.

qlog.level = Levels.DEBUG;

qlog.ignore = [Levels.HTTP];

Package Sidebar

Install

npm i qcza-log

Weekly Downloads

2

Version

1.0.3

License

ISC

Unpacked Size

18 kB

Total Files

21

Last publish

Collaborators

  • qcza