1.0.3 • Published 4 years ago
@evokegroup/console-logger v1.0.3
@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 messageStatic Properties
ConsoleLogger.Style
| Name | Description |
|---|---|
| Background | Background 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 | |
| Foreground | Foreground 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 | |
| Inverse | Inverse of default style |
| Reset | Resets to default style |
| Underscore | Underscores 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
| Name | Type | Default | Description |
|---|---|---|---|
| message | Array<ConsoleLogger.MessagePart>, ConsoleLogger.MessagePart, string | The message to be logged | |
| styles | Array<ConsoleLogger.Style>, ConsoleLogger.Style | The style of the message | |
| timestamp | boolean | true | Print 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
| Name | Type | Description |
|---|---|---|
| text | string | The text to log |
| styles | Array<ConsoleLogger.Style>, ConsoleLogger.Style | The style to apply to the text |