@idlebox/logger 0.0.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/LICENSE +21 -0
- package/config/rig.json +5 -0
- package/lib/common/colors.d.ts +13 -0
- package/lib/common/colors.d.ts.map +1 -0
- package/lib/common/colors.js +33 -0
- package/lib/common/colors.js.map +1 -0
- package/lib/common/create.d.ts +4 -0
- package/lib/common/create.d.ts.map +1 -0
- package/lib/common/create.js +93 -0
- package/lib/common/create.js.map +1 -0
- package/lib/common/debug-fn.d.ts +13 -0
- package/lib/common/debug-fn.d.ts.map +1 -0
- package/lib/common/debug-fn.js +141 -0
- package/lib/common/debug-fn.js.map +1 -0
- package/lib/common/debug.commands.d.ts +13 -0
- package/lib/common/debug.commands.d.ts.map +1 -0
- package/lib/common/debug.commands.js +129 -0
- package/lib/common/debug.commands.js.map +1 -0
- package/lib/common/helpers.d.ts +56 -0
- package/lib/common/helpers.d.ts.map +1 -0
- package/lib/common/helpers.js +173 -0
- package/lib/common/helpers.js.map +1 -0
- package/lib/common/logger.create.d.ts +9 -0
- package/lib/common/logger.create.d.ts.map +1 -0
- package/lib/common/logger.create.js +27 -0
- package/lib/common/logger.create.js.map +1 -0
- package/lib/common/logger.global.d.ts +10 -0
- package/lib/common/logger.global.d.ts.map +1 -0
- package/lib/common/logger.global.js +28 -0
- package/lib/common/logger.global.js.map +1 -0
- package/lib/common/printer.d.ts +2 -0
- package/lib/common/printer.d.ts.map +1 -0
- package/lib/common/printer.js +2 -0
- package/lib/common/printer.js.map +1 -0
- package/lib/common/types.d.ts +32 -0
- package/lib/common/types.d.ts.map +1 -0
- package/lib/common/types.js +12 -0
- package/lib/common/types.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -0
- package/lib/printers/file.d.ts +2 -0
- package/lib/printers/file.d.ts.map +1 -0
- package/lib/printers/file.js +27 -0
- package/lib/printers/file.js.map +1 -0
- package/lib/test/01-simple.test.d.ts +2 -0
- package/lib/test/01-simple.test.d.ts.map +1 -0
- package/lib/test/01-simple.test.js +33 -0
- package/lib/test/01-simple.test.js.map +1 -0
- package/lib/test/02-debug.test.d.ts +2 -0
- package/lib/test/02-debug.test.d.ts.map +1 -0
- package/lib/test/02-debug.test.js +9 -0
- package/lib/test/02-debug.test.js.map +1 -0
- package/lib/test/03-file.test.d.ts +2 -0
- package/lib/test/03-file.test.d.ts.map +1 -0
- package/lib/test/03-file.test.js +34 -0
- package/lib/test/03-file.test.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +35 -0
- package/src/common/colors.ts +33 -0
- package/src/common/create.ts +116 -0
- package/src/common/debug-fn.ts +171 -0
- package/src/common/debug.commands.ts +132 -0
- package/src/common/helpers.ts +184 -0
- package/src/common/logger.create.ts +35 -0
- package/src/common/logger.global.ts +31 -0
- package/src/common/printer.ts +0 -0
- package/src/common/types.ts +39 -0
- package/src/index.ts +23 -0
- package/src/printers/file.ts +29 -0
- package/src/test/01-simple.test.ts +44 -0
- package/src/test/02-debug.test.ts +11 -0
- package/src/test/03-file.test.ts +46 -0
- package/src/tsconfig.json +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 GongT<admin@gongt.me>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/config/rig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
fatal = 0,
|
|
3
|
+
error = 1,
|
|
4
|
+
success = 2,
|
|
5
|
+
warn = 3,
|
|
6
|
+
info = 4,
|
|
7
|
+
log = 5,
|
|
8
|
+
debug = 6,
|
|
9
|
+
verbose = 7
|
|
10
|
+
}
|
|
11
|
+
export declare const logTagColor: Record<LogLevel, string>;
|
|
12
|
+
export declare const logLevelPaddingStr: Record<LogLevel, string>;
|
|
13
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/common/colors.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IACnB,KAAK,IAAI;IACT,KAAK,IAAI;IACT,OAAO,IAAI;IACX,IAAI,IAAI;IACR,IAAI,IAAI;IACR,GAAG,IAAI;IAEP,KAAK,IAAI;IACT,OAAO,IAAI;CACX;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAShD,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CASvD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export var LogLevel;
|
|
2
|
+
(function (LogLevel) {
|
|
3
|
+
LogLevel[LogLevel["fatal"] = 0] = "fatal";
|
|
4
|
+
LogLevel[LogLevel["error"] = 1] = "error";
|
|
5
|
+
LogLevel[LogLevel["success"] = 2] = "success";
|
|
6
|
+
LogLevel[LogLevel["warn"] = 3] = "warn";
|
|
7
|
+
LogLevel[LogLevel["info"] = 4] = "info";
|
|
8
|
+
LogLevel[LogLevel["log"] = 5] = "log";
|
|
9
|
+
//
|
|
10
|
+
LogLevel[LogLevel["debug"] = 6] = "debug";
|
|
11
|
+
LogLevel[LogLevel["verbose"] = 7] = "verbose";
|
|
12
|
+
})(LogLevel || (LogLevel = {}));
|
|
13
|
+
export const logTagColor = {
|
|
14
|
+
[LogLevel.fatal]: '38;5;9;1',
|
|
15
|
+
[LogLevel.error]: '38;5;9',
|
|
16
|
+
[LogLevel.warn]: '38;5;11',
|
|
17
|
+
[LogLevel.log]: '0',
|
|
18
|
+
[LogLevel.info]: '38;5;14',
|
|
19
|
+
[LogLevel.success]: '38;5;10',
|
|
20
|
+
[LogLevel.debug]: '38;5;243',
|
|
21
|
+
[LogLevel.verbose]: '38;5;234',
|
|
22
|
+
};
|
|
23
|
+
export const logLevelPaddingStr = {
|
|
24
|
+
[LogLevel.fatal]: 'fatal ',
|
|
25
|
+
[LogLevel.error]: 'error ',
|
|
26
|
+
[LogLevel.success]: 'success',
|
|
27
|
+
[LogLevel.warn]: 'warn ',
|
|
28
|
+
[LogLevel.info]: 'info ',
|
|
29
|
+
[LogLevel.log]: 'log ',
|
|
30
|
+
[LogLevel.debug]: 'debug ',
|
|
31
|
+
[LogLevel.verbose]: 'verbose',
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/common/colors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,QAU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ReadonlySet<string>;
|
|
3
|
+
export declare function create(tag: string, color_enabled: undefined | boolean, stream: NodeJS.ReadWriteStream, defaultLevel?: EnableLogLevel): IMyLogger;
|
|
4
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/common/create.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAA4B,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGtF,eAAO,IAAI,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAgB,CAAC;AAEhE,wBAAgB,MAAM,CACrB,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,SAAS,GAAG,OAAO,EAClC,MAAM,EAAE,MAAM,CAAC,eAAe,EAC9B,YAAY,iBAAsB,GAChC,SAAS,CAgDX"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { shutdown } from '@idlebox/node';
|
|
2
|
+
import { LogLevel } from './colors.js';
|
|
3
|
+
import { createDebug } from './debug-fn.js';
|
|
4
|
+
import { defaultLogLevel, detectColorEnable } from './helpers.js';
|
|
5
|
+
import { EnableLogLevel } from './types.js';
|
|
6
|
+
const seen_loggers = new Set();
|
|
7
|
+
export let all_logger_names = seen_loggers;
|
|
8
|
+
export function create(tag, color_enabled, stream, defaultLevel = EnableLogLevel.auto) {
|
|
9
|
+
let currentLevel = defaultLevel;
|
|
10
|
+
seen_loggers.add(tag);
|
|
11
|
+
if (color_enabled === undefined)
|
|
12
|
+
color_enabled = detectColorEnable(stream);
|
|
13
|
+
const log_fatal = createDebug({ tag, color_enabled, level: LogLevel.fatal, stream, color_entire_line: true });
|
|
14
|
+
const error = createDebug({ tag, color_enabled, level: LogLevel.error, stream });
|
|
15
|
+
const success = createDebug({ tag, color_enabled, level: LogLevel.success, stream });
|
|
16
|
+
const warn = createDebug({ tag, color_enabled, level: LogLevel.warn, stream });
|
|
17
|
+
const info = createDebug({ tag, color_enabled, level: LogLevel.info, stream });
|
|
18
|
+
const log = createDebug({ tag, color_enabled, level: LogLevel.log, stream });
|
|
19
|
+
const debug = createDebug({ tag, color_enabled, level: LogLevel.debug, stream, color_entire_line: true });
|
|
20
|
+
const verbose = createDebug({ tag, color_enabled, level: LogLevel.verbose, stream, color_entire_line: true });
|
|
21
|
+
syncEnabled({ error, warn, info, log, success, debug, verbose }, tag, currentLevel);
|
|
22
|
+
return {
|
|
23
|
+
tag,
|
|
24
|
+
stream,
|
|
25
|
+
fatal: (messages, ...args) => {
|
|
26
|
+
log_fatal(messages, ...args);
|
|
27
|
+
shutdown(1);
|
|
28
|
+
},
|
|
29
|
+
error,
|
|
30
|
+
warn,
|
|
31
|
+
info,
|
|
32
|
+
log,
|
|
33
|
+
success,
|
|
34
|
+
debug,
|
|
35
|
+
verbose,
|
|
36
|
+
colorEnabled: color_enabled,
|
|
37
|
+
enable(newMaxLevel) {
|
|
38
|
+
currentLevel = newMaxLevel;
|
|
39
|
+
syncEnabled({ error, warn, info, log, success, debug, verbose }, tag, currentLevel);
|
|
40
|
+
},
|
|
41
|
+
extend: (newTag) => {
|
|
42
|
+
if (tag) {
|
|
43
|
+
return create(`${tag}:${newTag}`, color_enabled, stream, currentLevel);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return create(newTag, color_enabled, stream, currentLevel);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function syncEnabled(opt, tag, currentLevel) {
|
|
52
|
+
if (currentLevel === EnableLogLevel.auto) {
|
|
53
|
+
/**
|
|
54
|
+
* 如果自动探测,如何认定一个log启用
|
|
55
|
+
* - fatal永远启用
|
|
56
|
+
* - tag为空时,认为DEBUG中存在tag
|
|
57
|
+
* - 如果DEBUG中存在-tag:$level,则禁用 tag:$level 单个级别
|
|
58
|
+
* - 如果DEBUG中存在tag
|
|
59
|
+
* - 如果有DEBUG_LEVEL,则启用 >=DEBUG_LEVEL 级别
|
|
60
|
+
* - 否则启用 >log 级别
|
|
61
|
+
* 否则启用 >warn 级别
|
|
62
|
+
* - 如果DEBUG中存在tag:$level,则启用 tag:$level 单个级别
|
|
63
|
+
*
|
|
64
|
+
* TODO !!
|
|
65
|
+
*/
|
|
66
|
+
+tag;
|
|
67
|
+
currentLevel = defaultLogLevel;
|
|
68
|
+
}
|
|
69
|
+
// 手动控制(root-logger默认是手动控制)
|
|
70
|
+
for (const i of [opt.error, opt.warn, opt.info, opt.log, opt.success, opt.debug, opt.verbose]) {
|
|
71
|
+
i.enable();
|
|
72
|
+
}
|
|
73
|
+
if (currentLevel < EnableLogLevel.error) {
|
|
74
|
+
opt.error.disable();
|
|
75
|
+
opt.success.disable();
|
|
76
|
+
}
|
|
77
|
+
if (currentLevel < EnableLogLevel.warn) {
|
|
78
|
+
opt.warn.disable();
|
|
79
|
+
}
|
|
80
|
+
if (currentLevel < EnableLogLevel.info) {
|
|
81
|
+
opt.info.disable();
|
|
82
|
+
}
|
|
83
|
+
if (currentLevel < EnableLogLevel.log) {
|
|
84
|
+
opt.log.disable();
|
|
85
|
+
}
|
|
86
|
+
if (currentLevel < EnableLogLevel.debug) {
|
|
87
|
+
opt.debug.disable();
|
|
88
|
+
}
|
|
89
|
+
if (currentLevel < EnableLogLevel.verbose) {
|
|
90
|
+
opt.verbose.disable();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/common/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,cAAc,EAA4C,MAAM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
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LogLevel } from './colors.js';
|
|
2
|
+
import type { IMyDebugWithControl } from './types.js';
|
|
3
|
+
interface IDebugOptions {
|
|
4
|
+
tag: string;
|
|
5
|
+
level: LogLevel;
|
|
6
|
+
color_enabled: boolean;
|
|
7
|
+
color_entire_line?: boolean;
|
|
8
|
+
stream?: NodeJS.WritableStream;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function createDebug({ tag, level, color_enabled, color_entire_line, stream, enabled, }: IDebugOptions): IMyDebugWithControl;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=debug-fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-fn.d.ts","sourceRoot":"","sources":["../../src/common/debug-fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmC,MAAM,aAAa,CAAC;AAExE,OAAO,KAAK,EAAY,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhE,UAAU,aAAa;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AACD,wBAAgB,WAAW,CAAC,EAC3B,GAAG,EACH,KAAK,EACL,aAAa,EACb,iBAAyB,EACzB,MAAuB,EACvB,OAAc,GACd,EAAE,aAAa,GAAG,mBAAmB,CAmCrC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { LogLevel, logLevelPaddingStr, logTagColor } from './colors.js';
|
|
2
|
+
import { call_debug_command, nodeFormat } from './debug.commands.js';
|
|
3
|
+
export function createDebug({ tag, level, color_enabled, color_entire_line = false, stream = process.stdout, enabled = true, }) {
|
|
4
|
+
const color = logTagColor[level];
|
|
5
|
+
const lineOpt = {
|
|
6
|
+
tag: tag ? tag : `${LogLevel[level]}`,
|
|
7
|
+
stream,
|
|
8
|
+
color,
|
|
9
|
+
level,
|
|
10
|
+
};
|
|
11
|
+
let write_line;
|
|
12
|
+
if (!color_enabled) {
|
|
13
|
+
write_line = write_line_monolithic(lineOpt);
|
|
14
|
+
}
|
|
15
|
+
else if (color_entire_line) {
|
|
16
|
+
write_line = write_line_colored_line(lineOpt);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
write_line = write_line_colored_tag(lineOpt);
|
|
20
|
+
}
|
|
21
|
+
const r = Object.assign((m, ...args) => {
|
|
22
|
+
if (!r.isEnabled)
|
|
23
|
+
return;
|
|
24
|
+
write_line(m, ...args);
|
|
25
|
+
}, {
|
|
26
|
+
enable: () => {
|
|
27
|
+
r.isEnabled = true;
|
|
28
|
+
},
|
|
29
|
+
disable: () => {
|
|
30
|
+
r.isEnabled = false;
|
|
31
|
+
},
|
|
32
|
+
isEnabled: enabled,
|
|
33
|
+
});
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
function format_template(messages, args, color) {
|
|
37
|
+
const result_messages = messages.slice();
|
|
38
|
+
const result_args = [];
|
|
39
|
+
for (const [index, arg] of args.entries()) {
|
|
40
|
+
const prefix = result_messages[index] || '';
|
|
41
|
+
const postfix = result_messages[index + 1] || '';
|
|
42
|
+
if (prefix.endsWith('<') && postfix.startsWith('>')) {
|
|
43
|
+
const command = prefix.slice(prefix.lastIndexOf(' ') + 1, -1);
|
|
44
|
+
const result = call_debug_command(command, arg, color);
|
|
45
|
+
result_messages[index] = prefix.slice(0, prefix.lastIndexOf(' ') + 1);
|
|
46
|
+
if (result_messages[index + 1]) {
|
|
47
|
+
result_messages[index + 1] = postfix.slice(1);
|
|
48
|
+
}
|
|
49
|
+
result_args.push(result);
|
|
50
|
+
}
|
|
51
|
+
else if (typeof arg === 'string') {
|
|
52
|
+
result_args.push(call_debug_command('stripe', arg, color));
|
|
53
|
+
}
|
|
54
|
+
else if (typeof arg === 'number' ||
|
|
55
|
+
typeof arg === 'boolean' ||
|
|
56
|
+
typeof arg === 'bigint' ||
|
|
57
|
+
typeof arg === 'symbol') {
|
|
58
|
+
result_args.push(arg.toString());
|
|
59
|
+
}
|
|
60
|
+
else if (arg === null || arg === undefined) {
|
|
61
|
+
if (color) {
|
|
62
|
+
result_args.push(`\x1B[2m${arg}\x1B[22m`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result_args.push(String(arg));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
result_args.push(call_debug_command('inspect', arg, color));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let ret = '';
|
|
73
|
+
while (result_messages.length || result_args.length) {
|
|
74
|
+
const message = result_messages.shift();
|
|
75
|
+
if (message)
|
|
76
|
+
ret += message;
|
|
77
|
+
const arg = result_args.shift();
|
|
78
|
+
if (arg)
|
|
79
|
+
ret += arg;
|
|
80
|
+
}
|
|
81
|
+
return ret;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* TAG带颜色
|
|
85
|
+
*/
|
|
86
|
+
function write_line_colored_tag({ tag, stream, color }) {
|
|
87
|
+
return (messages, ...args) => {
|
|
88
|
+
const head = `[\x1b[${color}m${tag}\x1b[0m]`;
|
|
89
|
+
let body;
|
|
90
|
+
if (typeof messages === 'string') {
|
|
91
|
+
body = nodeFormat(messages, args, true);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
body = format_template(messages, args, true);
|
|
95
|
+
}
|
|
96
|
+
write(stream, head, body);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 整行带颜色
|
|
101
|
+
*/
|
|
102
|
+
function write_line_colored_line({ tag, stream, color }) {
|
|
103
|
+
return (messages, ...args) => {
|
|
104
|
+
const head = `\x1B[${color}m[${tag}]`;
|
|
105
|
+
let body;
|
|
106
|
+
if (typeof messages === 'string') {
|
|
107
|
+
body = nodeFormat(messages, args, false);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
body = format_template(messages, args, false);
|
|
111
|
+
}
|
|
112
|
+
body += '\x1B[0m';
|
|
113
|
+
write(stream, head, body);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 不带颜色
|
|
118
|
+
*/
|
|
119
|
+
function write_line_monolithic({ tag, level, stream }) {
|
|
120
|
+
const lvlStr = logLevelPaddingStr[level];
|
|
121
|
+
return (messages, ...args) => {
|
|
122
|
+
const head = `[${tag}:${lvlStr}]`;
|
|
123
|
+
let body;
|
|
124
|
+
if (typeof messages === 'string') {
|
|
125
|
+
body = nodeFormat(messages, args, false);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
body = format_template(messages, args, false);
|
|
129
|
+
}
|
|
130
|
+
write(stream, head, body);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function write(stream, head, body) {
|
|
134
|
+
if (body[0] === '[') {
|
|
135
|
+
stream.write(`${head}${body}\n`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
stream.write(`${head} ${body}\n`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=debug-fn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-fn.js","sourceRoot":"","sources":["../../src/common/debug-fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAWrE,MAAM,UAAU,WAAW,CAAC,EAC3B,GAAG,EACH,KAAK,EACL,aAAa,EACb,iBAAiB,GAAG,KAAK,EACzB,MAAM,GAAG,OAAO,CAAC,MAAM,EACvB,OAAO,GAAG,IAAI,GACC;IACf,MAAM,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,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACrB,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACP,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;IACnC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function nodeFormat(message: string, object: readonly unknown[], color: boolean): string;
|
|
2
|
+
export declare function nodeInspect(object: unknown, color: boolean): string;
|
|
3
|
+
declare const debug_commands: {
|
|
4
|
+
inspect(object: unknown, color: boolean): string;
|
|
5
|
+
stripe(s: unknown, color: boolean): string;
|
|
6
|
+
list(items: unknown, color: boolean): string;
|
|
7
|
+
commandline(cmds: unknown, color: boolean): string;
|
|
8
|
+
long(s: unknown, color: boolean): unknown;
|
|
9
|
+
relative(s: unknown, color: boolean): string;
|
|
10
|
+
};
|
|
11
|
+
export declare function call_debug_command(command: keyof typeof debug_commands | string, arg: unknown, color: boolean): string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=debug.commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.commands.d.ts","sourceRoot":"","sources":["../../src/common/debug.commands.ts"],"names":[],"mappings":"AAuBA,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAE9F;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnE;AAMD,QAAA,MAAM,cAAc;oBACH,OAAO,SAAS,OAAO;cAG7B,OAAO,SAAS,OAAO;gBAcrB,OAAO,SAAS,OAAO;sBAgCjB,OAAO,SAAS,OAAO;YAajC,OAAO,SAAS,OAAO;gBAcnB,OAAO,SAAS,OAAO;CAMnC,CAAC;AAGF,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,OAAO,cAAc,GAAG,MAAM,EAC7C,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,OAAO,GACZ,MAAM,CAMR"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { relative } from 'node:path';
|
|
2
|
+
import { formatWithOptions, inspect } from 'node:util';
|
|
3
|
+
const STRING_MAX_LENGTH = 128;
|
|
4
|
+
function color_error(message, color) {
|
|
5
|
+
if (color) {
|
|
6
|
+
return `\x1B[38;5;9m<inspect**${message}**>\x1B[39m`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return `<inspect**${message}**>`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function options(color) {
|
|
13
|
+
return {
|
|
14
|
+
depth: 5,
|
|
15
|
+
compact: true,
|
|
16
|
+
colors: color,
|
|
17
|
+
maxArrayLength: 3,
|
|
18
|
+
maxStringLength: STRING_MAX_LENGTH,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function nodeFormat(message, object, color) {
|
|
22
|
+
return formatWithOptions(options(color), message, ...object);
|
|
23
|
+
}
|
|
24
|
+
export function nodeInspect(object, color) {
|
|
25
|
+
return inspect(object, options(color));
|
|
26
|
+
}
|
|
27
|
+
function isSyncIterable(obj) {
|
|
28
|
+
return typeof obj === 'object' && obj !== null && Symbol.iterator in obj;
|
|
29
|
+
}
|
|
30
|
+
const debug_commands = {
|
|
31
|
+
inspect(object, color) {
|
|
32
|
+
return inspect(object, options(color));
|
|
33
|
+
},
|
|
34
|
+
stripe(s, color) {
|
|
35
|
+
if (typeof s !== 'string') {
|
|
36
|
+
return color_error(`can not stripe ${typeof s}`, color);
|
|
37
|
+
}
|
|
38
|
+
if (s.length > 100) {
|
|
39
|
+
if (color) {
|
|
40
|
+
return `\x1B[38;5;10m"${s.slice(0, STRING_MAX_LENGTH - 3)}..."\x1B[39m`;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return `"${s.slice(0, STRING_MAX_LENGTH - 3)}..."`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return s;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
list(items, color) {
|
|
51
|
+
if (!isSyncIterable(items)) {
|
|
52
|
+
return color_error(`list<> need iterable value, not ${typeof items}(${items?.constructor?.name})`, color);
|
|
53
|
+
}
|
|
54
|
+
const postfix = color ? '\x1B[0m' : '';
|
|
55
|
+
let index = 0;
|
|
56
|
+
const lines = [];
|
|
57
|
+
const prefix = color ? '\x1B[2m' : '';
|
|
58
|
+
for (const item of items) {
|
|
59
|
+
if (Array.isArray(item)) {
|
|
60
|
+
if (item.length === 2) {
|
|
61
|
+
const [key, value] = item;
|
|
62
|
+
if (typeof key === 'number') {
|
|
63
|
+
lines.push(` - ${prefix}${item}${postfix}`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
lines.push(` * ${prefix}${key}: ${value.toString()}${postfix}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return color_error(`list<> item ${index} is array with length ${item.length}, expected 2`, color);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
lines.push(` - ${prefix}${item}${postfix}`);
|
|
75
|
+
}
|
|
76
|
+
index++;
|
|
77
|
+
}
|
|
78
|
+
if (lines.length === 0) {
|
|
79
|
+
const prefix = color ? '\x1B[3;2m' : '';
|
|
80
|
+
return ':\n' + prefix + ' - <list is empty>' + postfix;
|
|
81
|
+
}
|
|
82
|
+
return ':\n' + lines.join('\n');
|
|
83
|
+
},
|
|
84
|
+
commandline(cmds, color) {
|
|
85
|
+
if (Array.isArray(cmds)) {
|
|
86
|
+
const prefix = color ? '\x1B[2m' : '';
|
|
87
|
+
const postfix = color ? '\x1B[0m' : '';
|
|
88
|
+
return prefix + cmds.map((s) => JSON.stringify(s)).join(' ') + postfix;
|
|
89
|
+
}
|
|
90
|
+
else if (typeof cmds === 'string') {
|
|
91
|
+
const prefix = color ? '\x1B[2;3m' : '';
|
|
92
|
+
const postfix = color ? '\x1B[0m' : '';
|
|
93
|
+
return prefix + cmds + postfix;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return color_error(`commandline<> need string or array, not ${typeof cmds}`, color);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
long(s, color) {
|
|
100
|
+
if (typeof s !== 'string') {
|
|
101
|
+
if (Array.isArray(s)) {
|
|
102
|
+
s = `[${s.join(', ')}]`;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return color_error(`long<> need string, not ${typeof s}(${s?.constructor?.name})`, color);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (color) {
|
|
109
|
+
return `\x1B[3m${s}\x1B[23m`;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return s;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
relative(s, color) {
|
|
116
|
+
if (typeof s !== 'string') {
|
|
117
|
+
return color_error(`relative<> need string, not ${typeof s}(${s?.constructor?.name})`, color);
|
|
118
|
+
}
|
|
119
|
+
return relative(process.cwd(), s);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
export function call_debug_command(command, arg, color) {
|
|
123
|
+
const fn = debug_commands[command];
|
|
124
|
+
if (!fn) {
|
|
125
|
+
return color_error(`unknown command ${command}`, color);
|
|
126
|
+
}
|
|
127
|
+
return fn(arg, color);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=debug.commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.commands.js","sourceRoot":"","sources":["../../src/common/debug.commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,C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CAAC,mBAAmB,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnableLogLevel } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 判断 字符串是否为“真值”
|
|
4
|
+
* * 1 / 0
|
|
5
|
+
* * true / false
|
|
6
|
+
* * on / off
|
|
7
|
+
* * yes / no
|
|
8
|
+
* * enabled / disabled
|
|
9
|
+
*
|
|
10
|
+
* 其他内容会导致一个警告,并返回 false
|
|
11
|
+
*/
|
|
12
|
+
export declare function is_string_truthy(value: string | undefined): boolean;
|
|
13
|
+
interface IWritableStream extends NodeJS.WritableStream {
|
|
14
|
+
colorEnabled?: boolean;
|
|
15
|
+
isTTY?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function detectColorEnable(stream?: IWritableStream): boolean;
|
|
18
|
+
export declare function escapeRegExp(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param tag tag to match, e.g. "app:db:insert"
|
|
22
|
+
* @returns a RegExp, eg. /(^|\s)(\\*|app:\\*|app:db:\\*|app:db:insert)($|\s)/
|
|
23
|
+
*/
|
|
24
|
+
export declare function compile_match_regex(tag: string, invert?: boolean): RegExp;
|
|
25
|
+
/**
|
|
26
|
+
* 从字符串中匹配指定的tag是否启用,不完全模拟 debug 模块的功能,不处理反义匹配(需用match_disabled)
|
|
27
|
+
* @param tag 类似 "app:db:insert" 的tag
|
|
28
|
+
* @param env 环境变量内容,默认 process.env.DEBUG
|
|
29
|
+
* @returns 冒号数量
|
|
30
|
+
*/
|
|
31
|
+
export declare function match_enabled(tag: string, env?: string): number;
|
|
32
|
+
/**
|
|
33
|
+
* 从字符串中匹配指定的tag是否禁用,不完全模拟 debug 模块的功能,tag前面不要加-
|
|
34
|
+
* @param tag 类似 "app:db:insert" 的tag
|
|
35
|
+
* @param env 环境变量内容,默认 process.env.DEBUG
|
|
36
|
+
* @returns 冒号数量 - 1
|
|
37
|
+
*/
|
|
38
|
+
export declare function match_disabled(tag: string, env?: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* 调用debug模块的debug.enabled方法
|
|
41
|
+
*/
|
|
42
|
+
export declare function debug_enabled(tag: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 当指定tag开启时,应该输出它的什么级别
|
|
45
|
+
* tag关闭时始终默认error
|
|
46
|
+
*
|
|
47
|
+
* 只有新创建的受此影响,且不影响root-logger,也不影响.extend
|
|
48
|
+
*/
|
|
49
|
+
export declare let defaultLogLevel: EnableLogLevel;
|
|
50
|
+
/**
|
|
51
|
+
* 手动设置默认日志级别
|
|
52
|
+
* root-logger 和 已经创建的 不受此影响
|
|
53
|
+
*/
|
|
54
|
+
export declare function set_default_log_level(level: EnableLogLevel): void;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/common/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,WAYzD;AAED,UAAU,eAAgB,SAAQ,MAAM,CAAC,cAAc;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AA+BD,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,eAAgC,GAAG,OAAO,CAKnF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,UAEvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAavE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAA0B,GAAG,MAAM,CAKhF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAA0B,GAAG,MAAM,CAKjF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,WAExC;AAED;;;;;GAKG;AACH,eAAO,IAAI,eAAe,gBA0CtB,CAAC;AAEL;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,QAE1D"}
|