rslog 1.2.11 → 1.3.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/README.md +1 -1
- package/dist/index.cjs +17 -6
- package/dist/index.js +17 -6
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ Rslog provides both CommonJS and ESModule output and supports Node.js >= 14.
|
|
|
142
142
|
|
|
143
143
|
## Credits
|
|
144
144
|
|
|
145
|
-
Rslog is built with [
|
|
145
|
+
Rslog is built with [Rslib](https://github.com/web-infra-dev/rslib).
|
|
146
146
|
|
|
147
147
|
The color implementation of Rslog are modified from [alexeyraspopov/picocolors](https://github.com/alexeyraspopov/picocolors).
|
|
148
148
|
|
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
100
100
|
if ('truecolor' === env.COLORTERM) return 3;
|
|
101
101
|
if ('xterm-kitty' === env.TERM) return 3;
|
|
102
102
|
if ('xterm-ghostty' === env.TERM) return 3;
|
|
103
|
+
if ('wezterm' === env.TERM) return 3;
|
|
103
104
|
if ('TERM_PROGRAM' in env) {
|
|
104
105
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
105
106
|
switch(env.TERM_PROGRAM){
|
|
@@ -234,6 +235,14 @@ let LOG_TYPES = {
|
|
|
234
235
|
color: magenta
|
|
235
236
|
}
|
|
236
237
|
};
|
|
238
|
+
const normalizeErrorMessage = (err)=>{
|
|
239
|
+
if (err.stack) {
|
|
240
|
+
let [name, ...rest] = err.stack.split('\n');
|
|
241
|
+
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
242
|
+
return `${name}\n${gray(rest.join('\n'))}`;
|
|
243
|
+
}
|
|
244
|
+
return err.message;
|
|
245
|
+
};
|
|
237
246
|
let createLogger = (options = {})=>{
|
|
238
247
|
let maxLevel = options.level || 'info';
|
|
239
248
|
let log = (type, message, ...args)=>{
|
|
@@ -246,12 +255,14 @@ let createLogger = (options = {})=>{
|
|
|
246
255
|
label = (logType.label || '').padEnd(7);
|
|
247
256
|
label = bold(logType.color ? logType.color(label) : label);
|
|
248
257
|
}
|
|
249
|
-
if (message instanceof Error)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
258
|
+
if (message instanceof Error) {
|
|
259
|
+
text += normalizeErrorMessage(message);
|
|
260
|
+
const { cause } = message;
|
|
261
|
+
if (cause) {
|
|
262
|
+
text += yellow('\n [cause]: ');
|
|
263
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
264
|
+
}
|
|
265
|
+
} else if ('error' === logType.level && 'string' == typeof message) {
|
|
255
266
|
let lines = message.split('\n');
|
|
256
267
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
257
268
|
} else text = `${message}`;
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
71
71
|
if ('truecolor' === env.COLORTERM) return 3;
|
|
72
72
|
if ('xterm-kitty' === env.TERM) return 3;
|
|
73
73
|
if ('xterm-ghostty' === env.TERM) return 3;
|
|
74
|
+
if ('wezterm' === env.TERM) return 3;
|
|
74
75
|
if ('TERM_PROGRAM' in env) {
|
|
75
76
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
76
77
|
switch(env.TERM_PROGRAM){
|
|
@@ -205,6 +206,14 @@ let LOG_TYPES = {
|
|
|
205
206
|
color: magenta
|
|
206
207
|
}
|
|
207
208
|
};
|
|
209
|
+
const normalizeErrorMessage = (err)=>{
|
|
210
|
+
if (err.stack) {
|
|
211
|
+
let [name, ...rest] = err.stack.split('\n');
|
|
212
|
+
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
213
|
+
return `${name}\n${gray(rest.join('\n'))}`;
|
|
214
|
+
}
|
|
215
|
+
return err.message;
|
|
216
|
+
};
|
|
208
217
|
let createLogger = (options = {})=>{
|
|
209
218
|
let maxLevel = options.level || 'info';
|
|
210
219
|
let log = (type, message, ...args)=>{
|
|
@@ -217,12 +226,14 @@ let createLogger = (options = {})=>{
|
|
|
217
226
|
label = (logType.label || '').padEnd(7);
|
|
218
227
|
label = bold(logType.color ? logType.color(label) : label);
|
|
219
228
|
}
|
|
220
|
-
if (message instanceof Error)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
if (message instanceof Error) {
|
|
230
|
+
text += normalizeErrorMessage(message);
|
|
231
|
+
const { cause } = message;
|
|
232
|
+
if (cause) {
|
|
233
|
+
text += yellow('\n [cause]: ');
|
|
234
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
235
|
+
}
|
|
236
|
+
} else if ('error' === logType.level && 'string' == typeof message) {
|
|
226
237
|
let lines = message.split('\n');
|
|
227
238
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
228
239
|
} else text = `${message}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rslog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rspack-contrib/rslog.git"
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"bump": "npx bumpp",
|
|
25
25
|
"dev": "rslib build --watch",
|
|
26
26
|
"prepare": "rslib build",
|
|
27
|
-
"preview": "
|
|
27
|
+
"preview": "node ./preview/index.ts",
|
|
28
28
|
"test": "rstest"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rslib/core": "^0.
|
|
32
|
-
"@rstest/core": "^0.
|
|
33
|
-
"@types/node": "^22.
|
|
34
|
-
"prettier": "~3.
|
|
35
|
-
"strip-ansi": "^7.1.
|
|
36
|
-
"supports-color": "^10.
|
|
37
|
-
"typescript": "~5.
|
|
31
|
+
"@rslib/core": "^0.15.1",
|
|
32
|
+
"@rstest/core": "^0.5.2",
|
|
33
|
+
"@types/node": "^22.18.11",
|
|
34
|
+
"prettier": "~3.6.2",
|
|
35
|
+
"strip-ansi": "^7.1.2",
|
|
36
|
+
"supports-color": "^10.2.2",
|
|
37
|
+
"typescript": "~5.9.3"
|
|
38
38
|
},
|
|
39
|
-
"packageManager": "pnpm@10.
|
|
39
|
+
"packageManager": "pnpm@10.18.3",
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public",
|
|
42
42
|
"registry": "https://registry.npmjs.org/"
|