@strivexnl/simple-logger
v1.0.2
Published
A simple wrapper around the console log functions.
Downloads
1
Readme
Simple Logger
Just a wrapper around the console functions. Easy way to log message. Only logs when log level has been set.
Log levels
The available log levels are:
- lvlNone
- lvlError
- lvlWarn
- lvlInfo
- lvlDebug
- lvlTrace
We also have some combined levels, easy to use and less to write:
- lvlAll All log levels combined.
- lvlErrorWarnInfo (default) Only Error, Warn and Info levels
- lvlDebugTrace Only Debug and Trace levels
Usage
Usage is straightforward:
import { SimpleLogger } from "SimpleLogger";
// Give the log levels you want as a parameter to the constructor.
const log = new SimpleLogger(SimpleLogger.lvlErrorWarnInfo);
// Call the log with the used loglevel.
log.log(SimpleLogger.lvlDebug, 'This is a debug message!');
// Or call the special method for each level directly.
log.logDebug('This is another debug message!');
log.logInfo('Some useful info message here!');
DateTime formatting.
Default the SimpleLogger uses "YYYY-MM-DD HH:mm:ss.SSS" as the default format. You can change that by using the second parameter in the constructor:
// Give the log levels you want as a parameter to the constructor.
const log = new SimpleLogger(SimpleLogger.lvlErrorWarnInfo, 'YYYYMMDD-HHmmss');