@qubit-ltd/logging 1.4.4

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.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +224 -0
  3. package/README.zh_CN.md +200 -0
  4. package/dist/logging.cjs +1338 -0
  5. package/dist/logging.cjs.map +1 -0
  6. package/dist/logging.iife.js +1342 -0
  7. package/dist/logging.iife.js.map +1 -0
  8. package/dist/logging.min.cjs +1 -0
  9. package/dist/logging.min.cjs.map +1 -0
  10. package/dist/logging.min.iife.js +1 -0
  11. package/dist/logging.min.iife.js.map +1 -0
  12. package/dist/logging.min.mjs +1 -0
  13. package/dist/logging.min.mjs.map +1 -0
  14. package/dist/logging.mjs +1330 -0
  15. package/dist/logging.mjs.map +1 -0
  16. package/doc/api/Logger.html +3352 -0
  17. package/doc/api/fonts/OpenSans-Bold-webfont.eot +0 -0
  18. package/doc/api/fonts/OpenSans-Bold-webfont.svg +1838 -0
  19. package/doc/api/fonts/OpenSans-Bold-webfont.woff +0 -0
  20. package/doc/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  21. package/doc/api/fonts/OpenSans-BoldItalic-webfont.svg +1838 -0
  22. package/doc/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  23. package/doc/api/fonts/OpenSans-Italic-webfont.eot +0 -0
  24. package/doc/api/fonts/OpenSans-Italic-webfont.svg +1838 -0
  25. package/doc/api/fonts/OpenSans-Italic-webfont.woff +0 -0
  26. package/doc/api/fonts/OpenSans-Light-webfont.eot +0 -0
  27. package/doc/api/fonts/OpenSans-Light-webfont.svg +1839 -0
  28. package/doc/api/fonts/OpenSans-Light-webfont.woff +0 -0
  29. package/doc/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  30. package/doc/api/fonts/OpenSans-LightItalic-webfont.svg +1843 -0
  31. package/doc/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  32. package/doc/api/fonts/OpenSans-Regular-webfont.eot +0 -0
  33. package/doc/api/fonts/OpenSans-Regular-webfont.svg +1839 -0
  34. package/doc/api/fonts/OpenSans-Regular-webfont.woff +0 -0
  35. package/doc/api/fonts/OpenSans-Semibold-webfont.eot +0 -0
  36. package/doc/api/fonts/OpenSans-Semibold-webfont.svg +1838 -0
  37. package/doc/api/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  38. package/doc/api/fonts/OpenSans-Semibold-webfont.woff +0 -0
  39. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  40. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.svg +1838 -0
  41. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  42. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  43. package/doc/api/global.html +787 -0
  44. package/doc/api/index.html +257 -0
  45. package/doc/api/scripts/linenumber.js +34 -0
  46. package/doc/api/scripts/prettify/Apache-License-2.0.txt +202 -0
  47. package/doc/api/scripts/prettify/lang-css.js +2 -0
  48. package/doc/api/scripts/prettify/prettify.js +28 -0
  49. package/doc/api/styles/jsdoc-default.css +699 -0
  50. package/doc/api/styles/prettify-jsdoc.css +120 -0
  51. package/doc/api/styles/prettify-tomorrow.css +141 -0
  52. package/doc/logging.min.visualization.html +4949 -0
  53. package/doc/logging.visualization.html +4949 -0
  54. package/package.json +103 -0
