@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { terminal } from './logger.global.js';
|
|
4
|
+
import { EnableLogLevel } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* 判断 字符串是否为“真值”
|
|
7
|
+
* * 1 / 0
|
|
8
|
+
* * true / false
|
|
9
|
+
* * on / off
|
|
10
|
+
* * yes / no
|
|
11
|
+
* * enabled / disabled
|
|
12
|
+
*
|
|
13
|
+
* 其他内容会导致一个警告,并返回 false
|
|
14
|
+
*/
|
|
15
|
+
export function is_string_truthy(value) {
|
|
16
|
+
if (!value)
|
|
17
|
+
return false;
|
|
18
|
+
value = value.toLowerCase();
|
|
19
|
+
if (value === '1' || value === 'true' || value === 'on' || value === 'yes' || value === 'enabled') {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
else if (value === '0' || value === 'false' || value === 'off' || value === 'no' || value === 'disabled') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
terminal.warn `invalid boolean string: ${value}, assuming false.`;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function _colorEnabled(stream) {
|
|
31
|
+
const colorArg = process.argv.find((e) => e.startsWith('--color=') || e === '--color' || e === '-c');
|
|
32
|
+
const noColorArg = process.argv.includes('--no-color');
|
|
33
|
+
// 命令行顶级优先
|
|
34
|
+
if (colorArg)
|
|
35
|
+
return true;
|
|
36
|
+
if (noColorArg)
|
|
37
|
+
return false;
|
|
38
|
+
// 环境变量
|
|
39
|
+
if (process.env.NO_COLOR || process.env.NODE_DISABLE_COLORS === '1') {
|
|
40
|
+
/**
|
|
41
|
+
* https://force-color.org/
|
|
42
|
+
* https://nodejs.org/docs/latest/api/cli.html#node_disable_colors1
|
|
43
|
+
*/
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
else if (process.env.FORCE_COLOR) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
// 检测其他可能
|
|
50
|
+
if (stream.isTTY) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
// TODO
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
export function detectColorEnable(stream = process.stderr) {
|
|
57
|
+
if (stream.colorEnabled === undefined) {
|
|
58
|
+
stream.colorEnabled = _colorEnabled(stream);
|
|
59
|
+
}
|
|
60
|
+
return stream.colorEnabled;
|
|
61
|
+
}
|
|
62
|
+
export function escapeRegExp(str) {
|
|
63
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param tag tag to match, e.g. "app:db:insert"
|
|
68
|
+
* @returns a RegExp, eg. /(^|\s)(\\*|app:\\*|app:db:\\*|app:db:insert)($|\s)/
|
|
69
|
+
*/
|
|
70
|
+
export function compile_match_regex(tag, invert = false) {
|
|
71
|
+
const parts = tag.split(':');
|
|
72
|
+
parts.pop();
|
|
73
|
+
let regs = ['\\*'];
|
|
74
|
+
let comb = [];
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
comb.push(part);
|
|
77
|
+
regs.push(`${escapeRegExp(comb.join(':'))}:\\*`);
|
|
78
|
+
}
|
|
79
|
+
regs.push(escapeRegExp(tag));
|
|
80
|
+
return new RegExp(`(?:^|,)(${invert ? '-' : ''})(${regs.join('|')})(?:$|,)`, 'i');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 从字符串中匹配指定的tag是否启用,不完全模拟 debug 模块的功能,不处理反义匹配(需用match_disabled)
|
|
84
|
+
* @param tag 类似 "app:db:insert" 的tag
|
|
85
|
+
* @param env 环境变量内容,默认 process.env.DEBUG
|
|
86
|
+
* @returns 冒号数量
|
|
87
|
+
*/
|
|
88
|
+
export function match_enabled(tag, env = process.env.DEBUG || '') {
|
|
89
|
+
const tagReg = compile_match_regex(tag);
|
|
90
|
+
const m = tagReg.exec(env);
|
|
91
|
+
if (!m)
|
|
92
|
+
return 0;
|
|
93
|
+
return m[0].split(':').length;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 从字符串中匹配指定的tag是否禁用,不完全模拟 debug 模块的功能,tag前面不要加-
|
|
97
|
+
* @param tag 类似 "app:db:insert" 的tag
|
|
98
|
+
* @param env 环境变量内容,默认 process.env.DEBUG
|
|
99
|
+
* @returns 冒号数量 - 1
|
|
100
|
+
*/
|
|
101
|
+
export function match_disabled(tag, env = process.env.DEBUG || '') {
|
|
102
|
+
const tagReg = compile_match_regex(tag, true);
|
|
103
|
+
const m = tagReg.exec(env);
|
|
104
|
+
if (!m)
|
|
105
|
+
return -1;
|
|
106
|
+
return m[0].split(':').length - 1;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 调用debug模块的debug.enabled方法
|
|
110
|
+
*/
|
|
111
|
+
export function debug_enabled(tag) {
|
|
112
|
+
return debug(tag).enabled;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 当指定tag开启时,应该输出它的什么级别
|
|
116
|
+
* tag关闭时始终默认error
|
|
117
|
+
*
|
|
118
|
+
* 只有新创建的受此影响,且不影响root-logger,也不影响.extend
|
|
119
|
+
*/
|
|
120
|
+
export let defaultLogLevel = (() => {
|
|
121
|
+
if (process.argv.includes('--verbose')) {
|
|
122
|
+
// 参数中含有 --verbose 时,设置默认日志级别
|
|
123
|
+
return EnableLogLevel.verbose;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// 参数中含有 --debug 或 -d 时,设置默认日志级别
|
|
127
|
+
const dbgCnt = process.argv.filter((e) => e === '--debug' || e === '-d').length;
|
|
128
|
+
if (dbgCnt > 1) {
|
|
129
|
+
return EnableLogLevel.verbose;
|
|
130
|
+
}
|
|
131
|
+
else if (dbgCnt === 1) {
|
|
132
|
+
return EnableLogLevel.debug;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// DEBUG=xxx,verbose,xxx
|
|
136
|
+
// biome-ignore lint/performance/useTopLevelRegex:
|
|
137
|
+
const has_debug_verbose = /(?<=^|,)(verbose|debug)(?=$|,)/;
|
|
138
|
+
const setted = has_debug_verbose.exec(process.env.DEBUG || '');
|
|
139
|
+
if (setted) {
|
|
140
|
+
if (setted[0] === 'verbose') {
|
|
141
|
+
return EnableLogLevel.verbose;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return EnableLogLevel.debug;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// 直接通过 DEBUG_LEVEL 设置
|
|
149
|
+
switch (process.env.DEBUG_LEVEL || '') {
|
|
150
|
+
case '':
|
|
151
|
+
return EnableLogLevel.log;
|
|
152
|
+
case 'verbose':
|
|
153
|
+
return EnableLogLevel.verbose;
|
|
154
|
+
case 'debug':
|
|
155
|
+
return EnableLogLevel.debug;
|
|
156
|
+
case 'info':
|
|
157
|
+
return EnableLogLevel.info;
|
|
158
|
+
case 'warn':
|
|
159
|
+
return EnableLogLevel.warn;
|
|
160
|
+
default:
|
|
161
|
+
console.error('Invalid DEBUG_LEVEL: %s, using verbose.', process.env.DEBUG_LEVEL);
|
|
162
|
+
return EnableLogLevel.verbose;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})();
|
|
166
|
+
/**
|
|
167
|
+
* 手动设置默认日志级别
|
|
168
|
+
* root-logger 和 已经创建的 不受此影响
|
|
169
|
+
*/
|
|
170
|
+
export function set_default_log_level(level) {
|
|
171
|
+
defaultLogLevel = level;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/common/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAyB;IACzD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAEzB,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAC5B,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACnG,OAAO,IAAI,CAAC;IACb,CAAC;SAAM,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KA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AC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC/D,IAAI,MAAM,EAAE,CAAC;QACZ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,cAAc,CAAC,OAAO,CAAC;QAC/B,CAAC;aAAM,CAAC;YACP,OAAO,cAAc,CAAC,KAAK,CAAC;QAC7B,CAAC;IACF,CAAC;SAAM,CAAC;QACP,sBAAsB;QACtB,QAAQ,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;YACvC,KAAK,EAAE;gBACN,OAAO,cAAc,CAAC,GAAG,CAAC;YAC3B,KAAK,SAAS;gBACb,OAAO,cAAc,CAAC,OAAO,CAAC;YAC/B,KAAK,OAAO;gBACX,OAAO,cAAc,CAAC,KAAK,CAAC;YAC7B,KAAK,MAAM;gBACV,OAAO,cAAc,CAAC,IAAI,CAAC;YAC5B,KAAK,MAAM;gBACV,OAAO,cAAc,CAAC,IAAI,CAAC;YAC5B;gBACC,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAClF,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,CAAC;IACF,CAAC;AACF,CAAC,CAAC,EAAE,CAAC;AAEL;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAqB;IAC1D,eAAe,GAAG,KAAK,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IMyLogger } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个新的logger实例
|
|
4
|
+
* @param color_enabled 默认自动
|
|
5
|
+
* @param pipeTo 默认是 process.stderr
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLogger(tag: string, color_enabled?: boolean | undefined, pipeTo?: undefined | NodeJS.WritableStream): IMyLogger;
|
|
9
|
+
//# sourceMappingURL=logger.create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.create.d.ts","sourceRoot":"","sources":["../../src/common/logger.create.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,MAAM,EACX,aAAa,GAAE,OAAO,GAAG,SAAqB,EAC9C,MAAM,GAAE,SAAS,GAAG,MAAM,CAAC,cAA+B,GACxD,SAAS,CAiBX"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import { create } from './create.js';
|
|
4
|
+
import { debug_enabled, defaultLogLevel } from './helpers.js';
|
|
5
|
+
import { terminal } from './logger.global.js';
|
|
6
|
+
import { EnableLogLevel } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* 创建一个新的logger实例
|
|
9
|
+
* @param color_enabled 默认自动
|
|
10
|
+
* @param pipeTo 默认是 process.stderr
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export function createLogger(tag, color_enabled = undefined, pipeTo = process.stderr) {
|
|
14
|
+
const stream = new PassThrough();
|
|
15
|
+
if (pipeTo) {
|
|
16
|
+
Object.assign(stream, { isTTY: pipeTo.isTTY });
|
|
17
|
+
stream.pipe(pipeTo);
|
|
18
|
+
}
|
|
19
|
+
let level = EnableLogLevel.error;
|
|
20
|
+
if (debug_enabled(tag)) {
|
|
21
|
+
level = defaultLogLevel;
|
|
22
|
+
}
|
|
23
|
+
const logger = create(tag, color_enabled, stream, level);
|
|
24
|
+
(terminal || logger).verbose `logger "${tag}" created, level = ${EnableLogLevel[level]}`;
|
|
25
|
+
return logger;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=logger.create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.create.js","sourceRoot":"","sources":["../../src/common/logger.create.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC3B,GAAW,EACX,gBAAqC,SAAS,EAC9C,SAA4C,OAAO,CAAC,MAAM;IAE1D,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IACjC,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAG,MAAc,CAAC,KAAK,EAAE,CAAC,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC;IACjC,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,GAAG,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAEzD,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,OAAO,CAAA,WAAW,GAAG,sBAAsB,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IAExF,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EnableLogLevel, type IMyLogger } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 作为logger导出,必须在程序入口调用过 createGlobalLogger() 才能使用
|
|
4
|
+
*/
|
|
5
|
+
export declare let terminal: IMyLogger;
|
|
6
|
+
/**
|
|
7
|
+
* 创建root-logger,随后logger变量可用
|
|
8
|
+
*/
|
|
9
|
+
export declare function createGlobalLogger(tag: string, defaultLevel?: EnableLogLevel): void;
|
|
10
|
+
//# sourceMappingURL=logger.global.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.global.d.ts","sourceRoot":"","sources":["../../src/common/logger.global.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAM5D;;GAEG;AACH,eAAO,IAAI,QAAQ,EAAE,SAAS,CAAC;AAE/B;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,cAAoC,GAAG,IAAI,CAaxG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import { create } from './create.js';
|
|
4
|
+
import { EnableLogLevel } from './types.js';
|
|
5
|
+
const stream = new PassThrough();
|
|
6
|
+
stream.pipe(process.stderr);
|
|
7
|
+
Object.assign(stream, { isTTY: process.stderr.isTTY });
|
|
8
|
+
/**
|
|
9
|
+
* 作为logger导出,必须在程序入口调用过 createGlobalLogger() 才能使用
|
|
10
|
+
*/
|
|
11
|
+
export let terminal;
|
|
12
|
+
/**
|
|
13
|
+
* 创建root-logger,随后logger变量可用
|
|
14
|
+
*/
|
|
15
|
+
export function createGlobalLogger(tag, defaultLevel = EnableLogLevel.auto) {
|
|
16
|
+
if (terminal)
|
|
17
|
+
throw new Error('global logger already created');
|
|
18
|
+
terminal = create(tag, undefined, stream);
|
|
19
|
+
terminal.enable(defaultLevel || EnableLogLevel.log);
|
|
20
|
+
if (terminal.verbose.isEnabled) {
|
|
21
|
+
terminal.verbose `verbose is enabled`;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
terminal.debug `debug is enabled`;
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=logger.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.global.js","sourceRoot":"","sources":["../../src/common/logger.global.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AAE5D,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;AACjC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC5B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,IAAI,QAAmB,CAAC;AAE/B;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,eAA+B,cAAc,CAAC,IAAI;IACjG,IAAI,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAE/D,QAAQ,GAAG,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAE1C,QAAQ,CAAC,MAAM,CAAC,YAAY,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;IAEpD,IAAI,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QAChC,QAAQ,CAAC,OAAO,CAAA,oBAAoB,CAAC;IACtC,CAAC;SAAM,CAAC;QACP,QAAQ,CAAC,KAAK,CAAA,kBAAkB,CAAC;IAClC,CAAC;IACD,OAAO;AACR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../src/common/printer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.js","sourceRoot":"","sources":["../../src/common/printer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type IMyDebug<T = void> = (message: TemplateStringsArray | string, ...args: readonly any[]) => T;
|
|
2
|
+
export interface IMyDebugWithControl extends IMyDebug {
|
|
3
|
+
enable(): void;
|
|
4
|
+
disable(): void;
|
|
5
|
+
readonly isEnabled: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare enum EnableLogLevel {
|
|
8
|
+
auto = 0,
|
|
9
|
+
fatal = 1,
|
|
10
|
+
error = 2,
|
|
11
|
+
warn = 3,
|
|
12
|
+
info = 4,
|
|
13
|
+
log = 5,
|
|
14
|
+
debug = 6,
|
|
15
|
+
verbose = 7
|
|
16
|
+
}
|
|
17
|
+
export type IMyLogger = {
|
|
18
|
+
fatal: IMyDebug<never>;
|
|
19
|
+
error: IMyDebug;
|
|
20
|
+
success: IMyDebugWithControl;
|
|
21
|
+
warn: IMyDebugWithControl;
|
|
22
|
+
info: IMyDebugWithControl;
|
|
23
|
+
log: IMyDebugWithControl;
|
|
24
|
+
debug: IMyDebugWithControl;
|
|
25
|
+
verbose: IMyDebugWithControl;
|
|
26
|
+
extend: (tag: string) => IMyLogger;
|
|
27
|
+
stream: NodeJS.ReadableStream;
|
|
28
|
+
enable(newMaxLevel: EnableLogLevel): void;
|
|
29
|
+
readonly tag: string;
|
|
30
|
+
readonly colorEnabled: boolean;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;AAExG,MAAM,WAAW,mBAAoB,SAAQ,QAAQ;IACpD,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B;AAED,oBAAY,cAAc;IACzB,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,KAAK,IAAA;IACL,OAAO,IAAA;CACP;AAED,MAAM,MAAM,SAAS,GAAG;IACvB,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEvB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,mBAAmB,CAAC;IAE7B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,GAAG,EAAE,mBAAmB,CAAC;IACzB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,EAAE,mBAAmB,CAAC;IAE7B,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAE9B,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,IAAI,CAAC;IAE1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var EnableLogLevel;
|
|
2
|
+
(function (EnableLogLevel) {
|
|
3
|
+
EnableLogLevel[EnableLogLevel["auto"] = 0] = "auto";
|
|
4
|
+
EnableLogLevel[EnableLogLevel["fatal"] = 1] = "fatal";
|
|
5
|
+
EnableLogLevel[EnableLogLevel["error"] = 2] = "error";
|
|
6
|
+
EnableLogLevel[EnableLogLevel["warn"] = 3] = "warn";
|
|
7
|
+
EnableLogLevel[EnableLogLevel["info"] = 4] = "info";
|
|
8
|
+
EnableLogLevel[EnableLogLevel["log"] = 5] = "log";
|
|
9
|
+
EnableLogLevel[EnableLogLevel["debug"] = 6] = "debug";
|
|
10
|
+
EnableLogLevel[EnableLogLevel["verbose"] = 7] = "verbose";
|
|
11
|
+
})(EnableLogLevel || (EnableLogLevel = {}));
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IACzB,mDAAI,CAAA;IACJ,qDAAK,CAAA;IACL,qDAAK,CAAA;IACL,mDAAI,CAAA;IACJ,mDAAI,CAAA;IACJ,iDAAG,CAAA;IACH,qDAAK,CAAA;IACL,yDAAO,CAAA;AACR,CAAC,EATW,cAAc,KAAd,cAAc,QASzB"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { LogLevel, logTagColor } from './common/colors.js';
|
|
2
|
+
export { all_logger_names } from './common/create.js';
|
|
3
|
+
export { createDebug } from './common/debug-fn.js';
|
|
4
|
+
export { detectColorEnable as color_enabled, debug_enabled, is_string_truthy, match_disabled, match_enabled, set_default_log_level, } from './common/helpers.js';
|
|
5
|
+
export { createLogger } from './common/logger.create.js';
|
|
6
|
+
export { createGlobalLogger as createRootLogger, terminal as logger, } from './common/logger.global.js';
|
|
7
|
+
export { EnableLogLevel, type IMyDebug, type IMyDebugWithControl, type IMyLogger, } from './common/types.js';
|
|
8
|
+
export { createLogFile } from './printers/file.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACN,iBAAiB,IAAI,aAAa,EAClC,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,qBAAqB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACN,kBAAkB,IAAI,gBAAgB,EACtC,QAAQ,IAAI,MAAM,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,cAAc,EACd,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { LogLevel, logTagColor } from './common/colors.js';
|
|
2
|
+
export { all_logger_names } from './common/create.js';
|
|
3
|
+
export { createDebug } from './common/debug-fn.js';
|
|
4
|
+
export { detectColorEnable as color_enabled, debug_enabled, is_string_truthy, match_disabled, match_enabled, set_default_log_level, } from './common/helpers.js';
|
|
5
|
+
export { createLogger } from './common/logger.create.js';
|
|
6
|
+
export { createGlobalLogger as createRootLogger, terminal as logger, } from './common/logger.global.js';
|
|
7
|
+
export { EnableLogLevel, } from './common/types.js';
|
|
8
|
+
export { createLogFile } from './printers/file.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACN,iBAAiB,IAAI,aAAa,EAClC,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,qBAAqB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACN,kBAAkB,IAAI,gBAAgB,EACtC,QAAQ,IAAI,MAAM,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,cAAc,GAId,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/printers/file.ts"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,cAAc,CAiBrE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { Transform } from 'node:stream';
|
|
4
|
+
export function createLogFile(filePath) {
|
|
5
|
+
const file = resolve(process.cwd(), filePath);
|
|
6
|
+
console.log(`Creating log file: ${file}`);
|
|
7
|
+
const target = createWriteStream(file, { autoClose: true, encoding: 'utf-8', flush: true });
|
|
8
|
+
target.on('error', (err) => {
|
|
9
|
+
console.error(`Error writing to log file ${file}:`, err);
|
|
10
|
+
});
|
|
11
|
+
target.on('open', (fd) => {
|
|
12
|
+
console.error(`log file ${file}:`, fd);
|
|
13
|
+
});
|
|
14
|
+
target.on('close', () => {
|
|
15
|
+
console.error(`log file ${file}: close`);
|
|
16
|
+
});
|
|
17
|
+
const filter = new ColorRemoveStream();
|
|
18
|
+
filter.pipe(target, { end: true });
|
|
19
|
+
return filter;
|
|
20
|
+
}
|
|
21
|
+
class ColorRemoveStream extends Transform {
|
|
22
|
+
_transform(chunk, _encoding, callback) {
|
|
23
|
+
const cleaned = chunk.toString().replace(/\x1B\[[0-9;]*m/g, '');
|
|
24
|
+
callback(null, cleaned);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +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;AAEhE,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,MAAM,CAAC;AACf,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"01-simple.test.d.ts","sourceRoot":"","sources":["../../src/test/01-simple.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createGlobalLogger } from '../common/logger.global.js';
|
|
2
|
+
import { logger } from '../index.js';
|
|
3
|
+
createGlobalLogger('wow');
|
|
4
|
+
const l = 'such';
|
|
5
|
+
const o = { hello: 'world' };
|
|
6
|
+
logger.error `wow, ${l} doge! ${o}!`;
|
|
7
|
+
logger.error('wow, such %s! %o?', l, o);
|
|
8
|
+
console.log('----------------');
|
|
9
|
+
logger.warn `wow, ${l} doge! ${o}!`;
|
|
10
|
+
logger.warn('wow, such %s! %o?', l, o);
|
|
11
|
+
console.log('----------------');
|
|
12
|
+
logger.info `wow, ${l} doge! ${o}!`;
|
|
13
|
+
logger.info('wow, such %s! %o?', l, o);
|
|
14
|
+
console.log('----------------');
|
|
15
|
+
logger.log `wow, ${l} doge! ${o}!`;
|
|
16
|
+
logger.log('wow, such %s! %o?', l, o);
|
|
17
|
+
console.log('----------------');
|
|
18
|
+
logger.success `wow, ${l} doge! ${o}!`;
|
|
19
|
+
logger.success('wow, such %s! %o?', l, o);
|
|
20
|
+
console.log('----------------');
|
|
21
|
+
logger.debug `wow, ${l} doge! ${o}!`;
|
|
22
|
+
logger.debug('wow, such %s! %o?', l, o);
|
|
23
|
+
console.log('----------------');
|
|
24
|
+
logger.verbose `wow, ${l} doge! ${o}!`;
|
|
25
|
+
logger.verbose('wow, such %s! %o?', l, o);
|
|
26
|
+
console.log('----------------');
|
|
27
|
+
logger.fatal `wow, ${l} doge! ${o}!`;
|
|
28
|
+
logger.fatal('wow, such %s! %o?', l, o);
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
console.log('----------------');
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
logger.error `this not happen`;
|
|
33
|
+
//# sourceMappingURL=01-simple.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"01-simple.test.js","sourceRoot":"","sources":["../../src/test/01-simple.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE1B,MAAM,CAAC,GAAG,MAAM,CAAC;AACjB,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAE7B,MAAM,CAAC,KAAK,CAAA,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;AACpC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEhC,MAAM,CAAC,IAAI,CAAA,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;AACnC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEhC,MAAM,CAAC,IAAI,CAAA,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;AACnC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,OAAO,CAAC,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obalLogger } from '../common/logger.global.js';
|
|
2
|
+
import { logger } from '../index.js';
|
|
3
|
+
createGlobalLogger('wow');
|
|
4
|
+
const l = 'such';
|
|
5
|
+
const o = { hello: 'world' };
|
|
6
|
+
logger.debug `wow, ${l} doge! ${o}!`;
|
|
7
|
+
console.log('----------------');
|
|
8
|
+
logger.debug('wow, such %s! %o?', l, o);
|
|
9
|
+
//# sourceMappingURL=02-debug.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"02-debug.test.js","sourceRoot":"","sources":["../../src/test/02-debug.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE1B,MAAM,CAAC,GAAG,MAAM,CAAC;AACjB,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAE7B,MAAM,CAAC,KAAK,CAAA,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;AACpC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAChC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"03-file.test.d.ts","sourceRoot":"","sources":["../../src/test/03-file.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createGlobalLogger } from '../common/logger.global.js';
|
|
2
|
+
import { createLogFile, logger } from '../index.js';
|
|
3
|
+
createGlobalLogger('wow');
|
|
4
|
+
logger.stream.pipe(createLogFile('test.log'));
|
|
5
|
+
const l = 'such';
|
|
6
|
+
const o = { hello: 'world' };
|
|
7
|
+
logger.error `wow, ${l} doge! ${o}!`;
|
|
8
|
+
logger.error('wow, such %s! %o?', l, o);
|
|
9
|
+
console.log('----------------');
|
|
10
|
+
logger.warn `wow, ${l} doge! ${o}!`;
|
|
11
|
+
logger.warn('wow, such %s! %o?', l, o);
|
|
12
|
+
console.log('----------------');
|
|
13
|
+
logger.info `wow, ${l} doge! ${o}!`;
|
|
14
|
+
logger.info('wow, such %s! %o?', l, o);
|
|
15
|
+
console.log('----------------');
|
|
16
|
+
logger.log `wow, ${l} doge! ${o}!`;
|
|
17
|
+
logger.log('wow, such %s! %o?', l, o);
|
|
18
|
+
console.log('----------------');
|
|
19
|
+
logger.success `wow, ${l} doge! ${o}!`;
|
|
20
|
+
logger.success('wow, such %s! %o?', l, o);
|
|
21
|
+
console.log('----------------');
|
|
22
|
+
logger.debug `wow, ${l} doge! ${o}!`;
|
|
23
|
+
logger.debug('wow, such %s! %o?', l, o);
|
|
24
|
+
console.log('----------------');
|
|
25
|
+
logger.verbose `wow, ${l} doge! ${o}!`;
|
|
26
|
+
logger.verbose('wow, such %s! %o?', l, o);
|
|
27
|
+
console.log('----------------');
|
|
28
|
+
logger.fatal `wow, ${l} doge! ${o}!`;
|
|
29
|
+
logger.fatal('wow, such %s! %o?', l, o);
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
console.log('----------------');
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
logger.error `this not happen`;
|
|
34
|
+
//# sourceMappingURL=03-file.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"03-file.test.js","sourceRoot":"","sources":["../../src/test/03-file.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEpD,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9C,MAAM,CAAC,GAAG,MAAM,CAAC;AACjB,MAAM,CAAC,GAAG,EA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