Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

FormidableLabs/abstract-log

Repository files navigation

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.

  • TODO: Document initialization options.
  • TODO: Also place options examples in each AbstractLog( call... #3

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

  • TODO: Document initialization here? #3

  • TODO: Document shimming. #1

  • TODO: Document integration with (1) console, (2) bunyan #2

Contributing

Please see CONTRIBUTING

About

A micro logging wrapper for shims, logging frameworks, console logs, etc.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published