Neanderthal Painting Monet

    namespaced-console-logger

    1.1.0 • Public • Published

    Namespaced Console Logger

    Build Status NPM version

    Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.

    The logger satisfies three requirements below and attempts to do nothing else:

    1. Is small: has no dependencies & <50 loc (for the browser)
    2. Has a timestamp
    3. Has a namespace

    Example output:

    2015-08-10T20:09:20.526Z (namespace) INFO: Hello world!
    

    Usage

    import createLoggers from 'namespaced-console-logger';
     
    const loggers = createLoggers();
    const logger = loggers.get('namespace');
     
    logger.info('Hello %s!', 'world');
    • createLoggers() takes a minimum logging level, which is one of: ['info', 'warn', 'error'] and defaults to info. For example if you select warn, all info logs will be ignored. warn and error logs will be displayed.

    Support for formatting and arbitrary metadata

    import createLoggers from 'namespaced-console-logger';
     
    const loggers = createLoggers('info', '{{timestamp}} {{hostname}} {{calculatedValue}} ({{namespace}}) {{level}}:', { hostname: 'machinename', calculatedValue: () =>  { return 1 + 2; } });
    const logger = loggers.get('namespace');
     
    //2015-08-10T20:09:20.526Z machinename 3 (namespace) INFO: Hello world!
    logger.info('Hello %s!', 'world');

    License

    MIT

    Install

    npm i namespaced-console-logger

    DownloadsWeekly Downloads

    80

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • ddrinf
    • nemtsov