@hackthedev/terminal-logger 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/README.md +91 -0
- package/assets/image-20260116014526091.png +0 -0
- package/assets/image-20260116015034925.png +0 -0
- package/assets/image-20260116015557446.png +0 -0
- package/index.mjs +76 -0
- package/package.json +19 -0
package/.gitattributes
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Terminal Logger
|
|
2
|
+
|
|
3
|
+
This small library was designed for NodeJS and to bring pretty logs to the terminal. It has the following features:
|
|
4
|
+
|
|
5
|
+
- `Logger.info` prints in cyan
|
|
6
|
+
- `Logger.warn` prints in yellow
|
|
7
|
+
- `Logger.error` prints in red
|
|
8
|
+
- `Logger.success` prints in green
|
|
9
|
+
- `Logger.debug` will only print if `Logger.logDebug` is set to true and on default in a bright black color.
|
|
10
|
+
- `Logger.log` can be used to print custom "levels", which is whats shown in the `[ ]` brackets, like `INFO`, `SUCCESS` and more.
|
|
11
|
+
- `Logger.space` will print emty lines and supports a number argument to print multiple empty lines without spamming `Logger.space` lines or `console.log` and can be done with `Logger.space(2)` for two empty lines or more.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
------
|
|
18
|
+
|
|
19
|
+
## Syntax examples
|
|
20
|
+
|
|
21
|
+
This is a general example
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
Logger.info("Content")
|
|
25
|
+
Logger.success("Content")
|
|
26
|
+
Logger.error("Content")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
### Printing objects
|
|
32
|
+
|
|
33
|
+
Objects will be printed using `JSON.stringify`
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
let obj = {
|
|
37
|
+
name: "Marvin"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Logger.info(obj)
|
|
41
|
+
Logger.warn(obj)
|
|
42
|
+
Logger.error(obj)
|
|
43
|
+
Logger.success(obj)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Custom colors and effects
|
|
47
|
+
|
|
48
|
+
You can print text with custom supported colors like in the following example. You can also use some special effects depending on your terminal like making text blink, underlined and more.
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
Logger.info(`My awesome text`, Logger.colors.fgMagenta)
|
|
52
|
+
Logger.info(`My blinking text`, Logger.colors.blink)
|
|
53
|
+
|
|
54
|
+
// Alternative, theoretical multicolored words
|
|
55
|
+
Logger.info(`${Logger.colors.fgMagenta} My awesome text`)
|
|
56
|
+
Logger.info(`${Logger.colors.blink} My blinking text`)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
// Supported colors and effects
|
|
62
|
+
static colors = {
|
|
63
|
+
reset: "\x1b[0m",
|
|
64
|
+
bright: "\x1b[1m",
|
|
65
|
+
dim: "\x1b[2m",
|
|
66
|
+
underscore: "\x1b[4m",
|
|
67
|
+
blink: "\x1b[5m",
|
|
68
|
+
reverse: "\x1b[7m",
|
|
69
|
+
hidden: "\x1b[8m",
|
|
70
|
+
|
|
71
|
+
fgBlack: "\x1b[30m",
|
|
72
|
+
fgRed: "\x1b[31m",
|
|
73
|
+
fgGreen: "\x1b[32m",
|
|
74
|
+
fgYellow: "\x1b[33m",
|
|
75
|
+
fgBlue: "\x1b[34m",
|
|
76
|
+
fgMagenta: "\x1b[35m",
|
|
77
|
+
fgCyan: "\x1b[36m",
|
|
78
|
+
fgWhite: "\x1b[37m",
|
|
79
|
+
fgGray: "\x1b[90m",
|
|
80
|
+
|
|
81
|
+
bgBlack: "\x1b[40m",
|
|
82
|
+
bgRed: "\x1b[41m",
|
|
83
|
+
bgGreen: "\x1b[42m",
|
|
84
|
+
bgYellow: "\x1b[43m",
|
|
85
|
+
bgBlue: "\x1b[44m",
|
|
86
|
+
bgMagenta: "\x1b[45m",
|
|
87
|
+
bgCyan: "\x1b[46m",
|
|
88
|
+
bgWhite: "\x1b[47m"
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export default class Logger {
|
|
2
|
+
static logDebug = false;
|
|
3
|
+
|
|
4
|
+
static colors = {
|
|
5
|
+
reset: "\x1b[0m",
|
|
6
|
+
bright: "\x1b[1m",
|
|
7
|
+
dim: "\x1b[2m",
|
|
8
|
+
underscore: "\x1b[4m",
|
|
9
|
+
blink: "\x1b[5m",
|
|
10
|
+
reverse: "\x1b[7m",
|
|
11
|
+
hidden: "\x1b[8m",
|
|
12
|
+
|
|
13
|
+
fgBlack: "\x1b[30m",
|
|
14
|
+
fgRed: "\x1b[31m",
|
|
15
|
+
fgGreen: "\x1b[32m",
|
|
16
|
+
fgYellow: "\x1b[33m",
|
|
17
|
+
fgBlue: "\x1b[34m",
|
|
18
|
+
fgMagenta: "\x1b[35m",
|
|
19
|
+
fgCyan: "\x1b[36m",
|
|
20
|
+
fgWhite: "\x1b[37m",
|
|
21
|
+
fgGray: "\x1b[90m",
|
|
22
|
+
|
|
23
|
+
bgBlack: "\x1b[40m",
|
|
24
|
+
bgRed: "\x1b[41m",
|
|
25
|
+
bgGreen: "\x1b[42m",
|
|
26
|
+
bgYellow: "\x1b[43m",
|
|
27
|
+
bgBlue: "\x1b[44m",
|
|
28
|
+
bgMagenta: "\x1b[45m",
|
|
29
|
+
bgCyan: "\x1b[46m",
|
|
30
|
+
bgWhite: "\x1b[47m"
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
static log(level, message, color = Logger.colors.fgWhite) {
|
|
34
|
+
if (message instanceof Error) {
|
|
35
|
+
console.log(`${color}${Logger.displayDate()}[${level}] ${message.message}\n${message.stack}${Logger.colors.reset}`);
|
|
36
|
+
} else if (typeof message === 'object') {
|
|
37
|
+
console.log(`${color}${Logger.displayDate()}[${level}]\n${JSON.stringify(message, null, 4)}${Logger.colors.reset}`);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`${color}${Logger.displayDate()}[${level}] ${message}${Logger.colors.reset}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static space(amount = 1){
|
|
44
|
+
for(let i = 0; i < amount; i++) {
|
|
45
|
+
console.log(" ");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static info(message, color = "") {
|
|
50
|
+
Logger.log("INFO", message, color ? Logger.colors.fgCyan + color : Logger.colors.fgCyan);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static success(message, color = "") {
|
|
54
|
+
Logger.log("SUCCESS", message, color ? Logger.colors.fgGreen + color : Logger.colors.fgGreen);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static warn(message, color = "") {
|
|
58
|
+
Logger.log("WARN", message, color ? Logger.colors.fgYellow + color : Logger.colors.fgYellow);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static error(message, color = "") {
|
|
62
|
+
Logger.log("ERROR", message, color ? Logger.colors.fgRed + color : Logger.colors.fgRed);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static debug(message, color = "") {
|
|
66
|
+
if(!Logger.logDebug) return;
|
|
67
|
+
Logger.log("DEBUG", message, color ? Logger.colors.bright + Logger.colors.fgBlack + color : Logger.colors.bright + Logger.colors.fgBlack);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static displayDate() {
|
|
71
|
+
const today = new Date();
|
|
72
|
+
const date = today.getFullYear() + '-' + (today.getMonth() + 1).toString().padStart(2, '0') + '-' + today.getDate().toString().padStart(2, '0');
|
|
73
|
+
const time = today.getHours().toString().padStart(2, '0') + ":" + today.getMinutes().toString().padStart(2, '0') + ":" + today.getSeconds().toString().padStart(2, '0');
|
|
74
|
+
return `[${date} ${time}] `;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hackthedev/terminal-logger",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "This small library was designed for NodeJS and to bring pretty logs to the terminal. It has the following features:",
|
|
5
|
+
"homepage": "https://github.com/NETWORK-Z-Dev/terminal-logger#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/NETWORK-Z-Dev/terminal-logger/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/NETWORK-Z-Dev/terminal-logger.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"author": "",
|
|
15
|
+
"main": "index.mjs",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
}
|
|
19
|
+
}
|