Provides ANSI color logging.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test/src
.babelrc
.editorconfig
.esdocrc
.eslintignore
.eslintrc
.gitignore
.npmscriptrc
.travis.yml
AUTHORS.md
CHANGELOG.md
LICENSE
README.md
package.json

README.md

typhonjs-color-logger

NPM Documentation Code Style License Gitter

Build Status Coverage Dependency Status

Provides a color coded logger for ANSI terminal usage. In addition to providing a global scope logger typhonjs-color-logger is optionally plugin enabled via typhonjs-plugin-manager and can self-register on an eventbus with all methods exposed as event bindings.

In the future an option to use CSS colors for browser usage will be enabled.

There are several format options to display additional data / info including location where the log method is invoked in addition to a time stamp. By default the time stamp option is disabled.

When passing in an Error for logging the stack trace of the error will be used for info and trace creation. The trace method will automatically generate a stack trace.

format: [LogLevel] [Time] [File] log text

Log level and color:

  • fatal: light red
  • error: red
  • warn: yellow
  • info: green
  • debug: blue
  • verbose: purple
  • trace: light cyan

Each log method for the log levels above have two alternate versions that are accessed by appending Compact, NoColor or Raw to the method name. Or if using event bindings appending :compact, :nocolor or :raw. The no color option with, well, no color outputting the message with the current log format and the raw format will output just the raw message with no format or color applied.

In addition trace inclusive and exclusive regexp filtering is available to eliminate spurious code removing it from the stack trace. By default the typhonjs-color-logger and backbone-esnext-events is excluded from trace results. Additionally the following events from typhonjs-plugin-manager are handled to automatically add and remove trace filters from plugins added & removed via the event bindings: typhonjs:plugin:manager:added:plugin, typhonjs:plugin:manager:plugin:changed:eventbus, and typhonjs:plugin:manager:removed:plugin. To skip auto filter registration for a particular plugin set logAutoFilter to false in the associated plugins options.

A simple example:

import logger from 'typhonjs-color-logger';

// simple usage
logger.error('An error occurred!');

Example typhonjs-plugin-manager usage:

import PluginManager    from 'typhonjs-plugin-manager';
import eventbus         from 'backbone-esnext-eventbus';

const pluginManager = new PluginManager({ eventbus });

// This will automatically wire up typhonjs-color-logger to the eventbus.
pluginManager.add({ name: typhonjs-color-logger });

// simple usage
eventbus.trigger('log:error', 'An error occurred!');

Please see: