Fancy lightweight logging utility for Node.js
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
media
src
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md Re-arranged badges from 2 lines to 1 Jul 5, 2018
demo.js
package.json

README.md

hiplog

Fancy lightweight logging utility for Node.js

Latest Stable Version Build Status NPM Downloads dependencies Status Test Coverage API Documentation

Installation

Prerequisites: Node.js 6+, npm 3+.

npm install --save hiplog

Usage

const { Log } = require('hiplog');
const log = new Log({ level: 'debug' });
log.debug('messages to debug an application');
log.info('a purely informational message');
log.notice('a normal but significant condition');
log.warning('warning condition');
log.error('error condition');
log.critical('the system is in critical condition');
log.alert('action must be taken immediately');
log.emergency('system is unusable');

Hiplog levels output

Objects

Objects are automatically stringified using Purdy. Small objects (< 200 characters) are inlined.

log.info('a small object:', { int: 123, bool: true, str: 'Hello' });

Hiplog small objects output

const circular = {};
circular.inner = circular;

log.info('a bigger object', {
  null: null,
  undefined,
  integer: 123,
  boolean: true,
  string: 'Hello',
  funtion: function myFunction() {},
  circular,
  array: ['one', 'two', 'three', 'four'],
});

Hiplog big objects output

Errors

Errors are displayed using jest-message-util (powered by babel-code-frame ):

try {
  throw new Error('Error example');
} catch (e) {
  log.error(e);
}

Hiplog errors output

Options

level

  • type: string
  • default value: 'info'

Minimum level to display. All messages below this level will be ignored.

stream

  • type: Steam | function: integer -> Stream
  • default value:
    level => (level <= 4 ? process.stderr : process.stdout)

Stream to write to.

displayTime

  • type: boolean
  • default value: false

Whether to display time information or not. Example:

Hiplog time output

displayTimeFormat

  • type: string
  • default value: 'yyyy-mm-dd HH:MM:ss.l'

Date format to display time in, when displayTime is set to true. See dateformat for possible values.

separator

  • type: string
  • default value: ' • '

Separator between message header and body, and also between time and and label, when displayTime is set to true;

format

  • type: function: string -> string
  • default value: hiplog.format

Message formatter function.

fromEnv

const hiplog = require('hiplog');
const log = hiplog.fromEnv();

fromEnv is a utility function that will create a new instance of Log with options taken from environment variables:

  • NODE_ENV:
    • 'development' (default): displayTime is disabled,
    • 'test': displayTime is disabled, 'level' is set to 'critical',
    • 'production': use default values for each option.
  • LOG: sets level value.
  • LOG_LEVEL: alias for LOG.
  • LOG_TIME: when set to true or 1, enables displayTime.
  • LOG_TIME_FORMAT: sets displayTimeFormat value.

Note: fromEnv accepts an options parameter that allow overriding these defaults. Example:

const hiplog = require('hiplog');
const log = hiplog.fromEnv({ displayTime: false });
// displayTime will be always `false`, disregarding the value of `LOG_TIME`.

Contributing

Please refer to the guidelines for contributing.

devDependencies Status

License

License


Created with npm-package-skeleton.