A micro logging wrapper for shims, logging frameworks, console logs, etc.
JavaScript HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demo
lib
test/client
.editorconfig
.eslintignore
.eslintrc-base
.eslintrc-browser
.eslintrc-browser-test
.eslintrc-node
.gitignore
.npmignore
.travis.yml
CONTRIBUTING.md
DEVELOPMENT.md
LICENSE.txt
README.md
karma.conf.coverage.js
karma.conf.dev.js
karma.conf.js
package.json
webpack.config.coverage.js
webpack.config.dev.js
webpack.config.js
webpack.config.test.js

README.md

Travis Status

Abstract Log

An micro log wrapper to implement production shims, loggers, etc.

The primary use case for this wrapper is for a project that needs to do some logging but doesn't want to take dependencies on a specific logger (like Bunyan, Winston, Good, etc.) or assume use in a specific environment (browser, Node.js, both etc.). And it is easily configured as a straight shim to do nothing in the most lightweight manner possible.

As an example, the main impetus for the creation of AbstractLog is for small React components that have no other dependencies, want to log specific information in the browser and in Node.js on the server, and leave the actual implementation of the logger up the consumer of the library code.

Installation

Install via npm:

$ npm install abstract-log

or bower:

$ bower install abstract-log

Usage

Import the AbstractLog class into your code (via AMD, CommonJS, etc) and use as a configurable logger. The basic abstraction is:

var log = new AbstractLog(OPTIONS);

log.METHOD(MESSAGE_STRING, METADATA_OBJECT);  // Abstraction
log.warn("My message", { an: "object" });     // Example

The instance of an AbstractLog requires an OPTIONS object that defines the actual methods available for the logger.

The underlying logger used by the abstraction ideally has:

  • METHOD: A method like warn, info, error that takes typically two arguments.
  • MESSAGE: A human-readable string, typically the first argument.
  • METADATA: An structured JS object of metadata that is meant to be outputted as a JSON line and hopefully programmatically ingested and used later. The ideal use is any aspect of a log message that is a metric like: database response time, number of database connections, timestamp, user id, etc.

AMD

define(["abstract-log"], function (AbstractLog) {
  var log = new AbstractLog();
  log.info("Hello world!");
});

CommonJS

var AbstractLog = require("abstract-log");
var log = new AbstractLog();
log.info("Hello world!");

VanillaJS

In your HTML:

<!-- Option One: Minified -->
<script src="PATH/TO/abstract-log/dist/abstract-log.min.js"></script>

<!-- Option Two: Raw source -->
<script src="PATH/TO/abstract-log/abstract-log.js"></script>

In your JS:

var log = new window.AbstractLog();
log.info("Hello world!");

Build Integration

Contributing

Please see CONTRIBUTING