1.0.3 • Published 2 years ago

@evokegroup/console-logger v1.0.3

Weekly downloads
11
License
ISC
Repository
-
Last release
2 years ago

@evokegroup/console-logger

Logs timestamped messages to the console.

Class: ConsoleLogger

const ConsoleLogger = require('@evokegroup/console-logger');
ConsoleLogger.log('Log this message');
// Expected result: [HH:mm:ss] Log this message

Static Properties

ConsoleLogger.Style

NameDescription
BackgroundBackground colors
Background.Black
Background.Blue
Background.Cyan
Background.Gray
Background.Green
Background.Magenta
Background.Red
Background.White
Background.Yellow
Background.BrightBlue
Background.BrightCyan
Background.BrightGreen
Background.BrightMagenta
Background.BrightRed
Background.BrightWhite
Background.BrightYellow
ForegroundForeground colors
Foreground.Black
Foreground.Blue
Foreground.Cyan
Foreground.Gray
Foreground.Green
Foreground.Magenta
Foreground.Red
Foreground.White
Foreground.Yellow
Foreground.BrightBlue
Foreground.BrightCyan
Foreground.BrightGreen
Foreground.BrightMagenta
Foreground.BrightRed
Foreground.BrightWhite
Foreground.BrightYellow
InverseInverse of default style
ResetResets to default style
UnderscoreUnderscores the text

Static Methods

ConsoleLogger.setStylesEnabled(flag)

Enable or disabled styles globally.

ConsoleLogger.setTimestampEnabled(flag)

Enable or disabled timestamps globally.

ConsoleLogger.setTimestampStyle(styles)

Set timestamp style globally.

ConsoleLogger.log(message, styles, timestamp = true)

Logs a message with given styles.

const ConsoleLogger = require('@evokegroup/console-logger');
ConsoleLogger.log('Log this message');
ConsoleLogger.log('Another message in blue', ConsoleLogger.Style.Foreground.Blue);
ConsoleLogger.log('Underscored in green with no timestamp', [ConsoleLogger.Style.Foreground.Green, ConsoleLogger.Style.Underscore], false);
ConsoleLogger.log([
  new ConsoleLogger.MessagePart('red', ConsoleLogger.Style.Foreground.Red),
  new ConsoleLogger.MessagePart(' green', ConsoleLogger.Style.Foreground.Green)
]);

Parameters

NameTypeDefaultDescription
messageArray<ConsoleLogger.MessagePart>, ConsoleLogger.MessagePart, stringThe message to be logged
stylesArray<ConsoleLogger.Style>, ConsoleLogger.StyleThe style of the message
timestampbooleantruePrint a timestamp

ConsoleLogger.error(message, timestamp = true)

Logs a message in red.

const ConsoleLogger = require('@evokegroup/console-logger');
ConsoleLogger.error('error');

ConsoleLogger.info(message, timestamp = true)

Logs a message in cyan.

const ConsoleLogger = require('@evokegroup/console-logger');
ConsoleLogger.info('info');

ConsoleLogger.warn(message, timestamp = true)

Logs a message in yellow.

const ConsoleLogger = require('@evokegroup/console-logger');
ConsoleLogger.warn('warn');

Class: ConsoleLogger.MessagePart

constructor(text, styles)

ConsoleLogger.log([
  new ConsoleLogger.MessagePart('red', ConsoleLogger.Style.Foreground.Red),
  new ConsoleLogger.MessagePart(' green', ConsoleLogger.Style.Foreground.Green)
]);

Properties

NameTypeDescription
textstringThe text to log
stylesArray<ConsoleLogger.Style>, ConsoleLogger.StyleThe style to apply to the text