logger.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Logger = /** @class */ (function () {
  4. function Logger(_a) {
  5. var id = _a.id, enabled = _a.enabled;
  6. this.id = id;
  7. this.enabled = enabled;
  8. this.start = Date.now();
  9. }
  10. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  11. Logger.prototype.debug = function () {
  12. var args = [];
  13. for (var _i = 0; _i < arguments.length; _i++) {
  14. args[_i] = arguments[_i];
  15. }
  16. if (this.enabled) {
  17. // eslint-disable-next-line no-console
  18. if (typeof window !== 'undefined' && window.console && typeof console.debug === 'function') {
  19. // eslint-disable-next-line no-console
  20. console.debug.apply(console, [this.id, this.getTime() + "ms"].concat(args));
  21. }
  22. else {
  23. this.info.apply(this, args);
  24. }
  25. }
  26. };
  27. Logger.prototype.getTime = function () {
  28. return Date.now() - this.start;
  29. };
  30. Logger.create = function (options) {
  31. Logger.instances[options.id] = new Logger(options);
  32. };
  33. Logger.destroy = function (id) {
  34. delete Logger.instances[id];
  35. };
  36. Logger.getInstance = function (id) {
  37. var instance = Logger.instances[id];
  38. if (typeof instance === 'undefined') {
  39. throw new Error("No logger instance found with id " + id);
  40. }
  41. return instance;
  42. };
  43. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  44. Logger.prototype.info = function () {
  45. var args = [];
  46. for (var _i = 0; _i < arguments.length; _i++) {
  47. args[_i] = arguments[_i];
  48. }
  49. if (this.enabled) {
  50. // eslint-disable-next-line no-console
  51. if (typeof window !== 'undefined' && window.console && typeof console.info === 'function') {
  52. // eslint-disable-next-line no-console
  53. console.info.apply(console, [this.id, this.getTime() + "ms"].concat(args));
  54. }
  55. }
  56. };
  57. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  58. Logger.prototype.error = function () {
  59. var args = [];
  60. for (var _i = 0; _i < arguments.length; _i++) {
  61. args[_i] = arguments[_i];
  62. }
  63. if (this.enabled) {
  64. // eslint-disable-next-line no-console
  65. if (typeof window !== 'undefined' && window.console && typeof console.error === 'function') {
  66. // eslint-disable-next-line no-console
  67. console.error.apply(console, [this.id, this.getTime() + "ms"].concat(args));
  68. }
  69. else {
  70. this.info.apply(this, args);
  71. }
  72. }
  73. };
  74. Logger.instances = {};
  75. return Logger;
  76. }());
  77. exports.Logger = Logger;
  78. //# sourceMappingURL=logger.js.map