@idlebox/logger 0.0.22 → 0.0.24
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/lib/common/ansi.d.ts +17 -13
- package/lib/common/ansi.d.ts.map +1 -1
- package/lib/common/ansi.js +5 -1
- package/lib/common/ansi.js.map +1 -1
- package/lib/common/create.compability.d.ts +5 -0
- package/lib/common/create.compability.d.ts.map +1 -0
- package/lib/common/create.compability.js +4 -0
- package/lib/common/create.compability.js.map +1 -0
- package/lib/common/create.function.d.ts +9 -5
- package/lib/common/create.function.d.ts.map +1 -1
- package/lib/common/create.function.js +51 -21
- package/lib/common/create.function.js.map +1 -1
- package/lib/common/create.logger.d.ts +3 -3
- package/lib/common/create.logger.d.ts.map +1 -1
- package/lib/common/create.logger.js +21 -20
- package/lib/common/create.logger.js.map +1 -1
- package/lib/common/helpers.d.ts +2 -6
- package/lib/common/helpers.d.ts.map +1 -1
- package/lib/common/helpers.js +4 -37
- package/lib/common/helpers.js.map +1 -1
- package/lib/common/logger.create.d.ts +8 -4
- package/lib/common/logger.create.d.ts.map +1 -1
- package/lib/common/logger.create.js +7 -14
- package/lib/common/logger.create.js.map +1 -1
- package/lib/common/logger.global.d.ts +4 -3
- package/lib/common/logger.global.d.ts.map +1 -1
- package/lib/common/logger.global.js +11 -17
- package/lib/common/logger.global.js.map +1 -1
- package/lib/common/registry.d.ts +8 -0
- package/lib/common/registry.d.ts.map +1 -0
- package/lib/common/registry.js +36 -0
- package/lib/common/registry.js.map +1 -0
- package/lib/common/types.d.ts +78 -22
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/types.js +2 -11
- package/lib/common/types.js.map +1 -1
- package/lib/environments/browser.d.ts +8 -0
- package/lib/environments/browser.d.ts.map +1 -0
- package/lib/environments/browser.js +21 -0
- package/lib/environments/browser.js.map +1 -0
- package/lib/environments/node.d.ts +12 -0
- package/lib/environments/node.d.ts.map +1 -0
- package/lib/environments/node.js +20 -0
- package/lib/environments/node.js.map +1 -0
- package/lib/environments/share.d.ts +13 -0
- package/lib/environments/share.d.ts.map +1 -0
- package/lib/environments/share.js +7 -0
- package/lib/environments/share.js.map +1 -0
- package/lib/{common/debug.commands.d.ts → functions/builtin-commands.d.ts} +2 -2
- package/lib/functions/builtin-commands.d.ts.map +1 -0
- package/lib/{common/debug.commands.js → functions/builtin-commands.js} +3 -10
- package/lib/functions/builtin-commands.js.map +1 -0
- package/lib/loglevels/control.browser.d.ts +2 -0
- package/lib/loglevels/control.browser.d.ts.map +1 -0
- package/lib/loglevels/control.browser.js +2 -0
- package/lib/loglevels/control.browser.js.map +1 -0
- package/lib/loglevels/control.nodejs.d.ts +2 -0
- package/lib/loglevels/control.nodejs.d.ts.map +1 -0
- package/lib/loglevels/control.nodejs.js +2 -0
- package/lib/loglevels/control.nodejs.js.map +1 -0
- package/lib/loglevels/loglevel.d.ts +12 -0
- package/lib/loglevels/loglevel.d.ts.map +1 -0
- package/lib/loglevels/loglevel.js +13 -0
- package/lib/loglevels/loglevel.js.map +1 -0
- package/lib/outputs/browser.d.ts +2 -0
- package/lib/outputs/browser.d.ts.map +1 -0
- package/lib/outputs/browser.js +23 -0
- package/lib/outputs/browser.js.map +1 -0
- package/lib/outputs/node-controllers/github-actions.d.ts +3 -0
- package/lib/outputs/node-controllers/github-actions.d.ts.map +1 -0
- package/lib/outputs/node-controllers/github-actions.js +15 -0
- package/lib/outputs/node-controllers/github-actions.js.map +1 -0
- package/lib/outputs/node-controllers/index.d.ts +3 -0
- package/lib/outputs/node-controllers/index.d.ts.map +1 -0
- package/lib/outputs/node-controllers/index.js +9 -0
- package/lib/outputs/node-controllers/index.js.map +1 -0
- package/lib/outputs/nodejs.d.ts +26 -0
- package/lib/outputs/nodejs.d.ts.map +1 -0
- package/lib/outputs/nodejs.js +82 -0
- package/lib/outputs/nodejs.js.map +1 -0
- package/lib/printers/file.d.ts +2 -1
- package/lib/printers/file.d.ts.map +1 -1
- package/lib/printers/file.js +2 -1
- package/lib/printers/file.js.map +1 -1
- package/package.json +13 -7
- package/src/common/ansi.ts +6 -1
- package/src/common/create.compability.ts +7 -0
- package/src/common/create.function.ts +59 -28
- package/src/common/create.logger.ts +22 -20
- package/src/common/helpers.ts +5 -46
- package/src/common/logger.create.ts +13 -15
- package/src/common/logger.global.ts +13 -18
- package/src/common/registry.ts +42 -0
- package/src/common/types.ts +100 -23
- package/src/environments/browser.ts +26 -0
- package/src/environments/node.ts +26 -0
- package/src/environments/share.ts +31 -0
- package/src/{common/debug.commands.ts → functions/builtin-commands.ts} +3 -13
- package/src/loglevels/control.browser.ts +0 -0
- package/src/loglevels/control.nodejs.ts +0 -0
- package/src/loglevels/loglevel.ts +12 -0
- package/src/outputs/browser.ts +27 -0
- package/src/outputs/node-controllers/github-actions.ts +18 -0
- package/src/outputs/node-controllers/index.ts +10 -0
- package/src/outputs/nodejs.ts +102 -0
- package/src/printers/file.ts +3 -2
- package/src/tsconfig.json +0 -1
- package/lib/common/debug.commands.d.ts.map +0 -1
- package/lib/common/debug.commands.js.map +0 -1
- package/lib/index.d.ts +0 -10
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -10
- package/lib/index.js.map +0 -1
- package/src/index.ts +0 -27
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Terminal } from '@idlebox/terminal-control';
|
|
2
|
+
import type { IInstrestedConsole } from '../common/types.js';
|
|
3
|
+
interface IOptions {
|
|
4
|
+
readonly stream: NodeJS.WritableStream;
|
|
5
|
+
readonly colorEnabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class NodejsOutput implements IInstrestedConsole {
|
|
8
|
+
static defaultInstance(): IInstrestedConsole;
|
|
9
|
+
readonly colorEnabled: boolean;
|
|
10
|
+
readonly stream: NodeJS.WritableStream;
|
|
11
|
+
readonly terminal: Terminal;
|
|
12
|
+
constructor({ stream, colorEnabled }: IOptions);
|
|
13
|
+
clear(): void;
|
|
14
|
+
group(message: string): void;
|
|
15
|
+
groupCollapsed(message: string): void;
|
|
16
|
+
groupEnd(): void;
|
|
17
|
+
readonly error: (message: string) => void;
|
|
18
|
+
readonly warn: (message: string) => void;
|
|
19
|
+
readonly info: (message: string) => void;
|
|
20
|
+
readonly log: (message: string) => void;
|
|
21
|
+
readonly debug: (message: string) => void;
|
|
22
|
+
readonly trace: (message: string) => void;
|
|
23
|
+
private _writeLine;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=nodejs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodejs.d.ts","sourceRoot":"","sources":["../../src/outputs/nodejs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAuC7D,UAAU,QAAQ;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CAChC;AAGD,qBAAa,YAAa,YAAW,kBAAkB;IACtD,MAAM,CAAC,eAAe,IAAI,kBAAkB;IAW5C,SAAgB,YAAY,UAAC;IAC7B,SAAgB,MAAM,wBAAC;IACvB,SAAgB,QAAQ,WAAC;gBACb,EAAE,MAAM,EAAE,YAAoB,EAAE,EAAE,QAAQ;IAatD,KAAK,IAAI,IAAI;IAIb,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIrC,QAAQ,IAAI,IAAI;IAIhB,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C,OAAO,CAAC,UAAU;CAGlB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Terminal } from '@idlebox/terminal-control';
|
|
2
|
+
import { applyControllerByEnvironment } from './node-controllers/index.js';
|
|
3
|
+
function environmentColorEnabled(stream) {
|
|
4
|
+
// biome-ignore lint/performance/useTopLevelRegex: one time use
|
|
5
|
+
const colorArgReg = /^--color=|^--color$|^-[^-]+c/;
|
|
6
|
+
const colorArg = process.argv.find((e) => colorArgReg.test(e));
|
|
7
|
+
const noColorArg = process.argv.includes('--no-color');
|
|
8
|
+
// 命令行顶级优先
|
|
9
|
+
if (noColorArg)
|
|
10
|
+
return false;
|
|
11
|
+
if (colorArg)
|
|
12
|
+
return true;
|
|
13
|
+
// 环境变量
|
|
14
|
+
if (process.env.NO_COLOR || process.env.NODE_DISABLE_COLORS === '1') {
|
|
15
|
+
/**
|
|
16
|
+
* https://force-color.org/
|
|
17
|
+
* https://nodejs.org/docs/latest/api/cli.html#node_disable_colors1
|
|
18
|
+
*/
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
else if (process.env.FORCE_COLOR) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
// 目标输出是TTY
|
|
25
|
+
if (stream.isTTY) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (process.env.GITHUB_ACTIONS) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
// TODO 检测其他可能
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
let instance;
|
|
35
|
+
export class NodejsOutput {
|
|
36
|
+
static defaultInstance() {
|
|
37
|
+
if (!instance) {
|
|
38
|
+
instance = new NodejsOutput({
|
|
39
|
+
stream: process.stderr,
|
|
40
|
+
colorEnabled: environmentColorEnabled(process.stderr),
|
|
41
|
+
});
|
|
42
|
+
applyControllerByEnvironment(instance);
|
|
43
|
+
}
|
|
44
|
+
return instance;
|
|
45
|
+
}
|
|
46
|
+
colorEnabled;
|
|
47
|
+
stream;
|
|
48
|
+
terminal;
|
|
49
|
+
constructor({ stream, colorEnabled = false }) {
|
|
50
|
+
this.colorEnabled = colorEnabled;
|
|
51
|
+
this.stream = stream;
|
|
52
|
+
this.terminal = new Terminal(this.stream);
|
|
53
|
+
this.error = this._writeLine.bind(this);
|
|
54
|
+
this.warn = this._writeLine.bind(this);
|
|
55
|
+
this.info = this._writeLine.bind(this);
|
|
56
|
+
this.log = this._writeLine.bind(this);
|
|
57
|
+
this.debug = this._writeLine.bind(this);
|
|
58
|
+
this.trace = this._writeLine.bind(this);
|
|
59
|
+
}
|
|
60
|
+
clear() {
|
|
61
|
+
this.terminal.resetIf(this.colorEnabled);
|
|
62
|
+
}
|
|
63
|
+
group(message) {
|
|
64
|
+
this.stream.write(`[${message}] START\n`);
|
|
65
|
+
}
|
|
66
|
+
groupCollapsed(message) {
|
|
67
|
+
this.stream.write(`[${message}] START (collapsed)\n`);
|
|
68
|
+
}
|
|
69
|
+
groupEnd() {
|
|
70
|
+
this.stream.write(`[GROUP] END\n`);
|
|
71
|
+
}
|
|
72
|
+
error;
|
|
73
|
+
warn;
|
|
74
|
+
info;
|
|
75
|
+
log;
|
|
76
|
+
debug;
|
|
77
|
+
trace;
|
|
78
|
+
_writeLine(message) {
|
|
79
|
+
this.stream.write(`${message}\n`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=nodejs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodejs.js","sourceRoot":"","sources":["../../src/outputs/nodejs.ts"],"names":[],"mappings":"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"}
|
package/lib/printers/file.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/printers/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/printers/file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAiB5D"}
|
package/lib/printers/file.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createWriteStream } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { Transform } from 'node:stream';
|
|
4
|
+
import { NodejsOutput } from '../outputs/nodejs.js';
|
|
4
5
|
export function createLogFile(filePath) {
|
|
5
6
|
const file = resolve(process.cwd(), filePath);
|
|
6
7
|
console.log(`Creating log file: ${file}`);
|
|
@@ -16,7 +17,7 @@ export function createLogFile(filePath) {
|
|
|
16
17
|
});
|
|
17
18
|
const filter = new ColorRemoveStream();
|
|
18
19
|
filter.pipe(target, { end: true });
|
|
19
|
-
return filter;
|
|
20
|
+
return new NodejsOutput({ stream: filter, colorEnabled: false });
|
|
20
21
|
}
|
|
21
22
|
class ColorRemoveStream extends Transform {
|
|
22
23
|
_transform(chunk, _encoding, callback) {
|
package/lib/printers/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/printers/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/printers/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5F,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,6BAA6B,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE;QACxB,OAAO,CAAC,KAAK,CAAC,YAAY,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,YAAY,IAAI,SAAS,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACvC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAEnC,OAAO,IAAI,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,iBAAkB,SAAQ,SAAS;IAC/B,UAAU,CAAC,KAAa,EAAE,SAAiB,EAAE,QAA2B;QAChF,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QAChE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlebox/logger",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.24",
|
|
5
5
|
"description": "A simple logger module for my self use (nodejs).",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"source": "./src/
|
|
9
|
-
"
|
|
8
|
+
"source": "./src/environments/node.ts",
|
|
9
|
+
"browser": "./lib/environments/browser.js",
|
|
10
|
+
"node": "./lib/environments/node.js",
|
|
11
|
+
"default": "./lib/environments/browser.js"
|
|
10
12
|
},
|
|
13
|
+
"./node": "./lib/environments/node.js",
|
|
14
|
+
"./browser": "./lib/environments/browser.js",
|
|
11
15
|
"./package.json": "./package.json"
|
|
12
16
|
},
|
|
13
17
|
"sideEffects": false,
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"debug": "^4.4.3",
|
|
16
|
-
"@idlebox/common": "^1.5.
|
|
20
|
+
"@idlebox/common": "^1.5.22",
|
|
21
|
+
"@idlebox/terminal-control": "^0.0.4"
|
|
17
22
|
},
|
|
18
23
|
"devDependencies": {
|
|
19
24
|
"@types/debug": "^4.1.13",
|
|
20
25
|
"@types/node": "^25.5.0",
|
|
21
|
-
"
|
|
22
|
-
"@mpis/run": "^0.0.
|
|
26
|
+
"mocha": "^11.7.5",
|
|
27
|
+
"@mpis/run": "^0.0.26",
|
|
28
|
+
"@build-script/baseline-rig": "latest"
|
|
23
29
|
},
|
|
24
30
|
"license": "MIT",
|
|
25
31
|
"author": "GongT <admin@gongt.me>",
|
|
@@ -28,7 +34,7 @@
|
|
|
28
34
|
"url": "git+https://github.com/GongT/baobao.git",
|
|
29
35
|
"directory": "@idlebox/logger"
|
|
30
36
|
},
|
|
31
|
-
"main": "./lib/
|
|
37
|
+
"main": "./lib/environments/browser.js",
|
|
32
38
|
"scripts": {
|
|
33
39
|
"build": "mpis-run build",
|
|
34
40
|
"watch": "mpis-run watch",
|
package/src/common/ansi.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { CSI } from '@idlebox/terminal-control/constants';
|
|
2
2
|
|
|
3
3
|
export const Crst = `${CSI}0m`;
|
|
4
4
|
|
|
@@ -17,3 +17,8 @@ export const CFgreen = `${CSI}38;5;10m`;
|
|
|
17
17
|
export const CFyellow = `${CSI}38;5;11m`;
|
|
18
18
|
export const CFblue = `${CSI}38;5;14m`;
|
|
19
19
|
export const CFred = `${CSI}38;5;9m`;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
export { CSI };
|
|
@@ -1,55 +1,86 @@
|
|
|
1
1
|
import { defineInspectMethod } from '@idlebox/common';
|
|
2
|
-
import
|
|
2
|
+
import { call_debug_command, debug_commands, nodeFormat } from '../functions/builtin-commands.js';
|
|
3
3
|
import { Cdim, Crst, CSI, NCdim } from './ansi.js';
|
|
4
4
|
import { LogLevel, logLevelPaddingStr, logTagColor } from './colors.js';
|
|
5
|
-
import { call_debug_command, debug_commands, nodeFormat } from './debug.commands.js';
|
|
6
5
|
import { current_error_action, escapeRegExp } from './helpers.js';
|
|
7
|
-
import type { IMyDebug, IMyDebugWithControl } from './types.js';
|
|
6
|
+
import type { ILineWriter, IMyDebug, IMyDebugWithControl, InspectContext } from './types.js';
|
|
8
7
|
|
|
9
8
|
interface IDebugOptions {
|
|
10
9
|
tag: string;
|
|
11
10
|
level: LogLevel;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
colorEnabled: boolean;
|
|
12
|
+
colorWholeLine?: boolean;
|
|
13
|
+
writer: ILineWriter;
|
|
15
14
|
enabled?: boolean;
|
|
16
15
|
}
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 创建一个debug函数
|
|
19
|
+
* 在浏览器中必须指定stream
|
|
20
|
+
*/
|
|
21
|
+
export function createDebug({ tag, level, colorEnabled, colorWholeLine = false, writer, enabled = true }: IDebugOptions): IMyDebugWithControl {
|
|
18
22
|
const color = logTagColor[level];
|
|
19
23
|
const lineOpt = {
|
|
20
24
|
tag: tag ? tag : `${LogLevel[level][0].toUpperCase()}`,
|
|
21
|
-
|
|
25
|
+
writer,
|
|
22
26
|
color,
|
|
23
27
|
level,
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
let write_line: IMyDebug;
|
|
27
|
-
if (!
|
|
31
|
+
if (!colorEnabled) {
|
|
28
32
|
write_line = write_line_monolithic({
|
|
29
33
|
...lineOpt,
|
|
30
34
|
tag: tag ? tag : `$$`,
|
|
31
35
|
});
|
|
32
|
-
} else if (
|
|
36
|
+
} else if (colorWholeLine) {
|
|
33
37
|
write_line = write_line_colored_line(lineOpt);
|
|
34
38
|
} else {
|
|
35
39
|
write_line = write_line_colored_tag(lineOpt);
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
// assert.equal(typeof writer, 'function', 'writer must be a function');
|
|
43
|
+
|
|
44
|
+
const r = Object.defineProperties(
|
|
39
45
|
(m: any, ...args: unknown[]) => {
|
|
40
|
-
if (!
|
|
46
|
+
if (!enabled) return;
|
|
41
47
|
write_line(m, ...args);
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
displayName: {
|
|
51
|
+
get() {
|
|
52
|
+
return `writeLine:${LogLevel[level]}|${enabled ? 'enabled' : 'disabled'}`;
|
|
53
|
+
},
|
|
54
|
+
configurable: false,
|
|
55
|
+
},
|
|
56
|
+
enable: {
|
|
57
|
+
value: function enable() {
|
|
58
|
+
enabled = true;
|
|
59
|
+
},
|
|
60
|
+
configurable: false,
|
|
61
|
+
writable: false,
|
|
62
|
+
},
|
|
63
|
+
disable: {
|
|
64
|
+
value: function disable() {
|
|
65
|
+
enabled = false;
|
|
66
|
+
},
|
|
67
|
+
configurable: false,
|
|
68
|
+
writable: false,
|
|
69
|
+
},
|
|
70
|
+
isEnabled: {
|
|
71
|
+
get() {
|
|
72
|
+
return enabled;
|
|
73
|
+
},
|
|
74
|
+
configurable: false,
|
|
46
75
|
},
|
|
47
|
-
|
|
48
|
-
|
|
76
|
+
writeLine: {
|
|
77
|
+
value: writer,
|
|
78
|
+
enumerable: false,
|
|
79
|
+
configurable: false,
|
|
80
|
+
writable: false,
|
|
49
81
|
},
|
|
50
|
-
isEnabled: enabled,
|
|
51
82
|
},
|
|
52
|
-
);
|
|
83
|
+
) as IMyDebugWithControl;
|
|
53
84
|
|
|
54
85
|
return defineInspectMethod(r, (_depth: number, context: InspectContext) => {
|
|
55
86
|
return `[${context.stylize('Debug', 'special')} "${context.stylize(tag, 'string')}" ${context.stylize(LogLevel[level], 'undefined')} ${context.stylize(r.isEnabled ? 'enabled' : 'disabled', 'boolean')}]`;
|
|
@@ -58,7 +89,7 @@ export function createDebug({ tag, level, color_enabled, color_entire_line = fal
|
|
|
58
89
|
|
|
59
90
|
interface IWriteLineOptions {
|
|
60
91
|
tag: string;
|
|
61
|
-
|
|
92
|
+
writer: ILineWriter;
|
|
62
93
|
color: string;
|
|
63
94
|
level: LogLevel;
|
|
64
95
|
}
|
|
@@ -118,7 +149,7 @@ function format_template(messages: TemplateStringsArray, args: unknown[], color:
|
|
|
118
149
|
/**
|
|
119
150
|
* TAG带颜色
|
|
120
151
|
*/
|
|
121
|
-
function write_line_colored_tag({ tag,
|
|
152
|
+
function write_line_colored_tag({ tag, writer, color }: IWriteLineOptions) {
|
|
122
153
|
return (messages: TemplateStringsArray | string, ...args: unknown[]) => {
|
|
123
154
|
const head = `[${CSI}${color}m${tag}${Crst}]`;
|
|
124
155
|
let body: string;
|
|
@@ -128,14 +159,14 @@ function write_line_colored_tag({ tag, stream, color }: IWriteLineOptions) {
|
|
|
128
159
|
body = format_template(messages, args, true);
|
|
129
160
|
}
|
|
130
161
|
|
|
131
|
-
write(
|
|
162
|
+
write(writer, head, body);
|
|
132
163
|
};
|
|
133
164
|
}
|
|
134
165
|
|
|
135
166
|
/**
|
|
136
167
|
* 整行带颜色
|
|
137
168
|
*/
|
|
138
|
-
function write_line_colored_line({ tag,
|
|
169
|
+
function write_line_colored_line({ tag, writer, color }: IWriteLineOptions) {
|
|
139
170
|
return (messages: TemplateStringsArray | string, ...args: unknown[]) => {
|
|
140
171
|
const head = `${CSI}${color}m[${tag}]`;
|
|
141
172
|
let body: string;
|
|
@@ -146,14 +177,14 @@ function write_line_colored_line({ tag, stream, color }: IWriteLineOptions) {
|
|
|
146
177
|
}
|
|
147
178
|
body += Crst;
|
|
148
179
|
|
|
149
|
-
write(
|
|
180
|
+
write(writer, head, body);
|
|
150
181
|
};
|
|
151
182
|
}
|
|
152
183
|
|
|
153
184
|
/**
|
|
154
185
|
* 不带颜色
|
|
155
186
|
*/
|
|
156
|
-
function write_line_monolithic({ tag, level,
|
|
187
|
+
function write_line_monolithic({ tag, level, writer }: IWriteLineOptions) {
|
|
157
188
|
const lvlStr = logLevelPaddingStr[level];
|
|
158
189
|
const head = `[${tag}/${lvlStr}]`;
|
|
159
190
|
|
|
@@ -166,14 +197,14 @@ function write_line_monolithic({ tag, level, stream }: IWriteLineOptions) {
|
|
|
166
197
|
body = format_template(messages, args, false);
|
|
167
198
|
}
|
|
168
199
|
|
|
169
|
-
write(
|
|
200
|
+
write(writer, head, body);
|
|
170
201
|
};
|
|
171
202
|
}
|
|
172
203
|
|
|
173
|
-
function write(
|
|
204
|
+
function write(writer: ILineWriter, head: string, body: string) {
|
|
174
205
|
if (body[0] === '[') {
|
|
175
|
-
|
|
206
|
+
writer(`${head}${body}`);
|
|
176
207
|
} else {
|
|
177
|
-
|
|
208
|
+
writer(`${head} ${body}`);
|
|
178
209
|
}
|
|
179
210
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { defineInspectMethod, SoftwareDefectError } from '@idlebox/common';
|
|
2
2
|
import type { InspectContext } from 'node:util';
|
|
3
|
+
import { EnableLogLevel } from '../loglevels/loglevel.js';
|
|
3
4
|
import { LogLevel } from './colors.js';
|
|
4
5
|
import { createDebug } from './create.function.js';
|
|
5
|
-
import { defaultLogLevel
|
|
6
|
-
import {
|
|
6
|
+
import { defaultLogLevel } from './helpers.js';
|
|
7
|
+
import { loggersRegistry, loggersRegistrySet } from './registry.js';
|
|
8
|
+
import type { IInstrestedConsole, IMyDebugWithControl, IMyLogger } from './types.js';
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export function create(console: IInstrestedConsole, tag: string, defaultLevel = EnableLogLevel.auto, color_enabled: boolean = true): IMyLogger {
|
|
11
|
+
const exists = loggersRegistry?.get(tag);
|
|
12
|
+
if (exists) return exists;
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
const colorEnabled = color_enabled && console.colorEnabled;
|
|
12
15
|
let currentLevel = defaultLevel;
|
|
13
|
-
seen_loggers.add(tag);
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
const log_fatal = createDebug({ tag, colorEnabled, level: LogLevel.fatal, writer: console.error, colorWholeLine: true });
|
|
16
18
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const debug = createDebug({ tag, color_enabled, level: LogLevel.debug, stream, color_entire_line: true });
|
|
25
|
-
const verbose = createDebug({ tag, color_enabled, level: LogLevel.verbose, stream, color_entire_line: true });
|
|
19
|
+
const error = createDebug({ tag, colorEnabled, level: LogLevel.error, writer: console.error });
|
|
20
|
+
const success = createDebug({ tag, colorEnabled, level: LogLevel.success, writer: console.log });
|
|
21
|
+
const warn = createDebug({ tag, colorEnabled, level: LogLevel.warn, writer: console.warn });
|
|
22
|
+
const info = createDebug({ tag, colorEnabled, level: LogLevel.info, writer: console.info });
|
|
23
|
+
const log = createDebug({ tag, colorEnabled, level: LogLevel.log, writer: console.log });
|
|
24
|
+
const debug = createDebug({ tag, colorEnabled, level: LogLevel.debug, writer: console.debug, colorWholeLine: true });
|
|
25
|
+
const verbose = createDebug({ tag, colorEnabled, level: LogLevel.verbose, writer: console.debug, colorWholeLine: true });
|
|
26
26
|
|
|
27
27
|
syncEnabled({ error, warn, info, log, success, debug, verbose }, tag, currentLevel);
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ export function create(tag: string, color_enabled: undefined | boolean, stream:
|
|
|
33
33
|
|
|
34
34
|
const result = {
|
|
35
35
|
tag,
|
|
36
|
-
|
|
36
|
+
console,
|
|
37
37
|
fatal,
|
|
38
38
|
error,
|
|
39
39
|
warn,
|
|
@@ -43,7 +43,7 @@ export function create(tag: string, color_enabled: undefined | boolean, stream:
|
|
|
43
43
|
debug,
|
|
44
44
|
verbose,
|
|
45
45
|
|
|
46
|
-
colorEnabled:
|
|
46
|
+
colorEnabled: colorEnabled,
|
|
47
47
|
|
|
48
48
|
enable(newLevel: EnableLogLevel) {
|
|
49
49
|
currentLevel = newLevel;
|
|
@@ -52,13 +52,15 @@ export function create(tag: string, color_enabled: undefined | boolean, stream:
|
|
|
52
52
|
|
|
53
53
|
extend: (newTag: string) => {
|
|
54
54
|
if (tag) {
|
|
55
|
-
return create(`${tag}:${newTag}`,
|
|
55
|
+
return create(console, `${tag}:${newTag}`, currentLevel, colorEnabled);
|
|
56
56
|
} else {
|
|
57
|
-
return create(
|
|
57
|
+
return create(console, newTag, currentLevel, colorEnabled);
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
loggersRegistrySet(result);
|
|
63
|
+
|
|
62
64
|
return defineInspectMethod(result, (_depth: number, context: InspectContext) => {
|
|
63
65
|
if (_depth < 0) return `${context.stylize(`[Logger ${tag}]`, 'special')}`;
|
|
64
66
|
return `${context.stylize('Logger', 'name')} { "${context.stylize(tag, 'string')}" ${context.stylize(EnableLogLevel[currentLevel], 'undefined')} }`;
|
package/src/common/helpers.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { prettyFormatError } from '@idlebox/common';
|
|
2
2
|
import debug from 'debug';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { debug_commands } from '../functions/builtin-commands.js';
|
|
4
|
+
import { EnableLogLevel } from '../loglevels/loglevel.js';
|
|
5
|
+
import { globalLogger } from './logger.global.js';
|
|
6
|
+
import type { IDebugCommand } from './types.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 判断 字符串是否为“真值”
|
|
@@ -24,52 +24,11 @@ export function is_string_truthy(value: string | undefined) {
|
|
|
24
24
|
} else if (value === '0' || value === 'false' || value === 'off' || value === 'no' || value === 'disabled') {
|
|
25
25
|
return false;
|
|
26
26
|
} else {
|
|
27
|
-
|
|
27
|
+
globalLogger.warn`invalid boolean string: ${value}, assuming false.`;
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
interface IWritableStream extends NodeJS.WritableStream {
|
|
33
|
-
colorEnabled?: boolean;
|
|
34
|
-
isTTY?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function _colorEnabled(stream: IWritableStream): boolean {
|
|
38
|
-
const colorArg = process.argv.find((e) => e.startsWith('--color=') || e === '--color' || e === '-c');
|
|
39
|
-
const noColorArg = process.argv.includes('--no-color');
|
|
40
|
-
|
|
41
|
-
// 命令行顶级优先
|
|
42
|
-
if (colorArg) return true;
|
|
43
|
-
if (noColorArg) return false;
|
|
44
|
-
|
|
45
|
-
// 环境变量
|
|
46
|
-
if (process.env.NO_COLOR || process.env.NODE_DISABLE_COLORS === '1') {
|
|
47
|
-
/**
|
|
48
|
-
* https://force-color.org/
|
|
49
|
-
* https://nodejs.org/docs/latest/api/cli.html#node_disable_colors1
|
|
50
|
-
*/
|
|
51
|
-
return false;
|
|
52
|
-
} else if (process.env.FORCE_COLOR) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 检测其他可能
|
|
57
|
-
if (stream.isTTY) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// TODO
|
|
62
|
-
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function detectColorEnable(stream: IWritableStream = process.stderr): boolean {
|
|
67
|
-
if (stream.colorEnabled === undefined) {
|
|
68
|
-
stream.colorEnabled = _colorEnabled(stream);
|
|
69
|
-
}
|
|
70
|
-
return stream.colorEnabled;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
32
|
export function escapeRegExp(str: string) {
|
|
74
33
|
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
75
34
|
}
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PassThrough } from 'node:stream';
|
|
1
|
+
import { EnableLogLevel } from '../loglevels/loglevel.js';
|
|
3
2
|
import { create } from './create.logger.js';
|
|
4
3
|
import { debug_enabled, defaultLogLevel } from './helpers.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { globalLogger } from './logger.global.js';
|
|
5
|
+
import type { IInstrestedConsole, IMyLogger } from './types.js';
|
|
6
|
+
|
|
7
|
+
export interface ILoggerOptionsReq {
|
|
8
|
+
readonly colors?: boolean;
|
|
9
|
+
readonly console: IInstrestedConsole;
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* 创建一个新的logger实例
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
14
|
+
* @param tag logger的tag,类似 "app:db:insert"
|
|
15
|
+
* @param colors 是否启用颜色,默认启用
|
|
12
16
|
* @returns
|
|
13
17
|
*/
|
|
14
|
-
export function
|
|
15
|
-
const stream = new PassThrough();
|
|
16
|
-
if (pipeTo) {
|
|
17
|
-
Object.assign(stream, { isTTY: (pipeTo as any).isTTY });
|
|
18
|
-
stream.pipe(pipeTo);
|
|
19
|
-
}
|
|
20
|
-
|
|
18
|
+
export function createLoggerObject(tag: string, { colors = true, console }: ILoggerOptionsReq): IMyLogger {
|
|
21
19
|
let level = EnableLogLevel.error;
|
|
22
20
|
if (debug_enabled(tag)) {
|
|
23
21
|
level = defaultLogLevel;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
const logger = create(
|
|
24
|
+
const logger = create(console, tag, level, colors);
|
|
27
25
|
|
|
28
|
-
(
|
|
26
|
+
(globalLogger || logger).verbose`logger "${tag}" created, level = ${EnableLogLevel[level]}`;
|
|
29
27
|
|
|
30
28
|
return logger;
|
|
31
29
|
}
|
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
import { globalObject } from '@idlebox/common';
|
|
2
|
-
import
|
|
3
|
-
import { PassThrough } from 'node:stream';
|
|
2
|
+
import type { EnableLogLevel } from '../loglevels/loglevel.js';
|
|
4
3
|
import { create } from './create.logger.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const stream = new PassThrough();
|
|
8
|
-
stream.pipe(process.stderr);
|
|
9
|
-
Object.assign(stream, { isTTY: process.stderr.isTTY });
|
|
4
|
+
import type { IInstrestedConsole, IMyLogger } from './types.js';
|
|
10
5
|
|
|
11
6
|
const symbol = Symbol.for('@idlebox/logger/global/terminal');
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
* 作为logger导出,必须在程序入口调用过 createGlobalLogger() 才能使用
|
|
15
10
|
*/
|
|
16
|
-
export let
|
|
11
|
+
export let globalLogger: IMyLogger;
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
14
|
* 创建root-logger,随后logger变量可用
|
|
20
15
|
*/
|
|
21
|
-
export function createGlobalLogger(tag: string, defaultLevel: EnableLogLevel
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
16
|
+
export function createGlobalLogger(console: IInstrestedConsole, tag: string, defaultLevel: EnableLogLevel): void {
|
|
17
|
+
globalLogger = globalObject[symbol];
|
|
18
|
+
if (globalLogger) {
|
|
19
|
+
globalLogger.error`global logger already created`;
|
|
25
20
|
return;
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
globalObject[symbol] =
|
|
23
|
+
globalLogger = create(console, tag);
|
|
24
|
+
globalObject[symbol] = globalLogger;
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
globalLogger.enable(defaultLevel);
|
|
32
27
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
28
|
+
if (globalLogger.verbose.isEnabled) {
|
|
29
|
+
globalLogger.verbose`verbose is enabled`;
|
|
35
30
|
} else {
|
|
36
|
-
|
|
31
|
+
globalLogger.debug`debug is enabled`;
|
|
37
32
|
}
|
|
38
33
|
return;
|
|
39
34
|
}
|