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 = require('standardlogger');
logger.INFO("[+] a message!");
logger.DEBUG("[+] a less important message!");
logger.WARN("[+] a threatening message");
Make functions global
Make INFO/WARN/DEBUG/vDEBUG/DIE globally accessible functions across program
logger.exportLoggerFunctionsToGlobal();
INFO("[+] a message!");
WARN("[!] a threatening message again!");
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.setLoggerVerbosity(0);
logger.setLoggerVerbosity(1);
logger.setLoggerVerbosity(-1);
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)
DEBUG("[D] Started request...");
INFO("[*] Successfully completed the request");
WARN("[-] Request gave us 404");
logger.turnOnColors();
logger.turnOffColors();
Timestamps
Timestamps are AUTOMATICALLY prefixed to all log calls in format of HH:MM:SS
WARN("[!] DISK I/O error");
DEBUG("[D] User registered.");
22:48:03 [!] DISK I/O error
22:48:04 [D] User registered.
logger.turnOnTimestamps();
logger.turnOffTimestamps();
DIE
DIE is a logger function that kills the program after printing. Useful for big errors
DIE("[!] Fatal error of some sort happened! Messages for DIE are ALWAYS printed.");
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"
logger.setColorTrigger("cat", "\x1b[36m");
INFO("the cat is in the tree");
logger.removeColorTrigger("cat");
INFO("the cat is in the tree");
{
'[*]': "\x1b[32m",
'[D]': "\x1b[37m",
'[DDDD]': "\x1b[1;37m",
'[!]': "\x1b[93m",
'[!!!!]': "\x1b[1;31m",
'[-]': "\x1B[33m",
'[%]': "\x1b[34m",
}
Credits
http://x64projects.tk/