@anjianshi/utils 2.0.8 → 2.1.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/env-node/logging/handlers.js +5 -10
- package/logging/adapt.js +3 -0
- package/package.json +4 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import util from 'node:util';
|
|
4
5
|
import chalk from 'chalk';
|
|
5
6
|
import dayjs from 'dayjs';
|
|
6
7
|
import { LogLevel, LogHandler, formatters } from '../../logging/index.js';
|
|
@@ -96,17 +97,11 @@ export class FileHandler extends LogHandler {
|
|
|
96
97
|
this.pushBuffer(prefix, ...itemStrings, '\n');
|
|
97
98
|
}
|
|
98
99
|
stringifyDataItem(item) {
|
|
100
|
+
// 去掉颜色控制字符
|
|
99
101
|
if (typeof item === 'string')
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const json = JSON.stringify(item);
|
|
105
|
-
return json ?? String(json);
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
return String(item);
|
|
109
|
-
}
|
|
102
|
+
item = item.replace(/\x1b\[\d+m/g, '');
|
|
103
|
+
// 利用 util.format() 获得和 console.log() 相同的输出(因为 console.log() 底层也是用的 util.format())
|
|
104
|
+
return util.format(item);
|
|
110
105
|
}
|
|
111
106
|
// Handle buffer
|
|
112
107
|
buffer = [];
|
package/logging/adapt.js
CHANGED
|
@@ -34,6 +34,9 @@ export function adaptDebugLib(debugLib, enable = '', logger) {
|
|
|
34
34
|
logger = getLogger('3rd-library');
|
|
35
35
|
debugLib.log = logger.debug.bind(logger);
|
|
36
36
|
if (enable) {
|
|
37
|
+
// 有些库(例如 prisma)重新实现了自己的 debug 库,且模仿 debug 也读取 DEBUG 环境变量。
|
|
38
|
+
// 这里除了设置 debug 库,顺便也适配这些遵循 debug 库模式的自定义库。
|
|
39
|
+
process.env.DEBUG = enable;
|
|
37
40
|
debugLib.enable(enable);
|
|
38
41
|
}
|
|
39
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anjianshi/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Common JavaScript Utils",
|
|
5
5
|
"homepage": "https://github.com/anjianshi/js-packages/utils",
|
|
6
6
|
"bugs": {
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"typeorm": "^0.3.20",
|
|
27
27
|
"vconsole": "^3.15.1",
|
|
28
28
|
"typescript": "^5.4.4",
|
|
29
|
-
"@anjianshi/presets-eslint-typescript": "4.0.
|
|
30
|
-
"@anjianshi/presets-
|
|
29
|
+
"@anjianshi/presets-eslint-typescript": "4.0.4",
|
|
30
|
+
"@anjianshi/presets-eslint-node": "4.0.4",
|
|
31
31
|
"@anjianshi/presets-prettier": "3.0.0",
|
|
32
|
-
"@anjianshi/presets-
|
|
32
|
+
"@anjianshi/presets-typescript": "3.1.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"chalk": "^5.3.0",
|