0.2.0 • Published 7 months ago

@hunteroi/advanced-logger v0.2.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
7 months ago

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:

KeyTypeDescriptionDefault
includeTimestampbooleanIf true, timestamp will be included in the message that is written to the console.false
minLevelLogEventLevelThe minimum level for which events with specified level or higher will be output to the consoleinfo
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):

LabelDescriptionBitfield
offWhen the minimum level is set to this, nothing will be logged.0
fatalCritical errors causing complete failure of the application.1
errorIndicates failures within the application or connected systems.3
warningIndicators of possible issues or service/functionality degradation.7
infoEvents of interest or that have relevance to outside observers (default).15
debugInternal control flow and diagnostic state dumps to facilitate pinpointing of recognised problems.31
verboseTracing 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');