root.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __spread = (this && this.__spread) || function () {
  19. for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
  20. return ar;
  21. };
  22. var __values = (this && this.__values) || function (o) {
  23. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  24. if (m) return m.call(o);
  25. return {
  26. next: function () {
  27. if (o && i >= o.length) o = void 0;
  28. return { value: o && o[i++], done: !o };
  29. }
  30. };
  31. };
  32. Object.defineProperty(exports, "__esModule", { value: true });
  33. var e_1, _a;
  34. var cache_getters_1 = require("../utils/cache-getters");
  35. var _1 = require(".");
  36. var level_1 = require("./level");
  37. var cache;
  38. var setup = function (factory) {
  39. if (factory === void 0) { factory = function () { return _1.createLogger({ targets: process.env.LOG_TARGETS || process.env.LOG_TARGET }); }; }
  40. cache = cache_getters_1.cacheGetters({
  41. get root() {
  42. return factory();
  43. },
  44. }, 'root');
  45. };
  46. exports.setup = setup;
  47. var rootLogger = (function () {
  48. var args = [];
  49. for (var _i = 0; _i < arguments.length; _i++) {
  50. args[_i] = arguments[_i];
  51. }
  52. return cache.root.apply(cache, __spread(args));
  53. });
  54. exports.rootLogger = rootLogger;
  55. var props = __spread(level_1.LogLevelNames, ['child', 'wrap']);
  56. var _loop_1 = function (prop) {
  57. Object.defineProperty(rootLogger, prop, {
  58. enumerable: true,
  59. configurable: true,
  60. get: function () {
  61. return cache.root[prop];
  62. },
  63. });
  64. };
  65. try {
  66. for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
  67. var prop = props_1_1.value;
  68. _loop_1(prop);
  69. }
  70. }
  71. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  72. finally {
  73. try {
  74. if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
  75. }
  76. finally { if (e_1) throw e_1.error; }
  77. }
  78. cache_getters_1.cacheGetters.apply(void 0, __spread([rootLogger], props));
  79. setup();