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