@@ -0,0 +1,1330 @@
1
+ function _classCallCheck(a, n) {
2
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
3
+ }
4
+
5
+ function _typeof(o) {
6
+ "@babel/helpers - typeof";
7
+
8
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
9
+ return typeof o;
10
+ } : function (o) {
11
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
12
+ }, _typeof(o);
13
+ }
14
+
15
+ function toPrimitive(t, r) {
16
+ if ("object" != _typeof(t) || !t) return t;
17
+ var e = t[Symbol.toPrimitive];
18
+ if (void 0 !== e) {
19
+ var i = e.call(t, r);
20
+ if ("object" != _typeof(i)) return i;
21
+ throw new TypeError("@@toPrimitive must return a primitive value.");
22
+ }
23
+ return (String )(t);
24
+ }
25
+
26
+ function toPropertyKey(t) {
27
+ var i = toPrimitive(t, "string");
28
+ return "symbol" == _typeof(i) ? i : i + "";
29
+ }
30
+
31
+ function _defineProperties(e, r) {
32
+ for (var t = 0; t < r.length; t++) {
33
+ var o = r[t];
34
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, toPropertyKey(o.key), o);
35
+ }
36
+ }
37
+ function _createClass(e, r, t) {
38
+ return _defineProperties(e.prototype, r), _defineProperties(e, t), Object.defineProperty(e, "prototype", {
39
+ writable: !1
40
+ }), e;
41
+ }
42
+
43
+ ////////////////////////////////////////////////////////////////////////////////
44
+ //
45
+ // Copyright (c) 2022 - 2023.
46
+ // Haixing Hu, Qubit Co. Ltd.
47
+ //
48
+ // All rights reserved.
49
+ //
50
+ ////////////////////////////////////////////////////////////////////////////////
51
+
52
+ /**
53
+ * Predefined logging levels.
54
+ *
55
+ * @author Haixing Hu
56
+ */
57
+ var LOGGING_LEVELS = {
58
+ TRACE: 0,
59
+ DEBUG: 1,
60
+ INFO: 2,
61
+ WARN: 3,
62
+ ERROR: 4,
63
+ NONE: 5
64
+ };
65
+
66
+ /**
67
+ * Checks the validity of an appender.
68
+ *
69
+ * @param {Object} appender
70
+ * The appender to be checked. If it is invalid, an `Error` will be thrown.
71
+ * @author Haixing Hu
72
+ * @private
73
+ */
74
+ function checkAppender(appender) {
75
+ if (appender === null || _typeof(appender) !== 'object') {
76
+ throw new TypeError('The appender for a logger must be a non-null object.');
77
+ }
78
+ for (var level in LOGGING_LEVELS) {
79
+ // NOTE: do NOT use Object.hasOwn() because it has a lot of compatibility problems
80
+ if (Object.prototype.hasOwnProperty.call(LOGGING_LEVELS, level) && level !== 'NONE') {
81
+ var methodName = level.toLowerCase();
82
+ var method = appender[methodName];
83
+ if (typeof method !== 'function') {
84
+ throw new Error("The appender of this logger has no ".concat(methodName, "() method."));
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ ////////////////////////////////////////////////////////////////////////////////
91
+ //
92
+ // Copyright (c) 2022 - 2023.
93
+ // Haixing Hu, Qubit Co. Ltd.
94
+ //
95
+ // All rights reserved.
96
+ //
97
+ ////////////////////////////////////////////////////////////////////////////////
98
+
99
+ /**
100
+ * Checks the validity of a logging level.
101
+ *
102
+ * @param {String} level
103
+ * The logging level to be checked. If it is invalid, an `Error` will be
104
+ * thrown.
105
+ * @private
106
+ */
107
+ function checkLoggingLevel(level) {
108
+ if (typeof level !== 'string') {
109
+ throw new TypeError('The logging level must be a string.');
110
+ }
111
+ if (LOGGING_LEVELS[level] === undefined) {
112
+ throw new RangeError("Unknown logging level \"".concat(level, "\". ") + "Possible values are\uFF1A".concat(JSON.stringify(Object.keys(LOGGING_LEVELS)), "."));
113
+ }
114
+ }
115
+
116
+ ////////////////////////////////////////////////////////////////////////////////
117
+ //
118
+ // Copyright (c) 2022 - 2023.
119
+ // Haixing Hu, Qubit Co. Ltd.
120
+ //
121
+ // All rights reserved.
122
+ //
123
+ ////////////////////////////////////////////////////////////////////////////////
124
+
125
+ /**
126
+ * Convert a string to uppercase.
127
+ *
128
+ * @param {any} value
129
+ * The value to be converted. If it is not a string, it will be returned directly.
130
+ * @return {any|string}
131
+ * The converted string, or the original value if it is not a string.
132
+ * @author Haixing Hu
133
+ * @private
134
+ */
135
+ function upperCaseString(value) {
136
+ if (typeof value !== 'string' && !(value instanceof String)) {
137
+ return value;
138
+ }
139
+ return value.toUpperCase();
140
+ }
141
+
142
+ ////////////////////////////////////////////////////////////////////////////////
143
+ //
144
+ // Copyright (c) 2022 - 2024.
145
+ // Haixing Hu, Qubit Co. Ltd.
146
+ //
147
+ // All rights reserved.
148
+ //
149
+ ////////////////////////////////////////////////////////////////////////////////
150
+
151
+ /**
152
+ * Determines whether a value is a string.
153
+ *
154
+ * A value is a string if it is a string or a `String` object.
155
+ *
156
+ * @param {any} value
157
+ * The value to be checked.
158
+ * @return {boolean}
159
+ * `true` if the value is a string; `false` otherwise.
160
+ * @author Haixing Hu
161
+ * @private
162
+ */
163
+ function isString(value) {
164
+ return typeof value === 'string' || value instanceof String;
165
+ }
166
+
167
+ ////////////////////////////////////////////////////////////////////////////////
168
+ //
169
+ // Copyright (c) 2022 - 2024.
170
+ // Haixing Hu, Qubit Co. Ltd.
171
+ //
172
+ // All rights reserved.
173
+ //
174
+ ////////////////////////////////////////////////////////////////////////////////
175
+
176
+ /**
177
+ * Gets the engine name of the current browser.
178
+ *
179
+ * @return {string}
180
+ * The engine name of the current browser.
181
+ * @author Haixing Hu
182
+ * @private
183
+ */
184
+ function getBrowserEngine() {
185
+ var userAgent = window.navigator.userAgent;
186
+ if (/Gecko\/\d/i.test(userAgent) && !/like Gecko/i.test(userAgent)) {
187
+ return 'Gecko'; // Firefox and other Gecko-based browsers
188
+ } else if (/Chrome|Chromium|Edg/i.test(userAgent)) {
189
+ return 'Blink'; // Chrome, Edge and other Blink-based browsers
190
+ } else if (/(Apple)?WebKit/i.test(userAgent) && !/Chrome/i.test(userAgent)) {
191
+ return 'WebKit'; // Safari and other WebKit-based browsers
192
+ } else if (/Trident/i.test(userAgent)) {
193
+ return 'Trident'; // Internet Explorer and other Trident-based browsers
194
+ } else if (/Presto/i.test(userAgent)) {
195
+ return 'Presto'; // Opera and other Presto-based browsers
196
+ } else {
197
+ return 'Unknown';
198
+ }
199
+ }
200
+
201
+ function _arrayLikeToArray$1(r, a) {
202
+ (null == a || a > r.length) && (a = r.length);
203
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
204
+ return n;
205
+ }
206
+
207
+ function _arrayWithoutHoles(r) {
208
+ if (Array.isArray(r)) return _arrayLikeToArray$1(r);
209
+ }
210
+
211
+ function _iterableToArray(r) {
212
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
213
+ }
214
+
215
+ function _unsupportedIterableToArray$1(r, a) {
216
+ if (r) {
217
+ if ("string" == typeof r) return _arrayLikeToArray$1(r, a);
218
+ var t = {}.toString.call(r).slice(8, -1);
219
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0;
220
+ }
221
+ }
222
+
223
+ function _nonIterableSpread() {
224
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
225
+ }
226
+
227
+ function _toConsumableArray(r) {
228
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$1(r) || _nonIterableSpread();
229
+ }
230
+
231
+ ////////////////////////////////////////////////////////////////////////////////
232
+ //
233
+ // Copyright (c) 2022 - 2024.
234
+ // Haixing Hu, Qubit Co. Ltd.
235
+ //
236
+ // All rights reserved.
237
+ //
238
+ ////////////////////////////////////////////////////////////////////////////////
239
+
240
+ /**
241
+ * Gets the logging prefix for a logger.
242
+ *
243
+ * @param {Logger} logger
244
+ * The logger object.
245
+ * @param {string} level
246
+ * The logging level.
247
+ * @return {string}
248
+ * The logging prefix.
249
+ * @author Haixing Hu
250
+ * @private
251
+ */
252
+ function getLoggingPrefix(logger, level) {
253
+ var prefix = "[".concat(level, "] ");
254
+ if (logger._name) {
255
+ prefix += "".concat(logger._name, " - ");
256
+ }
257
+ return prefix;
258
+ }
259
+
260
+ function fixFirstArgument(prefix, args) {
261
+ if (args.length === 0) {
262
+ return [prefix];
263
+ } else if (isString(args[0])) {
264
+ args[0] = prefix + args[0];
265
+ return args;
266
+ } else {
267
+ return [prefix].concat(_toConsumableArray(args));
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Binds a logging method of a logger with an array function.
273
+ *
274
+ * We use the simple arrow function to preserve the actual source code location
275
+ * where the logging method is called.
276
+ *
277
+ * This works for the Safari browser.
278
+ *
279
+ * @param {Logger} logger
280
+ * The logger object whose method to be bound.
281
+ * @param {string} method
282
+ * The name of the logging method to be bound.
283
+ * @param {string} level
284
+ * The logging level of the method.
285
+ * @param {object} appender
286
+ * The appender object which provides underlying logging operation.
287
+ * @author Haixing Hu
288
+ * @private
289
+ */
290
+ function bindWithArrowFunction(logger, method, level, appender) {
291
+ // Add a prefix to the message, which contains the logging level
292
+ // and the name of the logger. Since the prefix use the recursive
293
+ // string substitution pattern '%s', only some browsers support it.
294
+ var prefix = getLoggingPrefix(logger, level);
295
+ // For Safari, the recursive string substitution pattern '%s' is not
296
+ // supported. So we add the prefix to the first argument of the message
297
+ // manually. We use the arrow function to preserve the actual source
298
+ // code location where the logging method is called.
299
+ logger[method] = function () {
300
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
301
+ args[_key] = arguments[_key];
302
+ }
303
+ return appender[method].apply(appender, _toConsumableArray(fixFirstArgument(prefix, args)));
304
+ };
305
+ }
306
+
307
+ ////////////////////////////////////////////////////////////////////////////////
308
+ //
309
+ // Copyright (c) 2022 - 2024.
310
+ // Haixing Hu, Qubit Co. Ltd.
311
+ //
312
+ // All rights reserved.
313
+ //
314
+ ////////////////////////////////////////////////////////////////////////////////
315
+
316
+ /**
317
+ * Binds a logging method of a logger with the stack of an `Error` object
318
+ * with logging prefix.
319
+ *
320
+ * We use the `Function.prototype.bind` to preserve the actual source code
321
+ * location where the logging method is called.
322
+ *
323
+ * See: https://stackoverflow.com/questions/13815640/a-proper-wrapper-for-console-log-with-correct-line-number
324
+ *
325
+ * Some browsers do not support the recursive string substitution pattern '%s'
326
+ * in the `console` object. For those browsers, we have no way to add a prefix
327
+ * to the logging message.
328
+ *
329
+ * @param {Logger} logger
330
+ * The logger object whose method to be bound.
331
+ * @param {string} method
332
+ * The name of the logging method to be bound.
333
+ * @param {string} level
334
+ * The logging level of the method.
335
+ * @param {object} appender
336
+ * The appender object which provides underlying logging operation.
337
+ * @author Haixing Hu
338
+ * @private
339
+ */
340
+ function bindWithoutPrefix(logger, method, level, appender) {
341
+ logger[method] = Function.prototype.bind.call(appender[method], appender);
342
+ }
343
+
344
+ ////////////////////////////////////////////////////////////////////////////////
345
+ //
346
+ // Copyright (c) 2022 - 2024.
347
+ // Haixing Hu, Qubit Co. Ltd.
348
+ //
349
+ // All rights reserved.
350
+ //
351
+ ////////////////////////////////////////////////////////////////////////////////
352
+
353
+ /**
354
+ * Binds a logging method of a logger with the stack of an `Error` object.
355
+ *
356
+ * We use the `Function.prototype.bind` to preserve the actual source code
357
+ * location where the logging method is called.
358
+ *
359
+ * See: https://stackoverflow.com/questions/13815640/a-proper-wrapper-for-console-log-with-correct-line-number
360
+ *
361
+ * @param {Logger} logger
362
+ * The logger object whose method to be bound.
363
+ * @param {string} method
364
+ * The name of the logging method to be bound.
365
+ * @param {string} level
366
+ * The logging level of the method.
367
+ * @param {object} appender
368
+ * The appender object which provides underlying logging operation.
369
+ * @author Haixing Hu
370
+ * @private
371
+ */
372
+ function bindWithFunctionBind(logger, method, level, appender) {
373
+ // Add a prefix to the message, which contains the logging level
374
+ // and the name of the logger. Since the prefix use the recursive
375
+ // string substitution pattern '%s', only some browsers support it.
376
+ var prefix = getLoggingPrefix(logger, level);
377
+ // Note that we add a string substitution pattern '%s' to the end of
378
+ // the prefix, since according to the specification of the `console`,
379
+ // the string substitution is taken on the first argument **recursively**.
380
+ // See: https://stackoverflow.com/questions/75160241/what-order-does-console-log-with-multiple-arguments-and-multiple-s-substitu#answer-75167070
381
+ // https://console.spec.whatwg.org/#logger
382
+ // https://console.spec.whatwg.org/#formatter
383
+ //
384
+ // But the `console` object of the Node.js does not support the recursive
385
+ // string substitution.
386
+ // See: https://nodejs.org/api/console.html#console_console_log_data_args
387
+ // and https://nodejs.org/api/util.html#utilformatformat-args
388
+ logger[method] = Function.prototype.bind.call(appender[method], appender, "".concat(prefix, "%s"));
389
+ }
390
+
391
+ ////////////////////////////////////////////////////////////////////////////////
392
+ //
393
+ // Copyright (c) 2022 - 2023.
394
+ // Haixing Hu, Qubit Co. Ltd.
395
+ //
396
+ // All rights reserved.
397
+ //
398
+ ////////////////////////////////////////////////////////////////////////////////
399
+
400
+ /**
401
+ * A no-operation function.
402
+ *
403
+ * @author Haixing Hu
404
+ * @private
405
+ */
406
+ var NOOP = function NOOP() {};
407
+
408
+ /**
409
+ * Rebinds all logging implementation methods to the corresponding logging
410
+ * methods of the appender.
411
+ *
412
+ * @param {Logger} logger
413
+ * The logger whose logging methods will be rebind to the corresponding
414
+ * logging methods of the appender.
415
+ * @param {string} level
416
+ * The target logging level. All logging methods belows this target logging
417
+ * level will be bind to a no-op function, while all logging methods above
418
+ * or equal to this target logging level will be bind to the corresponding
419
+ * logging methods of the appender. This argument should be a valid
420
+ * logging level. The function do not check the validity of this argument.
421
+ * @param {object} appender
422
+ * The appender whose logging methods will be bound to the corresponding
423
+ * logging methods of this logger. This argument should be a valid appender.
424
+ * The function do not check the validity of this argument.
425
+ * @author Haixing Hu
426
+ * @private
427
+ */
428
+ function bindLoggingMethods(logger, level, appender) {
429
+ var target = LOGGING_LEVELS[level];
430
+ for (var _level in LOGGING_LEVELS) {
431
+ // NOTE: do NOT use Object.hasOwn() because it has a lot of compatibility problems
432
+ if (Object.prototype.hasOwnProperty.call(LOGGING_LEVELS, _level) && _level !== 'NONE') {
433
+ var m = _level.toLowerCase();
434
+ if (LOGGING_LEVELS[_level] < target) {
435
+ // binds the private logging method of this object to no-op
436
+ logger[m] = NOOP;
437
+ } else {
438
+ // binds the private logging method of this object to the
439
+ // corresponding logging method of this.appender.
440
+ var engine = getBrowserEngine();
441
+ switch (engine) {
442
+ case 'Blink':
443
+ // Chrome, Edge and other Blink-based browsers
444
+ bindWithFunctionBind(logger, m, _level, appender);
445
+ break;
446
+ case 'WebKit':
447
+ // Safari and other WebKit-based browsers
448
+ bindWithArrowFunction(logger, m, _level, appender);
449
+ break;
450
+ case 'Gecko': // Firefox and other Gecko-based browsers
451
+ case 'Trident': // Internet Explorer and other Trident-based browsers
452
+ case 'Presto': // Opera and other Presto-based browsers
453
+ default:
454
+ bindWithoutPrefix(logger, m, _level, appender);
455
+ // bindWithErrorStack(logger, m, level, appender);
456
+ // bindWithProxy(logger, m, level, appender);
457
+ break;
458
+ }
459
+ }
460
+ }
461
+ }
462
+ }
463
+
464
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
465
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
466
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
467
+
468
+ /**
469
+ * The factory value of the Logger class's default logging level,
470
+ * which is `DEBUG`.
471
+ *
472
+ * @type {string}
473
+ */
474
+ var FACTORY_DEFAULT_LEVEL = 'DEBUG';
475
+
476
+ /**
477
+ * The factory value of the Logger class's default log appender, which is
478
+ * the standard output pipe of the console.
479
+ *
480
+ * @type {Console}
481
+ */
482
+ var FACTORY_DEFAULT_APPENDER = console;
483
+
484
+ /**
485
+ * The default logging level of all `Logger` instances, which is `DEBUG`.
486
+ *
487
+ * @private
488
+ * @author Haixing Hu
489
+ */
490
+ var __defaultLevel = FACTORY_DEFAULT_LEVEL;
491
+
492
+ /**
493
+ * The default log appender of all `Logger` instances, which is the standard
494
+ * output pipe of the console.
495
+ *
496
+ * @private
497
+ * @author Haixing Hu
498
+ */
499
+ var __defaultAppender = FACTORY_DEFAULT_APPENDER;
500
+
501
+ /**
502
+ * The map of all `Logger` instances.
503
+ *
504
+ * This value maps the name of a `Logger` instance to its instance.
505
+ *
506
+ * @type {Map<String, Logger>}
507
+ * @private
508
+ * @author Haixing Hu
509
+ */
510
+ var __loggerMap = new Map();
511
+
512
+ /**
513
+ * The map of all logging levels.
514
+ *
515
+ * This value maps the name of a `Logger` instance to its logging level.
516
+ *
517
+ * @type {Map<String, String>}
518
+ * @private
519
+ * @author Haixing Hu
520
+ */
521
+ var __levelMap = new Map();
522
+
523
+ /**
524
+ * Indicates whether the `Logger` instance is under internal constructing.
525
+ *
526
+ * Many other languages include the capability to mark a constructor as private,
527
+ * which prevents the class from being instantiated outside the class itself,
528
+ * such taht you can only use static factory methods that create instances, or
529
+ * not be able to create instances at all. JavaScript does not have a native way
530
+ * to do this, but it can be accomplished by using a private static flag.
531
+ *
532
+ * @type {boolean}
533
+ * @private
534
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields#simulating_private_constructors
535
+ * @author Haixing Hu
536
+ */
537
+ var __isInternalConstructing = false;
538
+
539
+ /**
540
+ * A simple logging class.
541
+ *
542
+ * A `Logger` object provides the following logging methods:
543
+ *
544
+ * - `Logger.trace(message, arg1, arg2, ...)`: Outputs a log message with the `TRACE` level.
545
+ * - `Logger.debug(message, arg1, arg2, ...)`: Outputs a log message with the `DEBUG` level.
546
+ * - `Logger.info(message, arg1, arg2, ...)`: Outputs a log message with the `INFO` level.
547
+ * - `Logger.warn(message, arg1, arg2, ...)`: Outputs a log message with the `WARN` level.
548
+ * - `Logger.error(message, arg1, arg2, ...)`: Outputs a log message with the `ERROR` level.
549
+ * - `Logger.log(level, message, arg1, arg2, ...)`: Outputs a log message with the specified level.
550
+ *
551
+ * The message argument of those logging methods supports the following
552
+ * substitution patterns:
553
+ *
554
+ * - `%o` or `%O`: Outputs a JavaScript object. Clicking the object name opens
555
+ * more information about it in the inspector.
556
+ * - `%d` or `%i`: Outputs an integer. Number formatting is supported, for
557
+ * example `logger.info('Foo %.2d', 1.1)` will output the number as two
558
+ * significant figures with a leading 0: `Foo 01`.
559
+ * - `%s`: Outputs a string.
560
+ * - `%f`: Outputs a floating-point value. Formatting is supported, for example
561
+ * `logger.debug("Foo %.2f", 1.1)` will output the number to 2 decimal
562
+ * places: `Foo 1.10`.
563
+ *
564
+ * @author Haixing Hu
565
+ */
566
+ var Logger = /*#__PURE__*/function () {
567
+ /**
568
+ * Construct a log object.
569
+ *
570
+ * **NOTE**: Do NOT call this constructor directly. Use the static method
571
+ * `Logger.getLogger()` instead.
572
+ *
573
+ * @param {string} name
574
+ * The optional name of this logger. The default value of this argument
575
+ * is an empty string.
576
+ * @param {object} appender
577
+ * Optional, indicating the content output pipe of the log. This object
578
+ * must provide `trace`, `debug`, `info`, `warn` and `error` methods.
579
+ * The default value of this argument is `Logger.getDefaultAppender()`.
580
+ * @param {string} level
581
+ * Optional, indicating the log level of this object. The default value
582
+ * of this argument is `Logger.getDefaultLevel()`.
583
+ * @see Logger.getLogger
584
+ */
585
+ function Logger(name, appender, level) {
586
+ _classCallCheck(this, Logger);
587
+ if (!__isInternalConstructing) {
588
+ throw new Error('The `Logger` instance can only be constructed by the ' + 'static method `Logger.getLogger()`.');
589
+ }
590
+ if (appender === undefined) {
591
+ appender = __defaultAppender;
592
+ } else {
593
+ checkAppender(appender);
594
+ }
595
+ if (level === undefined) {
596
+ var _levelMap$get;
597
+ level = (_levelMap$get = __levelMap.get(name)) !== null && _levelMap$get !== void 0 ? _levelMap$get : __defaultLevel;
598
+ } else {
599
+ level = upperCaseString(level);
600
+ checkLoggingLevel(level);
601
+ }
602
+ this._name = name;
603
+ this._level = level;
604
+ this._appender = appender;
605
+ bindLoggingMethods(this, level, appender);
606
+ __levelMap.set(name, level);
607
+ }
608
+
609
+ /**
610
+ * Get the name of this logger.
611
+ *
612
+ * @returns {string}
613
+ * The name of this logger.
614
+ */
615
+ return _createClass(Logger, [{
616
+ key: "getName",
617
+ value: function getName() {
618
+ return this._name;
619
+ }
620
+
621
+ /**
622
+ * Get the appender of this logger.
623
+ *
624
+ * @return {object}
625
+ * The appender of this logger.
626
+ */
627
+ }, {
628
+ key: "getAppender",
629
+ value: function getAppender() {
630
+ return this._appender;
631
+ }
632
+
633
+ /**
634
+ * Set up a new Appender.
635
+ *
636
+ * @param {object} appender
637
+ * The new Appender serves as the content output pipeline of the log.
638
+ * This object must provide `trace`, `debug`, `info`, `warn` and `error`
639
+ * methods.
640
+ */
641
+ }, {
642
+ key: "setAppender",
643
+ value: function setAppender(appender) {
644
+ checkAppender(appender);
645
+ bindLoggingMethods(this, this._level, appender);
646
+ this._appender = appender;
647
+ }
648
+
649
+ /**
650
+ * Get the logging level of this logger.
651
+ *
652
+ * @return {string}
653
+ * The logging level of this logger. Possible return values are `TRACE`,
654
+ * `DEBUG`, `INFO`, `WARN`, `ERROR`, and `NONE`.
655
+ */
656
+ }, {
657
+ key: "getLevel",
658
+ value: function getLevel() {
659
+ return this._level;
660
+ }
661
+
662
+ /**
663
+ * Set the logging level of this logger.
664
+ *
665
+ * @param {string} level
666
+ * The new logging level. The allowed levels are `TRACE`, `DEBUG`, `INFO`,
667
+ * `WARN`, `ERROR`, and `NONE`. Lowercase letters are also allowed.
668
+ */
669
+ }, {
670
+ key: "setLevel",
671
+ value: function setLevel(level) {
672
+ level = upperCaseString(level);
673
+ checkLoggingLevel(level);
674
+ bindLoggingMethods(this, level, this._appender);
675
+ this._level = level;
676
+ }
677
+
678
+ /**
679
+ * Disable this logging object.
680
+ */
681
+ }, {
682
+ key: "disable",
683
+ value: function disable() {
684
+ bindLoggingMethods(this, 'NONE', this._appender);
685
+ }
686
+
687
+ /**
688
+ * Enable this logging object.
689
+ */
690
+ }, {
691
+ key: "enable",
692
+ value: function enable() {
693
+ bindLoggingMethods(this, this._level, this._appender);
694
+ }
695
+
696
+ /**
697
+ * Enable or disable this log object.
698
+ *
699
+ * @param {boolean} enabled
700
+ * Whether to enable this log object.
701
+ */
702
+ }, {
703
+ key: "setEnabled",
704
+ value: function setEnabled(enabled) {
705
+ if (enabled) {
706
+ this.enable();
707
+ } else {
708
+ this.disable();
709
+ }
710
+ }
711
+
712
+ /**
713
+ * Logs a message in the specified logging level.
714
+ *
715
+ * @param {string} level
716
+ * the logging level.
717
+ * @param {string} message
718
+ * the message or message template, which may contain zero or more
719
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
720
+ * @param {array} args
721
+ * the array of arguments used to format the message.
722
+ */
723
+ }, {
724
+ key: "log",
725
+ value: function log(level, message) {
726
+ var levelName = upperCaseString(level);
727
+ if (LOGGING_LEVELS[levelName] !== undefined && LOGGING_LEVELS[levelName] >= LOGGING_LEVELS[this._level]) {
728
+ var method = levelName.toLowerCase();
729
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
730
+ args[_key - 2] = arguments[_key];
731
+ }
732
+ this[method].apply(this, [message].concat(args));
733
+ }
734
+ }
735
+
736
+ /**
737
+ * Logs a message in the `TRACE` level.
738
+ *
739
+ * @param {string} message
740
+ * the message or message template, which may contain zero or more
741
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
742
+ * @param {array} args
743
+ * the array of arguments used to format the message.
744
+ * @private
745
+ */
746
+ // eslint-disable-next-line no-unused-vars
747
+ }, {
748
+ key: "trace",
749
+ value: function trace(message) {}
750
+
751
+ /**
752
+ * Logs a message in the `DEBUG` level.
753
+ *
754
+ * @param {string} message
755
+ * the message or message template, which may contain zero or more
756
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
757
+ * @param {array} args
758
+ * the array of arguments used to format the message.
759
+ * @private
760
+ */
761
+ // eslint-disable-next-line no-unused-vars
762
+ }, {
763
+ key: "debug",
764
+ value: function debug(message) {}
765
+
766
+ /**
767
+ * Logs a message in the `INFO` level.
768
+ *
769
+ * @param {string} message
770
+ * the message or message template, which may contain zero or more
771
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
772
+ * @param {array} args
773
+ * the array of arguments used to format the message.
774
+ * @private
775
+ */
776
+ // eslint-disable-next-line no-unused-vars
777
+ }, {
778
+ key: "info",
779
+ value: function info(message) {}
780
+
781
+ /**
782
+ * Logs a message in the `WARN` level.
783
+ *
784
+ * @param {string} message
785
+ * the message or message template, which may contain zero or more
786
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
787
+ * @param {array} args
788
+ * the array of arguments used to format the message.
789
+ * @private
790
+ */
791
+ // eslint-disable-next-line no-unused-vars
792
+ }, {
793
+ key: "warn",
794
+ value: function warn(message) {}
795
+
796
+ /**
797
+ * Logs a message in the `ERROR` level.
798
+ *
799
+ * @param {string} message
800
+ * the message or message template, which may contain zero or more
801
+ * substitution patterns, e.g., '%o', '%s', '%d', '%f', ..., etc.
802
+ * @param {array} args
803
+ * the array of arguments used to format the message.
804
+ * @private
805
+ */
806
+ // eslint-disable-next-line no-unused-vars
807
+ }, {
808
+ key: "error",
809
+ value: function error(message) {}
810
+ }], [{
811
+ key: "getLogger",
812
+ value:
813
+ /**
814
+ * Gets the `Logger` instance of the specified name, or constructs a new
815
+ * `Logger` instance if it does not exist.
816
+ *
817
+ * @param {string} name
818
+ * The name of the `Logger` instance to be retrieved.
819
+ * @param {Object} options
820
+ * The optional options of the `Logger` instance to be retrieved. This
821
+ * option object may have the following properties:
822
+ * - `appender: object`: the specified content output pipe of the log.
823
+ * This object must provide `trace`, `debug`, `info`, `warn` and `error`
824
+ * methods. If this option is not provided, the appender of the existing
825
+ * `Logger` instance will not be changed, and the default appender
826
+ * will be used to construct a new `Logger` instance if it does not exist.
827
+ * - `level: string`: the logging level of the `Logger` instance to be
828
+ * retrieved. The allowed levels are `TRACE`, `DEBUG`, `INFO`, `WARN`,
829
+ * `ERROR`, and `NONE`. Lowercase letters are also allowed. If this
830
+ * option is not provided, the logging level of the existing `Logger`
831
+ * instance will not be changed, and the default logging level will be
832
+ * used to construct a new `Logger` instance if it does not exist.
833
+ * @return {Logger}
834
+ * The `Logger` instance of the specified name, which either be the
835
+ * existing one or a newly constructed one.
836
+ */
837
+ function getLogger() {
838
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
839
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
840
+ if (!isString(name)) {
841
+ throw new TypeError('The name of a logger must be a string, and empty string is allowed.');
842
+ }
843
+ var theName = String(name); // make sure the name is a primitive string
844
+ var logger = __loggerMap.get(theName);
845
+ if (logger === undefined) {
846
+ // sets the internally constructing flag before constructing a instance
847
+ __isInternalConstructing = true;
848
+ logger = new Logger(theName, options.appender, options.level);
849
+ // clear the internally constructing flag after constructing the new instance
850
+ __isInternalConstructing = false;
851
+ __loggerMap.set(theName, logger);
852
+ } else {
853
+ if (options.appender !== undefined) {
854
+ logger.setAppender(options.appender);
855
+ }
856
+ if (options.level !== undefined) {
857
+ logger.setLevel(options.level);
858
+ }
859
+ }
860
+ return logger;
861
+ }
862
+
863
+ /**
864
+ * Clears all existing `Logger` instances.
865
+ */
866
+ }, {
867
+ key: "clearAllLoggers",
868
+ value: function clearAllLoggers() {
869
+ __loggerMap.clear();
870
+ __levelMap.clear();
871
+ }
872
+
873
+ /**
874
+ * Gets the logging level of the `Logger` instance of the specified name.
875
+ *
876
+ * @param name
877
+ * The name of the `Logger` instance.
878
+ * @returns {string}
879
+ * The logging level of the `Logger` instance of the specified name. If the
880
+ * `Logger` instance of the specified name does not exist, the default
881
+ * logging level will be returned.
882
+ */
883
+ }, {
884
+ key: "getLoggerLevel",
885
+ value: function getLoggerLevel(name) {
886
+ var level = __levelMap.get(name);
887
+ return level !== null && level !== void 0 ? level : __defaultLevel;
888
+ }
889
+
890
+ /**
891
+ * Sets the logging level of the `Logger` instance of the specified name.
892
+ *
893
+ * @param name
894
+ * The name of the `Logger` instance.
895
+ * @param level
896
+ * The new logging level of the `Logger` instance of the specified name.
897
+ * The allowed levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`,
898
+ * and `NONE`. Lowercase letters are also allowed.
899
+ */
900
+ }, {
901
+ key: "setLoggerLevel",
902
+ value: function setLoggerLevel(name, level) {
903
+ level = upperCaseString(level);
904
+ checkLoggingLevel(level);
905
+ __levelMap.set(name, level);
906
+ var logger = __loggerMap.get(name);
907
+ if (logger !== undefined) {
908
+ logger.setLevel(level);
909
+ }
910
+ }
911
+
912
+ /**
913
+ * Gets the default logging level.
914
+ *
915
+ * The default logging level is used to construct a new `Logger` instance if
916
+ * the logging level of the new instance is not specified.
917
+ *
918
+ * @return {string}
919
+ * The global default logging level.
920
+ * @see Logger.setDefaultLevel
921
+ * @see Logger.setAllLevels
922
+ * @see Logger.resetAllLevels
923
+ */
924
+ }, {
925
+ key: "getDefaultLevel",
926
+ value: function getDefaultLevel() {
927
+ return __defaultLevel;
928
+ }
929
+
930
+ /**
931
+ * Sets the default logging level.
932
+ *
933
+ * The default logging level is used to construct a new `Logger` instance if
934
+ * the logging level of the new instance is not specified.
935
+ *
936
+ * @param {string} level
937
+ * The new default logging level. The allowed levels are `TRACE`, `DEBUG`,
938
+ * `INFO`, `WARN`, `ERROR`, and `NONE`. Lowercase letters are also allowed.
939
+ * @see Logger.getDefaultLevel
940
+ * @see Logger.setAllLevels
941
+ * @see Logger.resetAllLevels
942
+ */
943
+ }, {
944
+ key: "setDefaultLevel",
945
+ value: function setDefaultLevel(level) {
946
+ level = upperCaseString(level);
947
+ checkLoggingLevel(level);
948
+ __defaultLevel = level;
949
+ }
950
+
951
+ /**
952
+ * Resets the default logging level to the factory value.
953
+ *
954
+ * The default logging level is used to construct a new `Logger` instance if
955
+ * the logging level of the new instance is not specified.
956
+ */
957
+ }, {
958
+ key: "resetDefaultLevel",
959
+ value: function resetDefaultLevel() {
960
+ __defaultLevel = FACTORY_DEFAULT_LEVEL;
961
+ }
962
+
963
+ /**
964
+ * Sets the logging level of all existing `Logger` instants.
965
+ *
966
+ * @param {string} level
967
+ * The new logging level of all existing `Logger` instants. The allowed
968
+ * levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `NONE`.
969
+ * Lowercase letters are also allowed.
970
+ * @see Logger.getDefaultLevel
971
+ * @see Logger.setDefaultLevel
972
+ * @see Logger.resetAllLevels
973
+ */
974
+ }, {
975
+ key: "setAllLevels",
976
+ value: function setAllLevels(level) {
977
+ level = upperCaseString(level);
978
+ checkLoggingLevel(level);
979
+ var _iterator = _createForOfIteratorHelper(__loggerMap.values()),
980
+ _step;
981
+ try {
982
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
983
+ var logger = _step.value;
984
+ logger.setLevel(level);
985
+ }
986
+ } catch (err) {
987
+ _iterator.e(err);
988
+ } finally {
989
+ _iterator.f();
990
+ }
991
+ }
992
+
993
+ /**
994
+ * Sets the logging level of all `Logger` instants to the default logging level.
995
+ *
996
+ * @see Logger.getDefaultLevel
997
+ * @see Logger.setDefaultLevel
998
+ * @see Logger.setAllLevels
999
+ */
1000
+ }, {
1001
+ key: "resetAllLevels",
1002
+ value: function resetAllLevels() {
1003
+ Logger.setAllLevels(__defaultLevel);
1004
+ }
1005
+
1006
+ /**
1007
+ * Gets the default logging appender.
1008
+ *
1009
+ * The default logging appender is used to construct a new `Logger` instance
1010
+ * if the logging appender of the new instance is not specified.
1011
+ *
1012
+ * @return {Object}
1013
+ * The default logging appender.
1014
+ * @see Logger.setDefaultAppender
1015
+ * @see Logger.setAllAppenders
1016
+ * @see Logger.resetAllAppenders
1017
+ */
1018
+ }, {
1019
+ key: "getDefaultAppender",
1020
+ value: function getDefaultAppender() {
1021
+ return __defaultAppender;
1022
+ }
1023
+
1024
+ /**
1025
+ * Sets the default logging appender.
1026
+ *
1027
+ * The default logging appender is used to construct a new `Logger` instance
1028
+ * if the logging appender of the new instance is not specified.
1029
+ *
1030
+ * @param {object} appender
1031
+ * The new default logging appender.
1032
+ * @see Logger.getDefaultAppender
1033
+ * @see Logger.setAllAppenders
1034
+ * @see Logger.resetAllAppenders
1035
+ */
1036
+ }, {
1037
+ key: "setDefaultAppender",
1038
+ value: function setDefaultAppender(appender) {
1039
+ checkAppender(appender);
1040
+ __defaultAppender = appender;
1041
+ }
1042
+
1043
+ /**
1044
+ * Resets the default logging appender to the factory value.
1045
+ *
1046
+ * The default logging appender is used to construct a new `Logger` instance
1047
+ * if the logging appender of the new instance is not specified.
1048
+ *
1049
+ * @see Logger.getDefaultAppender
1050
+ */
1051
+ }, {
1052
+ key: "resetDefaultAppender",
1053
+ value: function resetDefaultAppender() {
1054
+ __defaultAppender = FACTORY_DEFAULT_APPENDER;
1055
+ }
1056
+
1057
+ /**
1058
+ * Sets the appender of all `Logger` instants.
1059
+ *
1060
+ * @param {object} appender
1061
+ * The new appender to be set, indicating the content output pipe of the
1062
+ * log. This object must provide `trace`, `debug`, `info`, `warn` and
1063
+ * `error` methods.
1064
+ * @see Logger.getDefaultAppender
1065
+ * @see Logger.setDefaultAppender
1066
+ * @see Logger.resetAllAppenders
1067
+ */
1068
+ }, {
1069
+ key: "setAllAppenders",
1070
+ value: function setAllAppenders(appender) {
1071
+ checkAppender(appender);
1072
+ var _iterator2 = _createForOfIteratorHelper(__loggerMap.values()),
1073
+ _step2;
1074
+ try {
1075
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1076
+ var logger = _step2.value;
1077
+ logger.setAppender(appender);
1078
+ }
1079
+ } catch (err) {
1080
+ _iterator2.e(err);
1081
+ } finally {
1082
+ _iterator2.f();
1083
+ }
1084
+ }
1085
+
1086
+ /**
1087
+ * Sets the appender of all `Logger` instants to the default appender.
1088
+ *
1089
+ * @see Logger.getDefaultAppender
1090
+ * @see Logger.setDefaultAppender
1091
+ * @see Logger.setAllAppenders
1092
+ */
1093
+ }, {
1094
+ key: "resetAllAppenders",
1095
+ value: function resetAllAppenders() {
1096
+ Logger.setAllAppenders(__defaultAppender);
1097
+ }
1098
+
1099
+ /**
1100
+ * Resets all configurations of the `Logger` class to the factory values.
1101
+ *
1102
+ * This method is equivalent to calling the following methods in sequence:
1103
+ * - `Logger.clearAllLoggers()`
1104
+ * - `Logger.resetDefaultLevel()`
1105
+ * - `Logger.resetDefaultAppender()`
1106
+ */
1107
+ }, {
1108
+ key: "reset",
1109
+ value: function reset() {
1110
+ Logger.clearAllLoggers();
1111
+ Logger.resetDefaultLevel();
1112
+ Logger.resetDefaultAppender();
1113
+ }
1114
+ }]);
1115
+ }();
1116
+
1117
+ ////////////////////////////////////////////////////////////////////////////////
1118
+ //
1119
+ // Copyright (c) 2022 - 2023.
1120
+ // Haixing Hu, Qubit Co. Ltd.
1121
+ //
1122
+ // All rights reserved.
1123
+ //
1124
+ ////////////////////////////////////////////////////////////////////////////////
1125
+ var VUE3_CLASS_COMPONENT_DECORATORS_KEY = '__vue3_class_component_decorators__';
1126
+
1127
+ /**
1128
+ * The names of special functions of Vue components.
1129
+ *
1130
+ * @type {string[]}
1131
+ * @private
1132
+ * @author Haixing Hu
1133
+ */
1134
+ var VUE_FUNCTIONS = [
1135
+ // The names of lifecycle hooks of Vue components.
1136
+ 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked',
1137
+ // Dev only
1138
+ 'renderTriggered',
1139
+ // Dev only
1140
+ 'activated', 'deactivated', 'serverPrefetch',
1141
+ // SSR only
1142
+ // The names of special functions in the options API Vue components.
1143
+ 'render'];
1144
+
1145
+ /**
1146
+ * Print tracing logs for class methods.
1147
+ *
1148
+ * @param {string} className
1149
+ * The name of the class the decorated method belongs to.
1150
+ * @param {string} methodName
1151
+ * The name of the decorated method..
1152
+ * @param {array} args
1153
+ * The calling arguments of the decorated method.
1154
+ * @author Haixing Hu
1155
+ * @private
1156
+ */
1157
+ function printMethodLog(className, methodName, args) {
1158
+ var logger = Logger.getLogger(className);
1159
+ if (args.length === 0) {
1160
+ logger.trace('%s.%s.', className, methodName);
1161
+ } else {
1162
+ logger.trace.apply(logger, ['%s.%s:', className, methodName].concat(_toConsumableArray(args)));
1163
+ }
1164
+ }
1165
+
1166
+ /**
1167
+ * A decorator function that meets the requirements of the `createDecorator()`
1168
+ * function of `vue-class-component`.
1169
+ *
1170
+ * @param {Object} options
1171
+ * Options object used to create Vue components.
1172
+ * @param {String} key
1173
+ * The name of the property or method to which this decorator applies.
1174
+ * @param {Function} originalMethod
1175
+ * The original method to be called.
1176
+ * @author Haixing Hu
1177
+ * @private
1178
+ */
1179
+ function vueLogDecorator(options, key, originalMethod) {
1180
+ // If the method decorated by the decorator is a Vue's life cycle hook function,
1181
+ // Then `col` is `options`; otherwise `col` is `options.methods`
1182
+ var col = VUE_FUNCTIONS.includes(key) ? options : options.methods;
1183
+ col[key] = function logWrapperMethod() {
1184
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1185
+ args[_key] = arguments[_key];
1186
+ }
1187
+ printMethodLog(options.name, key, args);
1188
+ return originalMethod.apply(this, args);
1189
+ };
1190
+ }
1191
+
1192
+ /**
1193
+ * Defines a class method decorator that modifies the target method and prints
1194
+ * its calling signature in the log, including class name, method name and
1195
+ * parameters.
1196
+ *
1197
+ * Note that only non-constructor class method can be decorated by this decorator.
1198
+ * The global function and class constructor CANNOT be decorated by this decorator.
1199
+ *
1200
+ * Usage example:
1201
+ * ```js
1202
+ * import { Log } from '@haixing_hu/logging';
1203
+ *
1204
+ * class Person {
1205
+ * &#064;Log
1206
+ * eat(meal) {
1207
+ * ...
1208
+ * }
1209
+ * }
1210
+ *
1211
+ * const person = new Person();
1212
+ * const meal = new Meal();
1213
+ * person.eat(meal); // 日志中将会打印此方法调用的签名
1214
+ * ```
1215
+ *
1216
+ * @param {function} target
1217
+ * The method being decorated.
1218
+ * @param {object} context
1219
+ * the context object containing information about the method to be decorated.
1220
+ * @return {function}
1221
+ * The decorated method.
1222
+ * @author Haixing Hu
1223
+ */
1224
+ function Log(target, context) {
1225
+ var _metadata$VUE3_CLASS_;
1226
+ if (context === null || _typeof(context) !== 'object') {
1227
+ throw new TypeError('The context of `@Log` decorator must be an object.');
1228
+ }
1229
+ if (typeof target !== 'function' || context.kind !== 'method') {
1230
+ throw new TypeError('The `@Log` can only decorate a class method.');
1231
+ }
1232
+ // decorate the class-style Vue component
1233
+ // see the `createDecorator()` function in `@haixing_hu/vue3-class-component`
1234
+ var metadata = context.metadata;
1235
+ (_metadata$VUE3_CLASS_ = metadata[VUE3_CLASS_COMPONENT_DECORATORS_KEY]) !== null && _metadata$VUE3_CLASS_ !== void 0 ? _metadata$VUE3_CLASS_ : metadata[VUE3_CLASS_COMPONENT_DECORATORS_KEY] = [];
1236
+ metadata[VUE3_CLASS_COMPONENT_DECORATORS_KEY].push(function (Class, instance, options) {
1237
+ return vueLogDecorator(options, context.name, target);
1238
+ });
1239
+ // decorate the original method
1240
+ function decoratedMethod() {
1241
+ var prototype = Object.getPrototypeOf(this);
1242
+ var Class = prototype.constructor;
1243
+ var className = Class.name;
1244
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1245
+ args[_key2] = arguments[_key2];
1246
+ }
1247
+ printMethodLog(className, context.name, args);
1248
+ return target.apply(this, args);
1249
+ }
1250
+ return decoratedMethod;
1251
+ }
1252
+
1253
+ /**
1254
+ * A decorator to add a named logger to a class.
1255
+ *
1256
+ * This decorator will add a named logger to the class, which can be accessed
1257
+ * via the `logger` property of the class.
1258
+ *
1259
+ * Example usage:
1260
+ * ```js
1261
+ * import { HasLogger } from '@haixing_hu/logging';
1262
+ *
1263
+ * &#064;HasLogger
1264
+ * class MyClass {
1265
+ * foo() {
1266
+ * this.logger.debug('This is MyClass.foo()');
1267
+ * }
1268
+ * }
1269
+ * ```
1270
+ *
1271
+ * The following is another example usage with the class component of Vue.js:
1272
+ * ```js
1273
+ * import { Component, toVue } from '@haixing_hu/vue3-class-component';
1274
+ * import { HasLogger, Log } from '@haixing_hu/logging';
1275
+ *
1276
+ * &#064;Component({
1277
+ * template: '<p &#064;click="foo">{{ message }}</p>',
1278
+ * })
1279
+ * &#064;HasLogger
1280
+ * class MyComponent {
1281
+ * &#064;Log
1282
+ * foo() {
1283
+ * this.logger.debug('This is MyComponent.foo()');
1284
+ * }
1285
+ * }
1286
+ *
1287
+ * export default toVue(MyComponent);
1288
+ * ```
1289
+ *
1290
+ * **NOTE**: the order of the decorators is IMPORTANT. The `@HasLogger` decorator
1291
+ * must be placed **AFTER** the `@Component` decorator.
1292
+ *
1293
+ * @param {function} Class
1294
+ * the target class to be decorated.
1295
+ * @param {object} context
1296
+ * the context object containing information about the class to be decorated.
1297
+ * @return {function}
1298
+ * the new constructor of the decorated class.
1299
+ * @author Haixing Hu
1300
+ */
1301
+ function HasLogger(Class, context) {
1302
+ if (context === null || _typeof(context) !== 'object') {
1303
+ throw new TypeError('The context must be an object.');
1304
+ }
1305
+ if (typeof Class !== 'function' || context.kind !== 'class') {
1306
+ throw new TypeError('The `@HasLogger` can only decorate a class.');
1307
+ }
1308
+ if (Class.prototype.logger) {
1309
+ throw new Error('The @HasLogger decorator can only be used once on a class.');
1310
+ }
1311
+ var instance = new Class();
1312
+ if (instance.logger !== undefined) {
1313
+ throw new Error('The @HasLogger cannot be decorated on the class with a `logger` field.');
1314
+ }
1315
+ // add the logger to the class prototype
1316
+ Class.prototype.logger = Logger.getLogger(context.name);
1317
+ return Class;
1318
+ }
1319
+
1320
+ ////////////////////////////////////////////////////////////////////////////////
1321
+ //
1322
+ // Copyright (c) 2022 - 2023.
1323
+ // Haixing Hu, Qubit Co. Ltd.
1324
+ //
1325
+ // All rights reserved.
1326
+ //
1327
+ ////////////////////////////////////////////////////////////////////////////////
1328
+
1329
+ export { HasLogger, Log, Logger, Logger as default };
1330
+ //# sourceMappingURL=logging.mjs.map