1.0.2 • Published 7 years ago

universal-logger-browser v1.0.2

Weekly downloads
1,086
License
MIT
Repository
github
Last release
7 years ago

universal-logger-browser build status Coverage Status

NPM

Browser plugins for universal logger

Minimal

image

Styleable

image

Installation

npm install --save universal-logger universal-logger-browser

Usage

import emoji from 'node-emoji';
import logger, { TRACE, INFO } from 'universal-logger';
import { minimal, styleable } from 'universal-logger-browser';

const log = logger()
    .use(minimal({
        showSource: true,
        useNativeConsoleMethods: true
    }))
    .use(styleable({
        showSource: true,
        showTimestamp: true,
        style: {
            level: {
                silly: { // Custom log level
                    backgroundColor: '#FFF',
                    border: '1px solid #222',
                    color: '#222',
                    lineHeight: 2,
                    padding: '2px 5px'
                }
            }
        }
    }))
    .on('log', (context, messages) => {
        // Custom log processing
    });

log.enableStackTrace();
log.setLevel(TRACE);

log.log(INFO, 'The logger has initialized');
log.trace(emoji.get('mostly_sunny'));
log.debug(emoji.get('sun_small_cloud'));
log.info(emoji.get('barely_sunny'));
log.warn(emoji.get('rain_cloud'));
log.error(emoji.get('lightning_cloud'));

API

Minimal

NameTypeDefaultDescription
formatterfunction(context, messages)Custom log formatter.
showSourcebooleantrueShow the source line number of the caller.Note that you need to call log.enableStackTrace() to capture stack frames.
useNativeConsoleMethodsbooleantrueWhether to use native console methods for trace, debug, info, warn, and error.

Styleable

NameTypeDefaultDescription
colorizedbooleantrueShow colorized output.
showSourcebooleantrueShow the source line number of the caller.Note that you need to call log.enableStackTrace() to capture stack frames.
showTimestampbooleanfalseShow timestamp.
formatTimestampfunction(timestamp)Convert timestamp to string.
styleobjectSee styleable-style.jsCustom styles.

License

MIT