Home Reference Source Test

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 :sparkles: babel-code-frame :sparkles:):

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

Hiplog errors output

Options

level

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

stream

Stream to write to.

displayTime

Whether to display time information or not. Example:

Hiplog time output

displayTimeFormat

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

separator

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

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:

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


<sup>Created with npm-package-skeleton.</sup>