Giter VIP home page Giter VIP logo

debug-logtron's Introduction

debug-logtron

A debug logger with a logtron interface.

Example

This logger is designed for tests; it prints info & above and prints debugs if you set NODE_DEBUG=mylibrary

var DebugLogtron = require("debug-logtron");

var logger = DebugLogtron('mylibrary');

logger.debug('some fixed string', { some: 'meta object' });
logger.info('some fixed string', { some: 'meta object' });
logger.warn('some fixed string', { some: 'meta object' });
logger.error('some fixed string', { some: 'meta object' });

It writes all logs to stderr. If you call logger.error() or logger.fatal() it will throw exceptions. any error callsites are bugs.

warns go to stderr by default.

Using in tests

You can use the .whitelist() and .items() method to make testing easier

var DebugLogtron = require('debug-logtron');
var test = require('tape');

test('some module', function t(assert) {
    var logger = NullLogtron('mything');
    var thing = new Thing({ logger: logger })

    logger.whitelist('error', 'some msg');

    thing.doStuff();

    var items = logger.items();
    assert.equal(items.filter(function (x) {
        return x.levelName === 'error'
    }).length, 1, 'thing writes to logger.error()');
    assert.end();
});

Whilst it is recommended that you minimize state between tests by creating a new instance of debug-logtron, it is possible to remove a whitelisted item by calling .unwhitelist with the same arguments.

Interface

This library will re throw any .error() or .fatal() callsites.

Any warns and infos got to stderr.

Any debugs / access can be made visible using NODE_DEBUG=mylibrary.

You can turn colors off with --color false

If you want to see trace() logs you must set NODE_DEBUG=mylibrary TRACE=1

Alternatives

Warning: This a logger for testing! Not a default logger.

If you want to add a default logger to your dependencies then I strongly recommend you use null-logtron

Motivation

You want to instrument your application and your libraries with a production application logger. A logger that writes somewhere in production.

However for your writing tests for both your libraries and your applications you probably do not want to see all of your logs spewing on STDOUT by default.

This is where debug-logtron comes in, You can start your app or libraries with the debug logger in your tests which allows the test runner to decide when to spew.

This works great together with itape --trace where you can use itape to turn on and off trace mode.

Docs

// TODO. State what the module does.

Installation

npm install debug-logtron

Tests

npm test

Contributors

  • Raynos

MIT Licensed

debug-logtron's People

Contributors

raynos avatar benfleis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.