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