Code Monkey home page Code Monkey logo

abstract-log's Introduction

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

abstract-log's People

Contributors

ryan-roemer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

abstract-log's Issues

Core: Decide instance initialization options.

  • Shims: What exists even if underlying logger doesn't have it? (e.g, warn, info, etc.)
  • Mappings: What levels should I map to other levels? (e.g., log.log -> log.info)
  • Logger: Underlying logger to use.

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.