@wiajs/log 4.3.10 → 4.3.12

Sign up to get free protection for your applications and to get access to all the features.
package/dist/log.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * wia log v4.3.7
3
- * (c) 2022-2024 Sibyl Yu and contributors
2
+ * wia log v4.3.12
3
+ * (c) 2024-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  'use strict';
@@ -8,6 +8,7 @@
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
10
  const path = require('node:path');
11
+ const node_url = require('node:url');
11
12
  const debug = require('debug');
12
13
 
13
14
  /**
@@ -24,98 +25,93 @@ const debug = require('debug');
24
25
  * warn 和 err 一直打开!
25
26
  */
26
27
  class Log {
27
- /**
28
- * 构造函数
29
- * @param {*} opts {
30
- * pre: 前缀,一般是模块名称,
31
- * env: NODE_DEBUG 环境变量
32
- * }
33
- */
34
- constructor(opts) {
35
- let { env } = opts;
36
- env = env ?? "";
37
- const ds = {}; // debugs
38
- ds.debug = debug(`${env}`);
39
- ds.info = debug(`${env}:info`);
40
- ds.err = debug(`${env}:err`);
41
- ds.warn = debug(`${env}:warn`);
28
+ /**
29
+ * 构造函数
30
+ * @param {*} opts {
31
+ * pre: 前缀,一般是模块名称,
32
+ * env: NODE_DEBUG 环境变量
33
+ * }
34
+ */
35
+ constructor(opts) {
36
+ let {env} = opts;
37
+ env = env ?? '';
38
+ const ds = {}; // debugs
39
+ ds.debug = debug(`${env}`);
40
+ ds.info = debug(`${env}:info`);
41
+ ds.err = debug(`${env}:err`);
42
+ ds.warn = debug(`${env}:warn`);
42
43
 
43
- // 仅最后调用生效,覆盖环境变量
44
- if (ds.debug.enabled) debug.enable("*");
45
- else if (ds.info.enabled)
46
- debug.enable(`${env}:info,${env}:err,${env}:warn`);
47
- else debug.enable(`${env}:err,${env}:warn`);
44
+ // 仅最后调用生效,覆盖环境变量
45
+ if (ds.debug.enabled) debug.enable('*');
46
+ else if (ds.info.enabled) debug.enable(`${env}:info,${env}:err,${env}:warn`);
47
+ else debug.enable(`${env}:err,${env}:warn`);
48
48
 
49
- this.ds = ds;
50
- }
49
+ this.ds = ds;
50
+ }
51
51
 
52
- /**
53
- *
54
- * @param {...any} args
55
- */
56
- debug(...args) {
57
- const first = args?.at(0);
58
- const last = args?.at(-1);
59
- if (typeof first === "string") {
60
- args[0] = `${first}`;
61
- this.ds.debug(...args);
62
- } else if (typeof first === "object" && typeof last === "string")
63
- this.ds.debug(`${last}:%O`, first);
64
- // args[0] = `${this.pre}:${args[0]}`
65
- // console.debug(...args)
66
- // console.debug(this.pre, ...args)
67
- }
52
+ /**
53
+ *
54
+ * @param {...any} args
55
+ */
56
+ debug(...args) {
57
+ const first = args?.at(0);
58
+ const last = args?.at(-1);
59
+ if (typeof first === 'string') {
60
+ args[0] = `${first}`;
61
+ this.ds.debug(...args);
62
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.debug(`${last}:%O`, first);
63
+ // args[0] = `${this.pre}:${args[0]}`
64
+ // console.debug(...args)
65
+ // console.debug(this.pre, ...args)
66
+ }
68
67
 
69
- /**
70
- *
71
- * @param {...any} args
72
- */
73
- error(...args) {
74
- const first = args?.at(0);
75
- const last = args?.at(-1);
76
- if (typeof first === "string") {
77
- args[0] = ` ${first}`;
78
- this.ds.err(...args);
79
- } else if (typeof first === "object" && typeof last === "string")
80
- this.ds.err(` ${last}:%O`, first);
81
- }
68
+ /**
69
+ *
70
+ * @param {...any} args
71
+ */
72
+ error(...args) {
73
+ const first = args?.at(0);
74
+ const last = args?.at(-1);
75
+ if (typeof first === 'string') {
76
+ args[0] = ` ${first}`;
77
+ this.ds.err(...args);
78
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.err(` ${last}:%O`, first);
79
+ }
82
80
 
83
- /**
84
- *
85
- * @param {...any} args
86
- */
87
- err(...args) {
88
- const first = args?.[0];
89
- if (first?.message || first?.msg) {
90
- args[0] = { exp: first.message || first.msg };
91
- if (first?.code) args[0].exp += ` code:${first.code}`;
92
- }
93
- this.error(...args);
94
- }
81
+ /**
82
+ *
83
+ * @param {...any} args
84
+ */
85
+ err(...args) {
86
+ const first = args?.[0];
87
+ if (first?.message || first?.msg) {
88
+ args[0] = {exp: first.message || first.msg};
89
+ if (first?.code) args[0].exp += ` code:${first.code}`;
90
+ }
91
+ this.error(...args);
92
+ }
95
93
 
96
- /**
97
- *
98
- * @param {...any} args
99
- */
100
- warn(...args) {
101
- const first = args?.at(0);
102
- const last = args?.at(-1);
103
- if (typeof first === "string") this.ds.warn(...args);
104
- else if (typeof first === "object" && typeof last === "string")
105
- this.ds.warn(`${last}:%O`, first);
106
- }
94
+ /**
95
+ *
96
+ * @param {...any} args
97
+ */
98
+ warn(...args) {
99
+ const first = args?.at(0);
100
+ const last = args?.at(-1);
101
+ if (typeof first === 'string') this.ds.warn(...args);
102
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.warn(`${last}:%O`, first);
103
+ }
107
104
 
108
- /**
109
- *
110
- * @param {...any} args
111
- */
112
- info(...args) {
113
- const first = args?.at(0);
114
- const last = args?.at(-1);
115
- if (typeof first === "string") this.ds.info(...args);
116
- else if (typeof first === "object" && typeof last === "string")
117
- this.ds.info(`${last}:%O`, first);
118
- }
105
+ /**
106
+ *
107
+ * @param {...any} args
108
+ */
109
+ info(...args) {
110
+ const first = args?.at(0);
111
+ const last = args?.at(-1);
112
+ if (typeof first === 'string') this.ds.info(...args);
113
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.info(`${last}:%O`, first);
114
+ }
119
115
  }
120
116
 
121
117
  /**
@@ -125,35 +121,38 @@ class Log {
125
121
  * returns {pino & (...args) => void}
126
122
  */
127
123
  function log(...args) {
128
- const last = args.at(-1);
124
+ const last = args.at(-1);
129
125
 
130
- // 全局日志
131
- if (args.length !== 1 || !last?.env) return;
126
+ // 全局日志
127
+ if (args.length !== 1 || !last?.env) return
132
128
 
133
- const { env } = last;
134
- // 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
135
- const lg = new Log({ env });
129
+ const {env} = last;
130
+ // 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
131
+ const lg = new Log({env});
136
132
 
137
- /** @param {*} args2 */
138
- const R = (...args2) => lg.debug(...args2);
139
- R.debug = lg.debug.bind(lg);
140
- R.info = lg.info.bind(lg);
141
- R.warn = lg.warn.bind(lg);
142
- R.info = lg.info.bind(lg);
143
- R.error = lg.error.bind(lg);
144
- R.err = lg.err.bind(lg);
133
+ /** @param {*} args2 */
134
+ const R = (...args2) => lg.debug(...args2);
135
+ R.debug = lg.debug.bind(lg);
136
+ R.info = lg.info.bind(lg);
137
+ R.warn = lg.warn.bind(lg);
138
+ R.info = lg.info.bind(lg);
139
+ R.error = lg.error.bind(lg);
140
+ R.err = lg.err.bind(lg);
145
141
 
146
- return R;
142
+ return R
147
143
  }
148
144
 
149
145
  /**
150
146
  * 获取模块文件名称
147
+ * esm: import.meta.url or cjs: __filename
151
148
  * @param {string} file
152
149
  * @returns
153
150
  */
154
151
  function name(file) {
155
- const baseName = path.basename(file);
156
- return baseName.replace(path.extname(baseName), "");
152
+ // import.meta.url: 'file:///D:/prj/wiajs/req/test/log.t.js'
153
+ file = node_url.fileURLToPath(file); // fileUrl 转成路径
154
+ const baseName = path.basename(file);
155
+ return baseName.replace(path.extname(baseName), '')
157
156
  }
158
157
 
159
158
  exports.default = Log;
package/dist/log.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * wia log v4.3.7
3
- * (c) 2022-2024 Sibyl Yu and contributors
2
+ * wia log v4.3.12
3
+ * (c) 2024-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  (function (global, factory) {
package/dist/log.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * wia log v4.3.7
3
- * (c) 2022-2024 Sibyl Yu and contributors
2
+ * wia log v4.3.12
3
+ * (c) 2024-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  var o,e;o=this,e=function(){"use strict";let o=class{constructor(o){this.m="",this.fn="",this.m=o}getDesc(o){let e="";try{const n=this,{m:s}=n;let t="",c="";if(o.length>1){const e=o.at(-1);"object"==typeof e?({desc:c,fn:t}=e):"string"==typeof e&&(c=e),(c||t)&&(t=t||n.fn,n.fn=t,o.pop())}t=t||n.fn,s&&(c=`${c}[${s}${t?":"+t:""}]`),e=c}catch(o){console.error(`getDesc exp:${o.message}`)}return e}log(...o){const e=this,n=o.at(-1);if(1===o.length&&"object"==typeof n&&n.fn)e.fn="";else{const n=e.getDesc(o);console.log(n,...o)}}debug(...o){const e=this.getDesc(o);e?console.log(e,...o):console.log(...o)}info(...o){const e=this.getDesc(o);e?console.info(e,...o):console.log(...o)}warn(...o){const{desc:e,arg:n}=this.getDesc(o);e?console.warn(e,...n):console.log(...o)}trace(...o){const{desc:e,arg:n}=this.getDesc(o);e?console.trace(e,...n):console.trace(...o)}error(...o){const e=this.getDesc(o);e?console.error(e,...o):console.log(...o)}err(...o){const e=o?.[0];(e instanceof Error||e&&e.message&&e.cause&&e.stack)&&(o[0]={exp:o[0].message}),this.error(...o)}};function e(o){let e="";const n=o.at(-1);return"string"==typeof n&&(e=n,o.pop()),e}function n(...n){const s=n.at(-1);if(1!==n.length||!s?.m){const o=e(n);return void(o?console.log(o,...n):console.log(...n))}const t=new o(s?.m),c=(...o)=>t.log(...o);return c.debug=t.debug.bind(t),c.info=t.info.bind(t),c.warn=t.warn.bind(t),c.info=t.info.bind(t),c.trace=t.trace.bind(t),c.error=t.error.bind(t),c.err=t.err.bind(t),c}return n.err=(...o)=>{const n=e(o),s=o?.[0];(s instanceof Error||s&&s.message&&s.cause&&s.stack)&&(o[0]={exp:o[0].message}),n?console.error(n,...o):console.error(...o)},n.error=(...o)=>{const n=e(o);n?console.error(n,...o):console.error(...o)},n.warn=(...o)=>{const n=e(o);n?console.warn(n,...o):console.warn(...o)},n.info=(...o)=>{const n=e(o);n?console.info(n,...o):console.info(...o)},n.debug=(...o)=>{const n=e(o);n?console.log(n,...o):console.log(...o)},n.trace=(...o)=>{const n=e(o);n?console.trace(n,...o):console.trace(...o)},n},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(o="undefined"!=typeof globalThis?globalThis:o||self).Log=e();
package/dist/log.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  /*!
2
- * wia log v4.3.7
3
- * (c) 2022-2024 Sibyl Yu and contributors
2
+ * wia log v4.3.12
3
+ * (c) 2024-2024 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
6
6
  import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
7
8
  import debug from 'debug';
8
9
 
9
10
  /**
@@ -20,98 +21,93 @@ import debug from 'debug';
20
21
  * warn 和 err 一直打开!
21
22
  */
22
23
  class Log {
23
- /**
24
- * 构造函数
25
- * @param {*} opts {
26
- * pre: 前缀,一般是模块名称,
27
- * env: NODE_DEBUG 环境变量
28
- * }
29
- */
30
- constructor(opts) {
31
- let { env } = opts;
32
- env = env ?? "";
33
- const ds = {}; // debugs
34
- ds.debug = debug(`${env}`);
35
- ds.info = debug(`${env}:info`);
36
- ds.err = debug(`${env}:err`);
37
- ds.warn = debug(`${env}:warn`);
24
+ /**
25
+ * 构造函数
26
+ * @param {*} opts {
27
+ * pre: 前缀,一般是模块名称,
28
+ * env: NODE_DEBUG 环境变量
29
+ * }
30
+ */
31
+ constructor(opts) {
32
+ let {env} = opts;
33
+ env = env ?? '';
34
+ const ds = {}; // debugs
35
+ ds.debug = debug(`${env}`);
36
+ ds.info = debug(`${env}:info`);
37
+ ds.err = debug(`${env}:err`);
38
+ ds.warn = debug(`${env}:warn`);
38
39
 
39
- // 仅最后调用生效,覆盖环境变量
40
- if (ds.debug.enabled) debug.enable("*");
41
- else if (ds.info.enabled)
42
- debug.enable(`${env}:info,${env}:err,${env}:warn`);
43
- else debug.enable(`${env}:err,${env}:warn`);
40
+ // 仅最后调用生效,覆盖环境变量
41
+ if (ds.debug.enabled) debug.enable('*');
42
+ else if (ds.info.enabled) debug.enable(`${env}:info,${env}:err,${env}:warn`);
43
+ else debug.enable(`${env}:err,${env}:warn`);
44
44
 
45
- this.ds = ds;
46
- }
45
+ this.ds = ds;
46
+ }
47
47
 
48
- /**
49
- *
50
- * @param {...any} args
51
- */
52
- debug(...args) {
53
- const first = args?.at(0);
54
- const last = args?.at(-1);
55
- if (typeof first === "string") {
56
- args[0] = `${first}`;
57
- this.ds.debug(...args);
58
- } else if (typeof first === "object" && typeof last === "string")
59
- this.ds.debug(`${last}:%O`, first);
60
- // args[0] = `${this.pre}:${args[0]}`
61
- // console.debug(...args)
62
- // console.debug(this.pre, ...args)
63
- }
48
+ /**
49
+ *
50
+ * @param {...any} args
51
+ */
52
+ debug(...args) {
53
+ const first = args?.at(0);
54
+ const last = args?.at(-1);
55
+ if (typeof first === 'string') {
56
+ args[0] = `${first}`;
57
+ this.ds.debug(...args);
58
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.debug(`${last}:%O`, first);
59
+ // args[0] = `${this.pre}:${args[0]}`
60
+ // console.debug(...args)
61
+ // console.debug(this.pre, ...args)
62
+ }
64
63
 
65
- /**
66
- *
67
- * @param {...any} args
68
- */
69
- error(...args) {
70
- const first = args?.at(0);
71
- const last = args?.at(-1);
72
- if (typeof first === "string") {
73
- args[0] = ` ${first}`;
74
- this.ds.err(...args);
75
- } else if (typeof first === "object" && typeof last === "string")
76
- this.ds.err(` ${last}:%O`, first);
77
- }
64
+ /**
65
+ *
66
+ * @param {...any} args
67
+ */
68
+ error(...args) {
69
+ const first = args?.at(0);
70
+ const last = args?.at(-1);
71
+ if (typeof first === 'string') {
72
+ args[0] = ` ${first}`;
73
+ this.ds.err(...args);
74
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.err(` ${last}:%O`, first);
75
+ }
78
76
 
79
- /**
80
- *
81
- * @param {...any} args
82
- */
83
- err(...args) {
84
- const first = args?.[0];
85
- if (first?.message || first?.msg) {
86
- args[0] = { exp: first.message || first.msg };
87
- if (first?.code) args[0].exp += ` code:${first.code}`;
88
- }
89
- this.error(...args);
90
- }
77
+ /**
78
+ *
79
+ * @param {...any} args
80
+ */
81
+ err(...args) {
82
+ const first = args?.[0];
83
+ if (first?.message || first?.msg) {
84
+ args[0] = {exp: first.message || first.msg};
85
+ if (first?.code) args[0].exp += ` code:${first.code}`;
86
+ }
87
+ this.error(...args);
88
+ }
91
89
 
92
- /**
93
- *
94
- * @param {...any} args
95
- */
96
- warn(...args) {
97
- const first = args?.at(0);
98
- const last = args?.at(-1);
99
- if (typeof first === "string") this.ds.warn(...args);
100
- else if (typeof first === "object" && typeof last === "string")
101
- this.ds.warn(`${last}:%O`, first);
102
- }
90
+ /**
91
+ *
92
+ * @param {...any} args
93
+ */
94
+ warn(...args) {
95
+ const first = args?.at(0);
96
+ const last = args?.at(-1);
97
+ if (typeof first === 'string') this.ds.warn(...args);
98
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.warn(`${last}:%O`, first);
99
+ }
103
100
 
104
- /**
105
- *
106
- * @param {...any} args
107
- */
108
- info(...args) {
109
- const first = args?.at(0);
110
- const last = args?.at(-1);
111
- if (typeof first === "string") this.ds.info(...args);
112
- else if (typeof first === "object" && typeof last === "string")
113
- this.ds.info(`${last}:%O`, first);
114
- }
101
+ /**
102
+ *
103
+ * @param {...any} args
104
+ */
105
+ info(...args) {
106
+ const first = args?.at(0);
107
+ const last = args?.at(-1);
108
+ if (typeof first === 'string') this.ds.info(...args);
109
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.info(`${last}:%O`, first);
110
+ }
115
111
  }
116
112
 
117
113
  /**
@@ -121,35 +117,38 @@ class Log {
121
117
  * returns {pino & (...args) => void}
122
118
  */
123
119
  function log(...args) {
124
- const last = args.at(-1);
120
+ const last = args.at(-1);
125
121
 
126
- // 全局日志
127
- if (args.length !== 1 || !last?.env) return;
122
+ // 全局日志
123
+ if (args.length !== 1 || !last?.env) return
128
124
 
129
- const { env } = last;
130
- // 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
131
- const lg = new Log({ env });
125
+ const {env} = last;
126
+ // 唯一 env 属性,则构造新的 log 实例,这种写法,能被jsDoc识别子属性
127
+ const lg = new Log({env});
132
128
 
133
- /** @param {*} args2 */
134
- const R = (...args2) => lg.debug(...args2);
135
- R.debug = lg.debug.bind(lg);
136
- R.info = lg.info.bind(lg);
137
- R.warn = lg.warn.bind(lg);
138
- R.info = lg.info.bind(lg);
139
- R.error = lg.error.bind(lg);
140
- R.err = lg.err.bind(lg);
129
+ /** @param {*} args2 */
130
+ const R = (...args2) => lg.debug(...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.error = lg.error.bind(lg);
136
+ R.err = lg.err.bind(lg);
141
137
 
142
- return R;
138
+ return R
143
139
  }
144
140
 
145
141
  /**
146
142
  * 获取模块文件名称
143
+ * esm: import.meta.url or cjs: __filename
147
144
  * @param {string} file
148
145
  * @returns
149
146
  */
150
147
  function name(file) {
151
- const baseName = path.basename(file);
152
- return baseName.replace(path.extname(baseName), "");
148
+ // import.meta.url: 'file:///D:/prj/wiajs/req/test/log.t.js'
149
+ file = fileURLToPath(file); // fileUrl 转成路径
150
+ const baseName = path.basename(file);
151
+ return baseName.replace(path.extname(baseName), '')
153
152
  }
154
153
 
155
154
  export { Log as default, log, name };
package/index.js CHANGED
@@ -1 +1 @@
1
- export { default, name, log } from "./lib/node";
1
+ export {default, name, log} from './lib/node.js'
package/lib/browser.js CHANGED
@@ -160,5 +160,4 @@ function getDesc(args) {
160
160
  const desc = getDesc(args);
161
161
  desc ? console.trace(desc, ...args) : console.trace(...args);
162
162
  };
163
- // export default log;
164
- export { log, Log };
163
+ export default log; // export { log, Log };
package/lib/node.js CHANGED
@@ -1,5 +1,6 @@
1
- import path from "node:path";
2
- import debug from "debug";
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import debug from 'debug';
3
4
  /**
4
5
  * debug日志封装,
5
6
  * 使用方法:
@@ -14,54 +15,55 @@ import debug from "debug";
14
15
  * warn 和 err 一直打开!
15
16
  */ export default class Log {
16
17
  /**
17
- * 构造函数
18
- * @param {*} opts {
19
- * pre: 前缀,一般是模块名称,
20
- * env: NODE_DEBUG 环境变量
21
- * }
22
- */ constructor(opts){
18
+ * 构造函数
19
+ * @param {*} opts {
20
+ * pre: 前缀,一般是模块名称,
21
+ * env: NODE_DEBUG 环境变量
22
+ * }
23
+ */ constructor(opts){
23
24
  let { env } = opts;
24
- env = env ?? "";
25
- const ds = {}; // debugs
25
+ env = env ?? '';
26
+ const ds = {} // debugs
27
+ ;
26
28
  ds.debug = debug(`${env}`);
27
29
  ds.info = debug(`${env}:info`);
28
30
  ds.err = debug(`${env}:err`);
29
31
  ds.warn = debug(`${env}:warn`);
30
32
  // 仅最后调用生效,覆盖环境变量
31
- if (ds.debug.enabled) debug.enable("*");
33
+ if (ds.debug.enabled) debug.enable('*');
32
34
  else if (ds.info.enabled) debug.enable(`${env}:info,${env}:err,${env}:warn`);
33
35
  else debug.enable(`${env}:err,${env}:warn`);
34
36
  this.ds = ds;
35
37
  }
36
38
  /**
37
- *
38
- * @param {...any} args
39
- */ debug(...args) {
39
+ *
40
+ * @param {...any} args
41
+ */ debug(...args) {
40
42
  const first = args?.at(0);
41
43
  const last = args?.at(-1);
42
- if (typeof first === "string") {
44
+ if (typeof first === 'string') {
43
45
  args[0] = `${first}`;
44
46
  this.ds.debug(...args);
45
- } else if (typeof first === "object" && typeof last === "string") this.ds.debug(`${last}:%O`, first);
47
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.debug(`${last}:%O`, first);
46
48
  // args[0] = `${this.pre}:${args[0]}`
47
49
  // console.debug(...args)
48
50
  // console.debug(this.pre, ...args)
49
51
  }
50
52
  /**
51
- *
52
- * @param {...any} args
53
- */ error(...args) {
53
+ *
54
+ * @param {...any} args
55
+ */ error(...args) {
54
56
  const first = args?.at(0);
55
57
  const last = args?.at(-1);
56
- if (typeof first === "string") {
58
+ if (typeof first === 'string') {
57
59
  args[0] = ` ${first}`;
58
60
  this.ds.err(...args);
59
- } else if (typeof first === "object" && typeof last === "string") this.ds.err(` ${last}:%O`, first);
61
+ } else if (typeof first === 'object' && typeof last === 'string') this.ds.err(` ${last}:%O`, first);
60
62
  }
61
63
  /**
62
- *
63
- * @param {...any} args
64
- */ err(...args) {
64
+ *
65
+ * @param {...any} args
66
+ */ err(...args) {
65
67
  const first = args?.[0];
66
68
  if (first?.message || first?.msg) {
67
69
  args[0] = {
@@ -72,22 +74,22 @@ import debug from "debug";
72
74
  this.error(...args);
73
75
  }
74
76
  /**
75
- *
76
- * @param {...any} args
77
- */ warn(...args) {
77
+ *
78
+ * @param {...any} args
79
+ */ warn(...args) {
78
80
  const first = args?.at(0);
79
81
  const last = args?.at(-1);
80
- if (typeof first === "string") this.ds.warn(...args);
81
- else if (typeof first === "object" && typeof last === "string") this.ds.warn(`${last}:%O`, first);
82
+ if (typeof first === 'string') this.ds.warn(...args);
83
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.warn(`${last}:%O`, first);
82
84
  }
83
85
  /**
84
- *
85
- * @param {...any} args
86
- */ info(...args) {
86
+ *
87
+ * @param {...any} args
88
+ */ info(...args) {
87
89
  const first = args?.at(0);
88
90
  const last = args?.at(-1);
89
- if (typeof first === "string") this.ds.info(...args);
90
- else if (typeof first === "object" && typeof last === "string") this.ds.info(`${last}:%O`, first);
91
+ if (typeof first === 'string') this.ds.info(...args);
92
+ else if (typeof first === 'object' && typeof last === 'string') this.ds.info(`${last}:%O`, first);
91
93
  }
92
94
  }
93
95
  /**
@@ -115,10 +117,14 @@ import debug from "debug";
115
117
  }
116
118
  /**
117
119
  * 获取模块文件名称
120
+ * esm: import.meta.url or cjs: __filename
118
121
  * @param {string} file
119
122
  * @returns
120
123
  */ function name(file) {
124
+ // import.meta.url: 'file:///D:/prj/wiajs/req/test/log.t.js'
125
+ file = fileURLToPath(file) // fileUrl 转成路径
126
+ ;
121
127
  const baseName = path.basename(file);
122
- return baseName.replace(path.extname(baseName), "");
128
+ return baseName.replace(path.extname(baseName), '');
123
129
  }
124
130
  export { name, log };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wiajs/log",
3
3
  "description": "Lightweight debugging utility for Node.js and the browser",
4
- "version": "4.3.10",
4
+ "version": "4.3.12",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "browser": "./lib/browser.js",