@sjts/lib-log 30.1.4 → 30.1.5
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/dist/Logger.d.ts +18 -0
- package/dist/Logger.js +40 -7
- package/package.json +1 -1
package/dist/Logger.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { LoggerLevel } from './LoggerLevel.js';
|
|
2
2
|
export type LogListener = (message: string, data?: any) => void;
|
|
3
3
|
export declare class Logger {
|
|
4
|
+
static red: string;
|
|
5
|
+
static green: string;
|
|
6
|
+
static yellow: string;
|
|
7
|
+
static blue: string;
|
|
8
|
+
static magenta: string;
|
|
9
|
+
static cyan: string;
|
|
10
|
+
static reset: string;
|
|
11
|
+
static bold: string;
|
|
12
|
+
static dim: string;
|
|
13
|
+
static italic: string;
|
|
14
|
+
static underline: string;
|
|
15
|
+
static strikethrough: string;
|
|
16
|
+
static bgRed: string;
|
|
17
|
+
static bgGreen: string;
|
|
18
|
+
static bgYellow: string;
|
|
19
|
+
static bgBlue: string;
|
|
20
|
+
static bgMagenta: string;
|
|
21
|
+
static bgCyan: string;
|
|
4
22
|
private level;
|
|
5
23
|
private systemTags;
|
|
6
24
|
c: any;
|
package/dist/Logger.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { LoggerLevel } from './LoggerLevel.js';
|
|
2
2
|
const { DEBUG, INFO, SYSTEM, WARN, ERROR, THROW, KILL } = LoggerLevel;
|
|
3
3
|
export class Logger {
|
|
4
|
+
static red = '\x1b[31m';
|
|
5
|
+
static green = '\x1b[32m';
|
|
6
|
+
static yellow = '\x1b[33m';
|
|
7
|
+
static blue = '\x1b[34m';
|
|
8
|
+
static magenta = '\x1b[35m';
|
|
9
|
+
static cyan = '\x1b[36m';
|
|
10
|
+
static reset = '\x1b[0m';
|
|
11
|
+
static bold = '\x1b[1m';
|
|
12
|
+
static dim = '\x1b[2m';
|
|
13
|
+
static italic = '\x1b[3m';
|
|
14
|
+
static underline = '\x1b[4m';
|
|
15
|
+
static strikethrough = '\x1b[9m';
|
|
16
|
+
static bgRed = '\x1b[41m';
|
|
17
|
+
static bgGreen = '\x1b[42m';
|
|
18
|
+
static bgYellow = '\x1b[43m';
|
|
19
|
+
static bgBlue = '\x1b[44m';
|
|
20
|
+
static bgMagenta = '\x1b[45m';
|
|
21
|
+
static bgCyan = '\x1b[46m';
|
|
4
22
|
level = [INFO, WARN, ERROR, THROW, KILL];
|
|
5
23
|
systemTags = [];
|
|
6
24
|
c = console;
|
|
@@ -35,9 +53,19 @@ export class Logger {
|
|
|
35
53
|
static setSystemTags(tags) {
|
|
36
54
|
this.instance.setSystemTags(tags);
|
|
37
55
|
}
|
|
38
|
-
shout = (message, data) => Logger.info(
|
|
56
|
+
shout = (message, data) => Logger.info(Logger.green +
|
|
57
|
+
Logger.bold +
|
|
58
|
+
'--------------\n' +
|
|
59
|
+
message +
|
|
60
|
+
'\n--------------' +
|
|
61
|
+
Logger.reset, data);
|
|
39
62
|
static shout(message, data) {
|
|
40
|
-
this.info(
|
|
63
|
+
this.info(Logger.green +
|
|
64
|
+
Logger.bold +
|
|
65
|
+
'--------------\n' +
|
|
66
|
+
message +
|
|
67
|
+
'\n--------------' +
|
|
68
|
+
Logger.reset, data);
|
|
41
69
|
}
|
|
42
70
|
debug = (message, data) => Logger.debug(message, data);
|
|
43
71
|
static debug(message, data) {
|
|
@@ -53,33 +81,38 @@ export class Logger {
|
|
|
53
81
|
}
|
|
54
82
|
system = (tag, message, data) => Logger.info(message, data);
|
|
55
83
|
static system(tag, message, data) {
|
|
84
|
+
const formattedMessage = `${Logger.magenta}${message}${Logger.reset}`;
|
|
56
85
|
if (this.instance.level.includes(SYSTEM) && this.instance.systemTags.includes(tag))
|
|
57
|
-
this.instance.c.log(...(data ? [
|
|
86
|
+
this.instance.c.log(...(data ? [formattedMessage, data] : [formattedMessage]));
|
|
58
87
|
this.triggerListeners(message, data);
|
|
59
88
|
}
|
|
60
89
|
warn = (message, data) => Logger.warn(message, data);
|
|
61
90
|
static warn(message, data) {
|
|
91
|
+
const formattedMessage = `${Logger.yellow}WARN: ${message}${Logger.reset}`;
|
|
62
92
|
if (this.instance.level.includes(WARN))
|
|
63
|
-
this.instance.c.warn(...(data ? [
|
|
93
|
+
this.instance.c.warn(...(data ? [formattedMessage, data] : [formattedMessage]));
|
|
64
94
|
this.triggerListeners(message, data);
|
|
65
95
|
}
|
|
66
96
|
error = (message, data) => Logger.error(message, data);
|
|
67
97
|
static error(message, data) {
|
|
98
|
+
const formattedMessage = `${Logger.red}ERROR: ${message}${Logger.reset}`;
|
|
68
99
|
if (this.instance.level.includes(ERROR))
|
|
69
|
-
this.instance.c.error(...(data ? [
|
|
100
|
+
this.instance.c.error(...(data ? [formattedMessage, data] : [formattedMessage]));
|
|
70
101
|
this.triggerListeners(message, data);
|
|
71
102
|
}
|
|
72
103
|
throw = (message, data) => Logger.throw(message, data);
|
|
73
104
|
static throw(message, data) {
|
|
105
|
+
const formattedMessage = `${Logger.red}ERROR: ${message}${Logger.reset}`;
|
|
74
106
|
if (this.instance.level.includes(THROW))
|
|
75
|
-
this.instance.c.error(...(data ? [
|
|
107
|
+
this.instance.c.error(...(data ? [formattedMessage, data] : [formattedMessage]));
|
|
76
108
|
this.triggerListeners(message, data);
|
|
77
109
|
throw new Error(message.toString());
|
|
78
110
|
}
|
|
79
111
|
kill = (message, data) => Logger.kill(message, data);
|
|
80
112
|
static kill(message, data) {
|
|
113
|
+
const formattedMessage = `${Logger.red}ERROR: ${message}${Logger.reset}`;
|
|
81
114
|
if (this.instance.level.includes(KILL))
|
|
82
|
-
this.instance.c.error(...(data ? [
|
|
115
|
+
this.instance.c.error(...(data ? [formattedMessage, data] : [formattedMessage]));
|
|
83
116
|
this.triggerListeners(message, data);
|
|
84
117
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
85
118
|
// @ts-ignore
|