Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
/ simply-logs Public archive

Dead simple cross platform logger with the ability to set the log level

Notifications You must be signed in to change notification settings

cedvdb/simply-logs

Repository files navigation

Simple Log

A dead simple cross platform logger. It just does one thing: lets you set a log level and then log if it's appropriate

Features

  • Simple
  • Can set log level to disable some outputs
  • You can transform output to suit your needs
  • Typed

Usage

  import { log, LogLevel } from 'simply-logs';

  // same methods as on the console:
  log.setLogLevel(LogLevel.ALL);
  log.error('hey');
  log.warn('hey');
  log.info('hey');
  log.debug('hey');
  log.trace('hey');

  // others
  log.group(LogLevel.DEBUG, 'hey');
  log.groupEnd(LogLevel.INFO);
  log.time(LogLevel.WARN, 'hey');
  log.timeEnd(LogLevel.ERROR, 'hey');
  log.table(LogLevel.TRACE, obj);

  // turn off
  log.setLogLevel(LogLevel.OFF);

Transform

The log class exposes transformFn that you can override to transform how the output is displayed.

example:

import { TransformFn } from 'simply-logs';

const pretty = 
  (level, ...args) => [
    `[${level}] ${args.join(' ')} [${(new Date()).toLocaleTimeString()}]`, 
  ];

log.transformFn = pretty;

log.warn('hey'); // [WARN] hey [now]

Prebuilt transform

there is two prebuilt transform which have coloring (no dependencies).

import { log, prettyNode, prettyBrowser } from 'simply-logs';

log.transformFn = prettyBrowser;
// or log.transformFn = prettyNode;

Voila simple as that.

About

Dead simple cross platform logger with the ability to set the log level

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published