@wiajs/log 4.3.19 → 4.3.20
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/dist/log.bs.cjs +148 -190
- package/dist/log.cjs +123 -154
- package/dist/log.mjs +147 -188
- package/lib/log.bs.js +36 -45
- package/lib/log.js +76 -75
- package/package.json +3 -17
- package/dist/log.js +0 -194
- package/dist/log.min.js +0 -6
package/dist/log.cjs
CHANGED
|
@@ -1,166 +1,135 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia log v4.3.
|
|
3
|
-
* (c) 2024-
|
|
2
|
+
* wia log v4.3.20
|
|
3
|
+
* (c) 2024-2025 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
9
|
|
|
10
|
-
const path = require('node:path');
|
|
11
|
-
const node_url = require('node:url');
|
|
12
10
|
const debug = require('debug');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const url = require('url');
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// 全局日志
|
|
135
|
-
if (args.length !== 1 || !last?.env) return
|
|
136
|
-
|
|
137
|
-
const {env} = last;
|
|
138
|
-
// 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
|
|
139
|
-
const lg = new Log({env});
|
|
140
|
-
|
|
141
|
-
/** @param {*} args2 */
|
|
142
|
-
const R = (...args2) => lg.debug(...args2);
|
|
143
|
-
R.debug = lg.debug.bind(lg);
|
|
144
|
-
R.info = lg.info.bind(lg);
|
|
145
|
-
R.warn = lg.warn.bind(lg);
|
|
146
|
-
R.info = lg.info.bind(lg);
|
|
147
|
-
R.error = lg.error.bind(lg);
|
|
148
|
-
R.err = lg.err.bind(lg);
|
|
149
|
-
|
|
150
|
-
return R
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 获取模块文件名称
|
|
155
|
-
* esm: import.meta.url or cjs: __filename
|
|
156
|
-
* @param {string} file
|
|
157
|
-
* @returns
|
|
158
|
-
*/
|
|
159
|
-
function name(file) {
|
|
160
|
-
// import.meta.url: 'file:///D:/prj/wiajs/req/test/log.t.js'
|
|
161
|
-
file = node_url.fileURLToPath(file); // fileUrl 转成路径
|
|
162
|
-
const baseName = path.basename(file);
|
|
163
|
-
return baseName.replace(path.extname(baseName), '')
|
|
14
|
+
let Log = class Log {
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {...any} args
|
|
18
|
+
*/ debug(...args) {
|
|
19
|
+
const first = args == null ? void 0 : args.at(0);
|
|
20
|
+
const last = args == null ? void 0 : args.at(-1);
|
|
21
|
+
if (typeof first === 'string') {
|
|
22
|
+
args.shift();
|
|
23
|
+
this.dgs.debug(first, ...args);
|
|
24
|
+
} else if (typeof first === 'object' && typeof last === 'string') this.dgs.debug(`${last}:%O`, first);
|
|
25
|
+
// args[0] = `${this.pre}:${args[0]}`
|
|
26
|
+
// console.debug(...args)
|
|
27
|
+
// console.debug(this.pre, ...args)
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {...any} args
|
|
32
|
+
*/ error(...args) {
|
|
33
|
+
const first = args == null ? void 0 : args.at(0);
|
|
34
|
+
const last = args == null ? void 0 : args.at(-1);
|
|
35
|
+
if (typeof first === 'string') {
|
|
36
|
+
args.shift();
|
|
37
|
+
this.dgs.err(` ${first}`, ...args);
|
|
38
|
+
} else if (typeof first === 'object' && typeof last === 'string') this.dgs.err(` ${last}:%O`, first);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {...any} args
|
|
43
|
+
*/ err(...args) {
|
|
44
|
+
const first = args == null ? void 0 : args[0];
|
|
45
|
+
if ((first == null ? void 0 : first.message) || (first == null ? void 0 : first.msg)) {
|
|
46
|
+
args[0] = {
|
|
47
|
+
exp: first.message || first.msg
|
|
48
|
+
};
|
|
49
|
+
if (first == null ? void 0 : first.code) args[0].exp += ` code:${first.code}`;
|
|
50
|
+
}
|
|
51
|
+
this.error(...args);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {...any} args
|
|
56
|
+
*/ warn(...args) {
|
|
57
|
+
const first = args == null ? void 0 : args.at(0);
|
|
58
|
+
const last = args == null ? void 0 : args.at(-1);
|
|
59
|
+
if (typeof first === 'string') {
|
|
60
|
+
args.shift();
|
|
61
|
+
this.dgs.warn(first, ...args);
|
|
62
|
+
} else if (typeof first === 'object' && typeof last === 'string') this.dgs.warn(`${last}:%O`, first);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param {...any} args
|
|
67
|
+
*/ info(...args) {
|
|
68
|
+
const first = args == null ? void 0 : args.at(0);
|
|
69
|
+
const last = args == null ? void 0 : args.at(-1);
|
|
70
|
+
// const dg = debug('ab')
|
|
71
|
+
// dg()
|
|
72
|
+
if (typeof first === 'string') {
|
|
73
|
+
args.shift();
|
|
74
|
+
this.dgs.info(first, ...args);
|
|
75
|
+
} else if (typeof first === 'object' && typeof last === 'string') this.dgs.info(`${last}:%O`, first);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 构造函数
|
|
79
|
+
* @param {*} opts {
|
|
80
|
+
* pre: 前缀,一般是模块名称,
|
|
81
|
+
* env: NODE_DEBUG 环境变量
|
|
82
|
+
* }
|
|
83
|
+
*/ constructor(opts){
|
|
84
|
+
let { env } = opts;
|
|
85
|
+
env = env != null ? env : '';
|
|
86
|
+
const dgs = {} // debugs
|
|
87
|
+
;
|
|
88
|
+
dgs.debug = debug(`${env}`);
|
|
89
|
+
dgs.info = debug(`${env}:info`);
|
|
90
|
+
dgs.err = debug(`${env}:err`);
|
|
91
|
+
dgs.warn = debug(`${env}:warn`);
|
|
92
|
+
// 仅最后调用生效,覆盖环境变量
|
|
93
|
+
if (dgs.debug.enabled) debug.enable('*');
|
|
94
|
+
else if (dgs.info.enabled) debug.enable(`${env}:info,${env}:err,${env}:warn`);
|
|
95
|
+
else debug.enable(`${env}:err,${env}:warn`);
|
|
96
|
+
this.dgs = dgs;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* 标准日志输出或构建模块日志类实例,用于模块中带[m:xxx]标记日志输出
|
|
101
|
+
* 启用 {f:fn} 标记时,需在函数尾部清除f(log({f:''})),否则会溢出到其他函数
|
|
102
|
+
* @param {...any} args - params
|
|
103
|
+
* returns {pino & (...args) => void}
|
|
104
|
+
*/ function log(...args) {
|
|
105
|
+
const last = args.at(-1);
|
|
106
|
+
// 全局日志
|
|
107
|
+
if (args.length !== 1 || !(last == null ? void 0 : last.env)) return;
|
|
108
|
+
const { env } = last;
|
|
109
|
+
// 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
|
|
110
|
+
const lg = new Log({
|
|
111
|
+
env
|
|
112
|
+
});
|
|
113
|
+
/** @param {*} args2 */ const R = (...args2)=>lg.debug(...args2);
|
|
114
|
+
R.debug = lg.debug.bind(lg);
|
|
115
|
+
R.info = lg.info.bind(lg);
|
|
116
|
+
R.warn = lg.warn.bind(lg);
|
|
117
|
+
R.info = lg.info.bind(lg);
|
|
118
|
+
R.error = lg.error.bind(lg);
|
|
119
|
+
R.err = lg.err.bind(lg);
|
|
120
|
+
return R;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 获取模块文件名称
|
|
124
|
+
* esm: import.meta.url or cjs: __filename
|
|
125
|
+
* @param {string} file
|
|
126
|
+
* @returns
|
|
127
|
+
*/ function name(file) {
|
|
128
|
+
// import.meta.url: 'file:///D:/prj/wiajs/req/test/log.t.js'
|
|
129
|
+
file = url.fileURLToPath(file) // fileUrl 转成路径
|
|
130
|
+
;
|
|
131
|
+
const baseName = path.basename(file);
|
|
132
|
+
return baseName.replace(path.extname(baseName), '');
|
|
164
133
|
}
|
|
165
134
|
|
|
166
135
|
exports.default = Log;
|
package/dist/log.mjs
CHANGED
|
@@ -1,217 +1,176 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia log v4.3.
|
|
3
|
-
* (c) 2024-
|
|
2
|
+
* wia log v4.3.20
|
|
3
|
+
* (c) 2024-2025 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* 前端日志输出,封装 console日志,简化代码,支持模块或直接输出
|
|
8
8
|
* 调用时,描述字符串后置,便于可选缺省,输出时,自带前置,类似 后端pino,保持前后端一致性
|
|
9
9
|
* m 为模块,fn 为函数名称
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** @type {string} 模块 */
|
|
13
|
-
m = ''
|
|
14
|
-
|
|
15
|
-
/** @type {string} 函数 */
|
|
16
|
-
fn = ''
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {string} m 模块
|
|
20
|
-
*/
|
|
21
|
-
constructor(m) {
|
|
22
|
-
this.m = m;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
10
|
+
*/ let Log = class Log {
|
|
11
|
+
/**
|
|
26
12
|
* get log desc
|
|
27
|
-
*
|
|
13
|
+
* 描述字符串后置调用,前置显示
|
|
28
14
|
* @param {*[]} args
|
|
29
|
-
* @returns {
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const _ = this;
|
|
99
|
-
const {desc, arg} = _.getDesc(args);
|
|
100
|
-
if (desc) console.trace(desc, ...arg);
|
|
101
|
-
else console.trace(...args);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @param {...any} args - params */
|
|
105
|
-
error(...args) {
|
|
106
|
-
const _ = this;
|
|
107
|
-
const {desc, arg} = _.getDesc(args);
|
|
108
|
-
if (desc) console.error(desc, ...arg);
|
|
109
|
-
else console.log(...args);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/ getDesc(args) {
|
|
17
|
+
let R = '';
|
|
18
|
+
try {
|
|
19
|
+
const _ = this;
|
|
20
|
+
const { m } = _;
|
|
21
|
+
let fn = '', desc = '';
|
|
22
|
+
if (args.length > 1) {
|
|
23
|
+
const last = args.at(-1);
|
|
24
|
+
if (typeof last === 'object') {
|
|
25
|
+
;
|
|
26
|
+
({ desc, fn } = last);
|
|
27
|
+
} else if (typeof last === 'string') desc = last;
|
|
28
|
+
if (desc || fn) {
|
|
29
|
+
fn = fn || _.fn;
|
|
30
|
+
_.fn = fn;
|
|
31
|
+
args.pop();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
fn = fn || _.fn;
|
|
35
|
+
if (m) desc = `${desc}[${m}${fn ? ':' + fn : ''}]` // eslint-disable-line
|
|
36
|
+
;
|
|
37
|
+
R = desc;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(`getDesc exp:${e.message}`);
|
|
40
|
+
}
|
|
41
|
+
return R;
|
|
42
|
+
}
|
|
43
|
+
/** @param {...any} args - params */ log(...args) {
|
|
44
|
+
const _ = this;
|
|
45
|
+
const last = args.at(-1);
|
|
46
|
+
// clear fn
|
|
47
|
+
if (args.length === 1 && typeof last === 'object' && last.fn) _.fn = '';
|
|
48
|
+
else {
|
|
49
|
+
const desc = _.getDesc(args);
|
|
50
|
+
console.log(desc, ...args);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** @param {...any} args - params */ debug(...args) {
|
|
54
|
+
const _ = this;
|
|
55
|
+
const desc = _.getDesc(args);
|
|
56
|
+
if (desc) console.log(desc, ...args);
|
|
57
|
+
else console.log(...args);
|
|
58
|
+
}
|
|
59
|
+
/** @param {...any} args - params */ info(...args) {
|
|
60
|
+
const _ = this;
|
|
61
|
+
const desc = _.getDesc(args);
|
|
62
|
+
if (desc) console.info(desc, ...args);
|
|
63
|
+
else console.log(...args);
|
|
64
|
+
}
|
|
65
|
+
/** @param {...any} args - params */ warn(...args) {
|
|
66
|
+
const _ = this;
|
|
67
|
+
const { desc, arg } = _.getDesc(args);
|
|
68
|
+
if (desc) console.warn(desc, ...arg);
|
|
69
|
+
else console.log(...args);
|
|
70
|
+
}
|
|
71
|
+
/** @param {...any} args - params */ trace(...args) {
|
|
72
|
+
const _ = this;
|
|
73
|
+
const { desc, arg } = _.getDesc(args);
|
|
74
|
+
if (desc) console.trace(desc, ...arg);
|
|
75
|
+
else console.trace(...args);
|
|
76
|
+
}
|
|
77
|
+
/** @param {...any} args - params */ error(...args) {
|
|
78
|
+
const _ = this;
|
|
79
|
+
const desc = _.getDesc(args);
|
|
80
|
+
if (desc) console.error(desc, ...args);
|
|
81
|
+
else console.log(...args);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
113
84
|
* 用于 catch(e) log.err(e)
|
|
114
|
-
* @param {...any} args - params */
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
85
|
+
* @param {...any} args - params */ err(...args) {
|
|
86
|
+
const _ = this;
|
|
87
|
+
const first = args == null ? void 0 : args[0];
|
|
88
|
+
if (first instanceof Error || first && first.message && first.cause && first.stack) args[0] = {
|
|
89
|
+
exp: args[0].message
|
|
90
|
+
};
|
|
91
|
+
_.error(...args);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} m 模块
|
|
95
|
+
*/ constructor(m){
|
|
96
|
+
/** @type {string} 模块 */ this.m = '';
|
|
97
|
+
/** @type {string} 函数 */ this.fn = '';
|
|
98
|
+
this.m = m;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
124
101
|
/**
|
|
125
102
|
* get log desc
|
|
126
103
|
* 描述字符串作为最后参数调用,显示时,前置
|
|
127
104
|
* @param {*[]} args
|
|
128
105
|
* @returns {{desc: string, arg: *[]}}
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
106
|
+
*/ function getDesc(args) {
|
|
107
|
+
let desc = '';
|
|
108
|
+
const last = args.at(-1);
|
|
109
|
+
if (typeof last === 'string') {
|
|
110
|
+
desc = last;
|
|
111
|
+
args.pop();
|
|
112
|
+
}
|
|
113
|
+
return desc;
|
|
114
|
+
}
|
|
140
115
|
/**
|
|
141
116
|
* 标准日志输出或构建模块日志类实例,用于模块中带[m:xxx]标记日志输出
|
|
142
117
|
* 启用 {f:fn} 标记时,需在函数尾部清除f(log({f:''})),否则会溢出到其他函数
|
|
143
118
|
* @param {...any} args - params
|
|
144
119
|
* returns {*}
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
R.error = lg.error.bind(lg);
|
|
166
|
-
R.err = lg.err.bind(lg);
|
|
167
|
-
|
|
168
|
-
return R
|
|
169
|
-
}
|
|
170
|
-
|
|
120
|
+
*/ function log(...args) {
|
|
121
|
+
const last = args.at(-1);
|
|
122
|
+
// 全局日志
|
|
123
|
+
if (args.length !== 1 || !(last == null ? void 0 : last.m)) {
|
|
124
|
+
const desc = getDesc(args);
|
|
125
|
+
desc ? console.log(desc, ...args) : console.log(...args);
|
|
126
|
+
return; // 退出,不创建实例
|
|
127
|
+
}
|
|
128
|
+
// 唯一 m 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
|
|
129
|
+
const lg = new Log(last == null ? void 0 : last.m);
|
|
130
|
+
/** @param {*} args2 */ const R = (...args2)=>lg.log(...args2);
|
|
131
|
+
R.debug = lg.debug.bind(lg);
|
|
132
|
+
R.info = lg.info.bind(lg);
|
|
133
|
+
R.warn = lg.warn.bind(lg);
|
|
134
|
+
R.info = lg.info.bind(lg);
|
|
135
|
+
R.trace = lg.trace.bind(lg);
|
|
136
|
+
R.error = lg.error.bind(lg);
|
|
137
|
+
R.err = lg.err.bind(lg);
|
|
138
|
+
return R;
|
|
139
|
+
}
|
|
171
140
|
/**
|
|
172
141
|
* 用于 catch(e) log.err(e)
|
|
173
|
-
* @param {...any} args - params */
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
};
|
|
181
|
-
|
|
142
|
+
* @param {...any} args - params */ log.err = (...args)=>{
|
|
143
|
+
const desc = getDesc(args);
|
|
144
|
+
const first = args == null ? void 0 : args[0];
|
|
145
|
+
if (first instanceof Error || first && first.message && first.cause && first.stack) args[0] = {
|
|
146
|
+
exp: args[0].message
|
|
147
|
+
};
|
|
148
|
+
desc ? console.error(desc, ...args) : console.error(...args);
|
|
149
|
+
};
|
|
182
150
|
/**
|
|
183
|
-
* @param {...any} args - params */
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
188
|
-
|
|
151
|
+
* @param {...any} args - params */ log.error = (...args)=>{
|
|
152
|
+
const desc = getDesc(args);
|
|
153
|
+
desc ? console.error(desc, ...args) : console.error(...args);
|
|
154
|
+
};
|
|
189
155
|
/**
|
|
190
|
-
* @param {...any} args - params */
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
};
|
|
195
|
-
|
|
156
|
+
* @param {...any} args - params */ log.warn = (...args)=>{
|
|
157
|
+
const desc = getDesc(args);
|
|
158
|
+
desc ? console.warn(desc, ...args) : console.warn(...args);
|
|
159
|
+
};
|
|
196
160
|
/**
|
|
197
|
-
* @param {...any} args - params */
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
|
|
161
|
+
* @param {...any} args - params */ log.info = (...args)=>{
|
|
162
|
+
const desc = getDesc(args);
|
|
163
|
+
desc ? console.info(desc, ...args) : console.info(...args);
|
|
164
|
+
};
|
|
203
165
|
/**
|
|
204
|
-
* @param {...any} args - params */
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
209
|
-
|
|
166
|
+
* @param {...any} args - params */ log.debug = (...args)=>{
|
|
167
|
+
const desc = getDesc(args);
|
|
168
|
+
desc ? console.log(desc, ...args) : console.log(...args);
|
|
169
|
+
};
|
|
210
170
|
/**
|
|
211
|
-
* @param {...any} args - params */
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
desc ? console.trace(desc, ...arg) : console.trace(...args);
|
|
171
|
+
* @param {...any} args - params */ log.trace = (...args)=>{
|
|
172
|
+
const desc = getDesc(args);
|
|
173
|
+
desc ? console.trace(desc, ...args) : console.trace(...args);
|
|
215
174
|
};
|
|
216
175
|
|
|
217
|
-
export { log
|
|
176
|
+
export { Log, log };
|