@wsurface/debug 2.0.0 → 2.0.2
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/package.json +3 -10
- package/src/cjs/index.cjs +1 -0
- package/src/cjs/modules/logger.cjs +28 -5
- package/src/esm/index.mjs +1 -0
- package/src/esm/modules/logger.mjs +28 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsurface/debug",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A simple and powerful logger for your project.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,25 +14,18 @@
|
|
|
14
14
|
"logger",
|
|
15
15
|
"nodejs",
|
|
16
16
|
"shell",
|
|
17
|
-
"console",
|
|
18
17
|
"terminal",
|
|
19
18
|
"cli",
|
|
20
19
|
"string",
|
|
21
20
|
"text"
|
|
22
21
|
],
|
|
23
22
|
"type": "module",
|
|
24
|
-
"main": "./src/
|
|
23
|
+
"main": "./src/cjs/index.cjs",
|
|
25
24
|
"exports": {
|
|
26
25
|
"import": "./src/esm/index.mjs",
|
|
27
26
|
"require": "./src/cjs/index.cjs"
|
|
28
27
|
},
|
|
29
|
-
"
|
|
30
|
-
"files": [
|
|
31
|
-
"src",
|
|
32
|
-
"package.json",
|
|
33
|
-
"README.md",
|
|
34
|
-
"LICENSE.txt"
|
|
35
|
-
],
|
|
28
|
+
"files": ["src", "package.json", "README.md", "LICENSE.txt"],
|
|
36
29
|
"author": "nuneswip",
|
|
37
30
|
"license": "CC-BY-ND-4.0",
|
|
38
31
|
"dependencies": {
|
package/src/cjs/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ const DEFAULT_THEME = {
|
|
|
16
16
|
conn: "blue"
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const DEFAULT_ICONS = {
|
|
20
20
|
info: "ℹ",
|
|
21
21
|
warn: "⚠",
|
|
22
22
|
error: "✖",
|
|
@@ -32,6 +32,7 @@ class Logger {
|
|
|
32
32
|
icons: true,
|
|
33
33
|
tag: true,
|
|
34
34
|
theme: DEFAULT_THEME,
|
|
35
|
+
iconSet: DEFAULT_ICONS,
|
|
35
36
|
...options
|
|
36
37
|
};
|
|
37
38
|
|
|
@@ -67,13 +68,25 @@ class Logger {
|
|
|
67
68
|
if (!start) return;
|
|
68
69
|
|
|
69
70
|
const duration = Date.now() - start;
|
|
70
|
-
|
|
71
71
|
this.info(`⏱ ${label}: ${duration}ms`);
|
|
72
72
|
this.timers.delete(label);
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
getIcon(level, options) {
|
|
78
|
+
if (!options.icons) return "";
|
|
79
|
+
|
|
80
|
+
const iconSet = {
|
|
81
|
+
...DEFAULT_ICONS,
|
|
82
|
+
...options.iconSet
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const icon = iconSet[level];
|
|
86
|
+
|
|
87
|
+
return icon ? icon + " " : "";
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
createMode(options) {
|
|
78
91
|
const mode = {};
|
|
79
92
|
|
|
@@ -90,7 +103,8 @@ class Logger {
|
|
|
90
103
|
|
|
91
104
|
this.levels.forEach(level => {
|
|
92
105
|
box[level] = msg => {
|
|
93
|
-
const
|
|
106
|
+
const icon = this.getIcon(level, this.options);
|
|
107
|
+
const text = ` ${icon}${msg} `;
|
|
94
108
|
const line = "─".repeat(text.length);
|
|
95
109
|
|
|
96
110
|
console.log(`┌${line}┐`);
|
|
@@ -126,7 +140,16 @@ class Logger {
|
|
|
126
140
|
}
|
|
127
141
|
|
|
128
142
|
setOptions(options) {
|
|
129
|
-
this.options = {
|
|
143
|
+
this.options = {
|
|
144
|
+
...this.options,
|
|
145
|
+
...options,
|
|
146
|
+
iconSet: options.iconSet
|
|
147
|
+
? {
|
|
148
|
+
...this.options.iconSet,
|
|
149
|
+
...options.iconSet
|
|
150
|
+
}
|
|
151
|
+
: this.options.iconSet
|
|
152
|
+
};
|
|
130
153
|
}
|
|
131
154
|
|
|
132
155
|
formatTimestamp(enabled) {
|
|
@@ -151,7 +174,7 @@ class Logger {
|
|
|
151
174
|
|
|
152
175
|
const color = c[theme[level]] || c.white;
|
|
153
176
|
|
|
154
|
-
const icon =
|
|
177
|
+
const icon = this.getIcon(level, merged);
|
|
155
178
|
|
|
156
179
|
const timestamp = this.formatTimestamp(merged.timestamp);
|
|
157
180
|
|
package/src/esm/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const DEFAULT_THEME = {
|
|
|
11
11
|
conn: "blue"
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const DEFAULT_ICONS = {
|
|
15
15
|
info: "ℹ",
|
|
16
16
|
warn: "⚠",
|
|
17
17
|
error: "✖",
|
|
@@ -27,6 +27,7 @@ class Logger {
|
|
|
27
27
|
icons: true,
|
|
28
28
|
tag: true,
|
|
29
29
|
theme: DEFAULT_THEME,
|
|
30
|
+
iconSet: DEFAULT_ICONS,
|
|
30
31
|
...options
|
|
31
32
|
};
|
|
32
33
|
|
|
@@ -41,7 +42,6 @@ class Logger {
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
this.box = this.createBox();
|
|
44
|
-
|
|
45
45
|
this.json = this.createJSON();
|
|
46
46
|
|
|
47
47
|
this.group = {
|
|
@@ -70,6 +70,19 @@ class Logger {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
getIcon(level, options) {
|
|
74
|
+
if (!options.icons) return "";
|
|
75
|
+
|
|
76
|
+
const iconSet = {
|
|
77
|
+
...DEFAULT_ICONS,
|
|
78
|
+
...options.iconSet
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const icon = iconSet[level];
|
|
82
|
+
|
|
83
|
+
return icon ? icon + " " : "";
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
createMode(options) {
|
|
74
87
|
const mode = {};
|
|
75
88
|
this.levels.forEach(level => {
|
|
@@ -84,7 +97,8 @@ class Logger {
|
|
|
84
97
|
|
|
85
98
|
this.levels.forEach(level => {
|
|
86
99
|
box[level] = msg => {
|
|
87
|
-
const
|
|
100
|
+
const icon = this.getIcon(level, this.options);
|
|
101
|
+
const text = ` ${icon}${msg} `;
|
|
88
102
|
const line = "─".repeat(text.length);
|
|
89
103
|
|
|
90
104
|
console.log(`┌${line}┐`);
|
|
@@ -120,7 +134,16 @@ class Logger {
|
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
setOptions(options) {
|
|
123
|
-
this.options = {
|
|
137
|
+
this.options = {
|
|
138
|
+
...this.options,
|
|
139
|
+
...options,
|
|
140
|
+
iconSet: options.iconSet
|
|
141
|
+
? {
|
|
142
|
+
...this.options.iconSet,
|
|
143
|
+
...options.iconSet
|
|
144
|
+
}
|
|
145
|
+
: this.options.iconSet
|
|
146
|
+
};
|
|
124
147
|
}
|
|
125
148
|
|
|
126
149
|
formatTimestamp(enabled) {
|
|
@@ -143,7 +166,7 @@ class Logger {
|
|
|
143
166
|
|
|
144
167
|
const color = chalk[theme[level]] || chalk.white;
|
|
145
168
|
|
|
146
|
-
const icon =
|
|
169
|
+
const icon = this.getIcon(level, merged);
|
|
147
170
|
|
|
148
171
|
const timestamp = this.formatTimestamp(merged.timestamp);
|
|
149
172
|
|