@hunteroi/advanced-logger
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

advanced-logger

Advanced Logger is a logging framework using Javascript's Console object, moment and chalk libraries to log strings to your console.

npm

Usage

This library can be used within Javascript and Typescript applications.

// Javascript

const { ConsoleLogger } = require('@hunteroi/advanced-logger');

const log = new ConsoleLogger();


// Typescript

import { ConsoleLogger } from '@hunteroi/advanced-logger';

const log = new ConsoleLogger();

Installation

advanced-logger can be found on npm. Run the following:

yarn add @hunteroi/advanced-logger

Configuration

advanced-logger provides a constructor with a LoggerOptions parameter. It supports the following properties:

Key Type Description Default
includeTimestamp boolean If true, timestamp will be included in the message that is written to the console. false
minLevel LogEventLevel The minimum level for which events with specified level or higher will be output to the console info
const log = new ConsoleLogger({ includeTimestamp: true });

Log Levels

There are 6 log levels available by default, in addition to a setting to disable logging completely. In decreasing order of severity (with descriptions borrowed from Seq):

Label Description Bitfield
off When the minimum level is set to this, nothing will be logged. 0
fatal Critical errors causing complete failure of the application. 1
error Indicates failures within the application or connected systems. 3
warning Indicators of possible issues or service/functionality degradation. 7
info Events of interest or that have relevance to outside observers (default). 15
debug Internal control flow and diagnostic state dumps to facilitate pinpointing of recognised problems. 31
verbose Tracing information and debugging minutiae; generally only switched on in unusual situations. 63

The log levels can also be represented as bitfields, and each log level also includes any levels of higher severity. For example, warning will also allow events of the error level through, but block info, debug and verbose.

The Logger object contains shorthand methods for logging to each level.

log.fatal('some fatal logging');
log.error('some error logging');
log.warn('some warning logging');
log.info('some info logging');
log.debug('some debug logging');
log.verbose('some verbose logging');

Package Sidebar

Install

npm i @hunteroi/advanced-logger

Weekly Downloads

2

Version

0.2.0

License

Apache-2.0

Unpacked Size

27.1 kB

Total Files

19

Last publish

Collaborators

  • hunteroi