1.0.1 • Published 6 months ago

@marianmeres/clog v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@marianmeres/clog

On top of console.log. Mostly.

Tiny namespaced console wrapper with configurable silence switches (global or local). And with custom writer support.

Installation

$ npm i @marianmeres/clog

Usage

// factory signature
const createClog = (ns, config: boolean | ConfigFlags = null, writer: Writer = null) => Writer

// create logger
const clog = createClog('foo');

// use any of the debug, info, log, warn, error (or none) methods
clog('bar', 'baz'); // same as clog.log
clog.debug('bar', 'baz');
clog.log('bar', 'baz');
clog.info('bar', 'baz');
clog.warn('bar', 'baz');
clog.error('bar', 'baz');
// 6 x output: [foo] bar baz

// example for errors only output (configured locally)
const clog = createClog('foo', { error: true });
clog('debug'); // ignored
clog.error('error');
// output: [foo] error

// example for global config silence
createClog.CONFIG.none();
clog('bar', 'baz');
// output none

// to use clog without namespace, use `false`
createClog(false)('foo', 'bar');
// output: foo bar

Custom writer setup example

This creates colored output based on log level

import { gray, green, red, yellow } from 'kleur/colors';

// somewhere in app bootstrap
const _setup = (k, c) => (...a) => console[k].apply(null, a.map((v) => c(v)));
createClog.CONFIG.WRITER = {
    debug: _setup('debug', gray),
    log: _setup('log', gray),
    info: _setup('info', green),
    warn: _setup('warn', yellow),
    error: _setup('error', red),
};

// somewhere later in app
const clog = createClog('my-module');
clog('foo') // output "[my-module] foo" in gray
clog.info('success'); // output "[my-module] success" in green
clog.error('alert!') // output "[my-module] alert!" in red
1.0.1

6 months ago

1.0.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago