standardlogger
ES6 JS class for specifying log output verbosity, log colors, and timestamps
Installation
npm install standardlogger --save
Simple usage
ES6 JS class for specifying log output verbosity, log colors, and timestamps.
All content is always just logged to console.log (stdout)
let logger = ; logger;logger;logger;
Make functions global
Make INFO/WARN/DEBUG/vDEBUG/DIE globally accessible functions across program
logger;; // No longer need to call with logger.INFO;
Change Verbosity
Lower the verbosity to disable some functions from printing when they're called.
Verbosity priorities are: { vDEBUG: 2, DEBUG: 1, INFO: 0, WARN: -1 }
logger; // DEFAULT. only INFO/WARN calls will be printedlogger; // only DEBUG/INFO/WARN calls will be printedlogger; // only WARN calls will be printed
Colors
ALL log functions will color messages if you put certain strings in your message.
Put [D]
in your message to ensure it becomes light gray (like a debug message)
Put [!]
in your message to ensure it becomes bright yellow (like a warning)
Put [*]
in your message to ensure it becomes green (conveying success)
; // Will be light gray; // Will be green; // Colors can be globally toggled on or off:logger; // On by defaultlogger;
Timestamps
Timestamps are AUTOMATICALLY prefixed to all log calls in format of HH:MM:SS
;;// will output:
22:48:03 [!] DISK I/O error
22:48:04 [D] User registered.
// Timestamps can be turned ON or OFF for all functions:logger; // On by defaultlogger;
DIE
DIE is a logger function that kills the program after printing. Useful for big errors
// This is a special function. This EXITS the program after logging your message;
Custom color triggers
You can add your own triggers to change message colors.
i.e. if you want messages containing the word "cat" to always be "cyan"
// To add your own global color trigger:logger; // 1st arg is trigger, 2nd arg is color for cyan; // <-- will be printed cyan in terminal // To remove a color trigger globally:logger;; // <-- will be printed normally in terminal // This is the full default color hash. You can use or remove these triggers always // '[+] ' will be just standard unaltered color by default (like any other message) '[*]': "\x1b[32m" // green for success (used to look for 'Successfully') '[D]': "\x1b[37m" // light gray for less important '[DDDD]': "\x1b[1;37m" // bold gray for medium importance '[!]': "\x1b[93m" // brighter yellow for warning '[!!!!]': "\x1b[1;31m" // dark red for BIG ERROR '[-]': "\x1B[33m" // darker yellow for milder warning '[%]': "\x1b[34m" // darker blue for... blue messages