Read Github README, in case of unpublished changes
NodeJS Console Logger
A powerful and efficient JavaScript logger for NodeJS
npm install forbidden-node-logger
Getting Started
Logger (No File Support)
const NodeLogger = ;const Logger = ;
Logger (File Support)
const NodeLogger = ;const Logger = dirPath: __dirname + "/log" ;
Logger Basics
const NodeLogger = ;const Logger = dirPath: __dirname + "/log" ; Logger // Emits when logging with any methodLogger; // Emits when doing `Logger.error();`// All log methods include an event "info", "debug" vice versa Logger;Logger;Logger; // Look at "test/break.js" as why this exists Loggerhistory; // Get the last 2 logsLoggerfileHistory; // Log an array of lines from the latest log file
Avoid Unhandled Rejection
const NodeLogger = ;const Logger = dirPath: __dirname + "/log" ; /*The EventEmitter will cause an unhandled rejection errorWhen you use Logger.error(). You need to handle the reject by not handling it*/Logger; // This only applies to those who are not in need of the "error" emit Logger;
File Structure
yyyy ->
mm ->
dd.log
dd-warn.log
dd-error.log
Example
2019 ->
09 ->
01.log
01-error.log
10 ->
03.log
04.log
05.log
06.log
06-warn.log
07.log
07-error.log
2020 ->
01 ->
01.log
01-error.log
02 ->
03.log
04.log
05.log
06.log
06-warn.log
07.log
07-error.log
Test Scripts
In the project directory you can run the following scripts:
npm run log
Will run a sample of the Logger's log methods and events
Located at test/log.js
npm run history
Will run a sample of Logger's history and file history
Located at test/history.js
npm run break
Will run a file which is designed to break Logger
Used for educational purposes. eventLog() is to prevent this.
Located at test/break.js
Colour Codes
PREFIX: &
Special
RESET: r
REVERSE: k
Format
BOLD: l
ITALIC: o
UNDER: n
STRIKE: m
Colour
FOREGROUND: -
BACKGROUND: _
EXAMPLE: &-5
DARK RED: 4
BRIGHT RED: c
DARK YELLOW: 6
BRIGHT YELLOW: e
DARK GREEN: 2
BRIGHT GREEN: a
DARK CYAN: 3
BRIGHT CYAN: b
DARK BLUE: 1
BRIGHT BLUE: 9
DARK PURPLE: 5
BRIGHT PURPLE: d
DARK WHITE: 7
BRIGHT WHITE: f
DARK BLACK: 0
BRIGHT BLACK: 8