Catalog npm
Back to packageRELEASE DETAILS

2.0.2

npm

106

Log library with sequences and colors, for node.js and browsers

browsercolorslognodesequences
Published3 Oct 2017
Direct dependencies7
Transitive dependenciesNot calculated

README

Current package documentation

npm version build status

106

Log library with sequences and colors, for node.js and browsers

Synopsis

The numbers 106 are shaped like the word "log", but I assume you already got that.

There are lots of log libraries out there, but this one has two main targets:

  • Working the same in browsers and node.js
  • Support for sequences (flows)

When any kind of asynchronous operation take place, log lines get interleaved. This applies to server-side as well as client-side, and is the result of asynchrony per se.

To follow logs and see what lines are part of a certain code flow (a client-side outgoing call, or a server-side incoming request, e.g.), the concept of unique tags (or "sequences") help out a lot. Consider an HTTP server getting a request, performing multiple asynchronous tasks (like database operations) and then responding back. All things which get logged here, will be interleaved with other requests.

You also have the possibility to add your own custom transports (e.g. to automatically send log errors from the browser to the server).

API

The API works the same in the browser as well as in node.js.

Core logging API

// In lib/foobar.js:
var log = require( '106' )( 'lib:foobar' );

require( '106' ).level = 'debug'; // Sets log level

log.info( "Hello world", { objects: 'are allowed' } );
log.warn( "Warnings with warn()" );
log.error( "Errors with error()", new Error( "doh!" ) );

The log levels are:

silly
debug
verbose
info
warn
error

Sequences

var logger = require( '106' );
var log = logger( 'server' );
var Sequencer = logger.Sequencer;

// An http server creates a sequencer for incoming HTTP requests
var sequencer = new Sequencer( 'http', { timeout: 5000 } );

// For each incoming request:
var seq = sequencer.next( );

// Start the sequence
log.info( seq, Sequencer.IN, "Got request %s", req.path );

// Pass around 'seq' wherever logging is needed, and prepend it
// to any arguments to log.info, log.warn, log.* ... Example:
log.info( seq, "Querying database for users..." );

// When the request ends successfully (HTTP server replies to client)
log.info( seq, Sequencer.OUT, "Request finished" );
// or if the request chain failed:
var err = new Error( "Could not connect to database" );
log.error( seq, Sequencer.OUTERR, "Request failed", err );

All logging using a sequence will print the time since the sequence was created. The output will be:

2016-02-24 08:47:08.315 info - server: [seq:http:1] ⇒ Got request /my-path 1ms
2016-02-24 08:47:08.322 info - server: [seq:http:1] Querying database for users... 2ms
2016-02-24 08:47:08.324 info - server: [seq:http:1] ⇐ Request finished 3ms
2016-02-24 08:47:08.324 error - server: [seq:http:1] ⇍ Request failed 4ms
{
    name: "Error",
    message: "Could not connect to database",
    stack: [ ... ]
}

The above will be colored, and each sequence will get its own color (circulating between a few pre-defined colors). Again, this applies to node.js as well as browsers!

Custom transports

To add a custom transport, you create your own callback function, and call addTransport( ) on the logger. You can also set your own log-level using the second (optional) argument, so that this transport only get certain logs.

var logger = require( '106' );
var log = logger( 'foo' );

function customTransport( logData )
{
    logData.level;             // The log level, 'info', 'warn', etc
    logData.messages;          // The message parts (as an array)
    logData.errror;            // The error object, if that was the last
                               // argument.
    logData.meta;              // The last argument to log() if it's an
                               // object or array, and not covered by a '%s'.
    logData.prefix;            // The prefix ('foo' in this example)
    logData.sequence;          // The sequence (or null)
    logData.sequenceDirection; // The sequence direction (or null)
    logData.time;              // The time (as a javascript Date object)
    logData.timestamp;         // The time as an ISO-formatted string
}

// Forward error logs to "customTransport"
logger.addTransport( customTransport, { level: 'warn' } );

log.error( "This will be sent to the custom logger" );
log.warn( "And this" );
log.info( "But this won't" );

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
ansi-styles
Environment
{
  "local_name": "ansi-styles",
  "alias": false,
  "peer_metadata": null
}
^2.2.0runtime
winston
Environment
{
  "local_name": "winston",
  "alias": false,
  "peer_metadata": null
}
^2.1.1runtime
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^7.0.31development
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^2.4.5development
pre-commit
Environment
{
  "local_name": "pre-commit",
  "alias": false,
  "peer_metadata": null
}
1.xdevelopment
timekeeper
Environment
{
  "local_name": "timekeeper",
  "alias": false,
  "peer_metadata": null
}
0.0.5development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
2.4.xdevelopment

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-l0+Sz80hak7vsf4+un/pBvs454Ftwra/MTokpbICh99enqQJoQwmjfvWBI+ZuGg9lrTO+1+xzSpR2TznkFppHw==",
  "shasum": "c2536e6c5079eb33dfc0360a17f0d9cb904f3163",
  "tarball": "https://registry.npmjs.org/106/-/106-2.0.2.tgz",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQDLW0WnQMnBQ+VIEc2fvO3/MwQ+P/f0cExdp/0xyILbIwIgKNFNPMJEhAR3KP2xd2sghYbFUNY62sTsb6IhASqcI3E="
    }
  ]
}

Repository

PENDING
grantila/106

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:00 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:18c37cb331b8a4cf240800989c3fc7c252dde129589ae1cb8b0b09c033d93147

Other collected versions

2.1.126 Oct2.0.511 Oct2.0.45 Oct2.0.33 Oct2.0.13 Oct2.0.020 JunView all collected versions →