rslog 1.2.11 → 1.3.1
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 +24 -11
- package/dist/index.js +22 -9
- 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
|
@@ -24,8 +24,8 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
createLogger: ()=>createLogger,
|
|
28
|
+
logger: ()=>src_logger
|
|
29
29
|
});
|
|
30
30
|
const external_node_process_namespaceObject = require("node:process");
|
|
31
31
|
const external_node_os_namespaceObject = require("node:os");
|
|
@@ -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,28 +235,40 @@ 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)=>{
|
|
240
|
-
if (LOG_LEVEL[LOG_TYPES[type].level] > LOG_LEVEL[maxLevel]) return;
|
|
241
|
-
if (null == message) return console.log();
|
|
242
249
|
let logType = LOG_TYPES[type];
|
|
250
|
+
const { level } = logType;
|
|
251
|
+
if (LOG_LEVEL[level] > LOG_LEVEL[maxLevel]) return;
|
|
252
|
+
if (null == message) return console.log();
|
|
243
253
|
let label = '';
|
|
244
254
|
let text = '';
|
|
245
255
|
if ('label' in logType) {
|
|
246
256
|
label = (logType.label || '').padEnd(7);
|
|
247
257
|
label = bold(logType.color ? logType.color(label) : label);
|
|
248
258
|
}
|
|
249
|
-
if (message instanceof Error)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
259
|
+
if (message instanceof Error) {
|
|
260
|
+
text += normalizeErrorMessage(message);
|
|
261
|
+
const { cause } = message;
|
|
262
|
+
if (cause) {
|
|
263
|
+
text += yellow('\n [cause]: ');
|
|
264
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
265
|
+
}
|
|
266
|
+
} else if ('error' === level && 'string' == typeof message) {
|
|
255
267
|
let lines = message.split('\n');
|
|
256
268
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
257
269
|
} else text = `${message}`;
|
|
258
|
-
|
|
270
|
+
const method = 'error' === level || 'warn' === level ? level : 'log';
|
|
271
|
+
console[method](label.length ? `${label} ${text}` : text, ...args);
|
|
259
272
|
};
|
|
260
273
|
let logger = {
|
|
261
274
|
greet: (message)=>log('log', gradient(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,28 +206,40 @@ 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)=>{
|
|
211
|
-
if (LOG_LEVEL[LOG_TYPES[type].level] > LOG_LEVEL[maxLevel]) return;
|
|
212
|
-
if (null == message) return console.log();
|
|
213
220
|
let logType = LOG_TYPES[type];
|
|
221
|
+
const { level } = logType;
|
|
222
|
+
if (LOG_LEVEL[level] > LOG_LEVEL[maxLevel]) return;
|
|
223
|
+
if (null == message) return console.log();
|
|
214
224
|
let label = '';
|
|
215
225
|
let text = '';
|
|
216
226
|
if ('label' in logType) {
|
|
217
227
|
label = (logType.label || '').padEnd(7);
|
|
218
228
|
label = bold(logType.color ? logType.color(label) : label);
|
|
219
229
|
}
|
|
220
|
-
if (message instanceof Error)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
if (message instanceof Error) {
|
|
231
|
+
text += normalizeErrorMessage(message);
|
|
232
|
+
const { cause } = message;
|
|
233
|
+
if (cause) {
|
|
234
|
+
text += yellow('\n [cause]: ');
|
|
235
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
236
|
+
}
|
|
237
|
+
} else if ('error' === level && 'string' == typeof message) {
|
|
226
238
|
let lines = message.split('\n');
|
|
227
239
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
228
240
|
} else text = `${message}`;
|
|
229
|
-
|
|
241
|
+
const method = 'error' === level || 'warn' === level ? level : 'log';
|
|
242
|
+
console[method](label.length ? `${label} ${text}` : text, ...args);
|
|
230
243
|
};
|
|
231
244
|
let logger = {
|
|
232
245
|
greet: (message)=>log('log', gradient(message))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rslog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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.1
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"prettier": "~3.
|
|
35
|
-
"strip-ansi": "^7.1.
|
|
36
|
-
"supports-color": "^10.
|
|
37
|
-
"typescript": "~5.
|
|
31
|
+
"@rslib/core": "^0.17.0",
|
|
32
|
+
"@rstest/core": "^0.6.1",
|
|
33
|
+
"@types/node": "^24.9.2",
|
|
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.20.0",
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public",
|
|
42
42
|
"registry": "https://registry.npmjs.org/"
|