1.2.2 • Published 3 years ago
@lauwri/log v1.2.2
log
A lightweight node logger with zero dependencies.
Installation
Install through npm
npm i @lauwri/log
yarn add @lauwri/log
Usage
import log from "@lauwri/log";
// Enables logging to file, use outputFile to change output
log.setup({
enableFile: true,
});
log.info("This is a regular log");
//INFO: 2022-05-16T22:53:47.688Z example.ts:8:5: This is a regular log
log.warn("This is a warning log");
//WARN: 2022-05-16T22:53:47.692Z example.ts:9:5: This is a warning log
log.error("This is a error log");
//ERROR: 2022-05-16T22:53:47.693Z example.ts:10:5: This is a error log
log.debug("This is a debug log");
//DEBUG: 2022-05-16T22:53:47.694Z example.ts:11:5: This is a debug log
API
import log from "@lauwri/log";
info
warn
error
debug
(message?: any, ...args: any[])
:
Log by level
setup(options)
:
Set global options for logger
options
:
command | description | default |
---|---|---|
logLevels | Array of levels to log | Info ,Debug ,Warn ,Error |
enableLogging | Enable logging to console | true |
enableFile | Enable logging to file | false |
outputFile | Path to log output file | ./logs/logs.txt |
tagDate | Tags file with a timestamp | true |
tagLevel | Tags file with a log level | true |
tagColor | Tags file with a color | true |
tagFileMessage | Tags file with a message | Logging started at n from origin x |
color | Colors for logging levels |
Colors
:
ANSI colorcodes. If any color is present, log adds Reset
as last argument to console.
Name | Value |
---|---|
Reset | "\x1b[0m" |
Bright | "\x1b[1m" |
Dim | "\x1b[2m" |
Underscore | "\x1b[4m" |
Blink | "\x1b[5m" |
Reverse | "\x1b[7m" |
Hidden | "\x1b[8m" |
FgBlack | "\x1b[30m" |
FgRed | "\x1b[31m" |
FgGreen | "\x1b[32m" |
FgYellow | "\x1b[33m" |
FgBlue | "\x1b[34m" |
FgMagenta | "\x1b[35m" |
FgCyan | "\x1b[36m" |
FgWhite | "\x1b[37m" |
BgBlack | "\x1b[40m" |
BgRed | "\x1b[41m" |
BgGreen | "\x1b[42m" |
BgYellow | "\x1b[43m" |
BgBlue | "\x1b[44m" |
BgMagenta | "\x1b[45m" |
BgCyan | "\x1b[46m" |
BgWhite | "\x1b[47m" |