standard-log 11.5.1 → 12.0.0

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 (157) hide show
  1. package/README.md +2 -3
  2. package/cjs/console.d.ts +3 -3
  3. package/cjs/console.d.ts.map +1 -1
  4. package/cjs/console.js +18 -9
  5. package/cjs/console.js.map +1 -1
  6. package/cjs/errors.d.ts.map +1 -1
  7. package/cjs/errors.js.map +1 -1
  8. package/cjs/formatter.d.ts +1 -1
  9. package/cjs/formatter.d.ts.map +1 -1
  10. package/cjs/formatter.js +2 -2
  11. package/cjs/formatter.js.map +1 -1
  12. package/cjs/index.d.ts +4 -4
  13. package/cjs/index.d.ts.map +1 -1
  14. package/cjs/index.js +7 -8
  15. package/cjs/index.js.map +1 -1
  16. package/cjs/{logLevels.d.ts → log_levels.d.ts} +1 -1
  17. package/cjs/log_levels.d.ts.map +1 -0
  18. package/cjs/{logLevels.js → log_levels.js} +1 -1
  19. package/cjs/log_levels.js.map +1 -0
  20. package/{esm/logStore.d.ts → cjs/log_store.d.ts} +1 -1
  21. package/cjs/log_store.d.ts.map +1 -0
  22. package/cjs/{logStore.js → log_store.js} +6 -6
  23. package/cjs/log_store.js.map +1 -0
  24. package/cjs/logger.d.ts +1 -1
  25. package/cjs/logger.d.ts.map +1 -1
  26. package/cjs/logger.js +16 -14
  27. package/cjs/logger.js.map +1 -1
  28. package/cjs/memory.d.ts +2 -2
  29. package/cjs/memory.d.ts.map +1 -1
  30. package/cjs/memory.js +15 -8
  31. package/cjs/memory.js.map +1 -1
  32. package/cjs/platform.d.ts.map +1 -1
  33. package/cjs/platform.js +1 -2
  34. package/cjs/platform.js.map +1 -1
  35. package/cjs/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  36. package/cjs/standard_log.ctx.d.ts.map +1 -0
  37. package/cjs/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  38. package/cjs/standard_log.ctx.js.map +1 -0
  39. package/{esm/standardLog.d.ts → cjs/standard_log.d.ts} +4 -9
  40. package/cjs/standard_log.d.ts.map +1 -0
  41. package/cjs/{standardLog.js → standard_log.js} +37 -40
  42. package/cjs/standard_log.js.map +1 -0
  43. package/cjs/standard_log.mocks.d.ts +8 -0
  44. package/cjs/standard_log.mocks.d.ts.map +1 -0
  45. package/cjs/standard_log.mocks.js +32 -0
  46. package/cjs/standard_log.mocks.js.map +1 -0
  47. package/cjs/test_utils.d.ts +10 -0
  48. package/cjs/test_utils.d.ts.map +1 -0
  49. package/cjs/test_utils.js +25 -0
  50. package/cjs/test_utils.js.map +1 -0
  51. package/cjs/testing/index.d.ts +2 -0
  52. package/cjs/testing/index.d.ts.map +1 -0
  53. package/cjs/testing/index.js +6 -0
  54. package/cjs/testing/index.js.map +1 -0
  55. package/cjs/types.d.ts +12 -12
  56. package/cjs/types.d.ts.map +1 -1
  57. package/cjs/types.js.map +1 -1
  58. package/dist/standard-log.es5.js +1139 -758
  59. package/dist/standard-log.es5.js.gz +0 -0
  60. package/dist/standard-log.es5.js.map +1 -1
  61. package/dist/standard-log.es5.js.map.gz +0 -0
  62. package/dist/standard-log.esm.js +220 -175
  63. package/dist/standard-log.esm.js.gz +0 -0
  64. package/dist/standard-log.esm.js.map +1 -1
  65. package/dist/standard-log.esm.js.map.gz +0 -0
  66. package/esm/console.d.ts +3 -3
  67. package/esm/console.d.ts.map +1 -1
  68. package/esm/console.js +21 -10
  69. package/esm/console.js.map +1 -1
  70. package/esm/errors.d.ts.map +1 -1
  71. package/esm/errors.js.map +1 -1
  72. package/esm/formatter.d.ts +1 -1
  73. package/esm/formatter.d.ts.map +1 -1
  74. package/esm/formatter.js +1 -1
  75. package/esm/formatter.js.map +1 -1
  76. package/esm/index.d.ts +4 -4
  77. package/esm/index.d.ts.map +1 -1
  78. package/esm/index.js +2 -2
  79. package/esm/index.js.map +1 -1
  80. package/esm/{logLevels.d.ts → log_levels.d.ts} +1 -1
  81. package/esm/log_levels.d.ts.map +1 -0
  82. package/esm/{logLevels.js → log_levels.js} +1 -1
  83. package/esm/log_levels.js.map +1 -0
  84. package/{cjs/logStore.d.ts → esm/log_store.d.ts} +1 -1
  85. package/esm/log_store.d.ts.map +1 -0
  86. package/esm/{logStore.js → log_store.js} +2 -2
  87. package/esm/log_store.js.map +1 -0
  88. package/esm/logger.d.ts +1 -1
  89. package/esm/logger.d.ts.map +1 -1
  90. package/esm/logger.js +2 -2
  91. package/esm/logger.js.map +1 -1
  92. package/esm/memory.d.ts +2 -2
  93. package/esm/memory.d.ts.map +1 -1
  94. package/esm/memory.js +15 -8
  95. package/esm/memory.js.map +1 -1
  96. package/esm/platform.d.ts.map +1 -1
  97. package/esm/platform.js +1 -2
  98. package/esm/platform.js.map +1 -1
  99. package/esm/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  100. package/esm/standard_log.ctx.d.ts.map +1 -0
  101. package/esm/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  102. package/esm/standard_log.ctx.js.map +1 -0
  103. package/{cjs/standardLog.d.ts → esm/standard_log.d.ts} +4 -9
  104. package/esm/standard_log.d.ts.map +1 -0
  105. package/esm/{standardLog.js → standard_log.js} +27 -28
  106. package/esm/standard_log.js.map +1 -0
  107. package/esm/standard_log.mocks.d.ts +8 -0
  108. package/esm/standard_log.mocks.d.ts.map +1 -0
  109. package/esm/standard_log.mocks.js +16 -0
  110. package/esm/standard_log.mocks.js.map +1 -0
  111. package/esm/test_utils.d.ts +10 -0
  112. package/esm/test_utils.d.ts.map +1 -0
  113. package/esm/test_utils.js +18 -0
  114. package/esm/test_utils.js.map +1 -0
  115. package/esm/testing/index.d.ts +2 -0
  116. package/esm/testing/index.d.ts.map +1 -0
  117. package/esm/testing/index.js +2 -0
  118. package/esm/testing/index.js.map +1 -0
  119. package/esm/types.d.ts +12 -12
  120. package/esm/types.d.ts.map +1 -1
  121. package/esm/types.js.map +1 -1
  122. package/package.json +14 -8
  123. package/ts/console.ts +55 -46
  124. package/ts/errors.ts +6 -6
  125. package/ts/formatter.ts +19 -19
  126. package/ts/index.ts +19 -10
  127. package/ts/log_levels.ts +107 -0
  128. package/ts/log_store.ts +63 -0
  129. package/ts/logger.ts +69 -59
  130. package/ts/memory.ts +66 -54
  131. package/ts/platform.ts +2 -2
  132. package/ts/standard_log.ctx.ts +8 -0
  133. package/ts/standard_log.mocks.ts +22 -0
  134. package/ts/standard_log.ts +140 -0
  135. package/ts/test_utils.ts +21 -0
  136. package/ts/testing/index.ts +1 -0
  137. package/ts/types.ts +72 -62
  138. package/cjs/logLevels.d.ts.map +0 -1
  139. package/cjs/logLevels.js.map +0 -1
  140. package/cjs/logStore.d.ts.map +0 -1
  141. package/cjs/logStore.js.map +0 -1
  142. package/cjs/standardLog.ctx.d.ts.map +0 -1
  143. package/cjs/standardLog.ctx.js.map +0 -1
  144. package/cjs/standardLog.d.ts.map +0 -1
  145. package/cjs/standardLog.js.map +0 -1
  146. package/esm/logLevels.d.ts.map +0 -1
  147. package/esm/logLevels.js.map +0 -1
  148. package/esm/logStore.d.ts.map +0 -1
  149. package/esm/logStore.js.map +0 -1
  150. package/esm/standardLog.ctx.d.ts.map +0 -1
  151. package/esm/standardLog.ctx.js.map +0 -1
  152. package/esm/standardLog.d.ts.map +0 -1
  153. package/esm/standardLog.js.map +0 -1
  154. package/ts/logLevels.ts +0 -108
  155. package/ts/logStore.ts +0 -54
  156. package/ts/standardLog.ctx.ts +0 -8
  157. package/ts/standardLog.ts +0 -135
package/README.md CHANGED
@@ -48,7 +48,7 @@ log.debug('debug message')
48
48
  log.on(logLevels.trace, () => prettify(someValue))
49
49
  ```
50
50
 
51
- ![Rendering example][rendering-example]
51
+ ![Rendering example](../../images/color-log.png)
52
52
 
53
53
  (above is logged with `standard-log-color`)
54
54
 
@@ -149,7 +149,7 @@ During test,
149
149
  you should use `createStandardLogForTest` which includes a `MemoryReporter` to capture the logs.
150
150
 
151
151
  ```ts
152
- import { createStandardLogForTest, createMemoryReporter } from 'standard-log'
152
+ import { createStandardLogForTest } from 'standard-log/testing'
153
153
 
154
154
  test('your test', () => {
155
155
  const standardLog = createStandardLogForTest()
@@ -198,7 +198,6 @@ It is the main driving force for 9.0.
198
198
  [github-nodejs]: https://github.com/unional/standard-log/workflows/release/badge.svg
199
199
  [npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
200
200
  [npm-url]: https://www.npmjs.com/package/standard-log
201
- [rendering-example]: https://github.com/unional/standard-log/tree/main/images/color-log.png
202
201
  [standard-log-color]: https://github.com/unional/standard-log/tree/master/packages/color
203
202
  [standard-log-syslog]: https://github.com/unional/standard-log/tree/master/packages/syslog
204
203
  [standard-log]: https://github.com/unional/standard-log
package/cjs/console.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { ConsoleLike, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
2
2
  export declare function toConsoleMethod(level: number): "error" | "warn" | "info" | "debug";
3
- export declare type ConsoleLogFormatter = LogFormatter<any[]>;
4
- export declare type ConsoleLogReporter = LogReporter<any[]> & {
3
+ export type ConsoleLogFormatter = LogFormatter<any[]>;
4
+ export type ConsoleLogReporter = LogReporter<any[]> & {
5
5
  console: ConsoleLike;
6
6
  };
7
- export declare type ConsoleLogReporterOptions = LogReporterOptions<any[]>;
7
+ export type ConsoleLogReporterOptions = LogReporterOptions<any[]>;
8
8
  export declare function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter;
9
9
  //# sourceMappingURL=console.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAY,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,uCAS5C;AAiCD,oBAAY,mBAAmB,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;AACrD,oBAAY,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;AAC9E,oBAAY,yBAAyB,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAA;AAEjE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAiBhG"}
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAY,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,uCAc5C;AAiCD,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;AACrD,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;AAC9E,MAAM,MAAM,yBAAyB,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAA;AAEjE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAqBhG"}
package/cjs/console.js CHANGED
@@ -3,16 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createConsoleLogReporter = exports.toConsoleMethod = void 0;
4
4
  var type_plus_1 = require("type-plus");
5
5
  var formatter_js_1 = require("./formatter.js");
6
- var logLevels_js_1 = require("./logLevels.js");
6
+ var log_levels_js_1 = require("./log_levels.js");
7
7
  var platform_js_1 = require("./platform.js");
8
8
  function toConsoleMethod(level) {
9
9
  switch (true) {
10
10
  // edge case in case none is somehow written
11
- case (level <= 0): return 'debug';
12
- case (level <= logLevels_js_1.logLevels.error): return 'error';
13
- case (level <= logLevels_js_1.logLevels.warn): return 'warn';
14
- case (level <= logLevels_js_1.logLevels.info): return 'info';
15
- default: return 'debug';
11
+ case level <= 0:
12
+ return 'debug';
13
+ case level <= log_levels_js_1.logLevels.error:
14
+ return 'error';
15
+ case level <= log_levels_js_1.logLevels.warn:
16
+ return 'warn';
17
+ case level <= log_levels_js_1.logLevels.info:
18
+ return 'info';
19
+ default:
20
+ return 'debug';
16
21
  }
17
22
  }
18
23
  exports.toConsoleMethod = toConsoleMethod;
@@ -36,7 +41,7 @@ function buildPolyfillConsole() {
36
41
  debug: buildFn(typeof console.debug === 'function' ? 'debug' : 'log'),
37
42
  info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
38
43
  warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
39
- error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
44
+ error: buildFn(typeof console.error === 'function' ? 'error' : 'log')
40
45
  };
41
46
  }
42
47
  }
@@ -57,8 +62,12 @@ function createConsoleLogReporter(options) {
57
62
  return Object.freeze({
58
63
  id: id,
59
64
  isConsoleReporter: true,
60
- get formatter() { return formatter; },
61
- get filter() { return filter; },
65
+ get formatter() {
66
+ return formatter;
67
+ },
68
+ get filter() {
69
+ return filter;
70
+ },
62
71
  console: platform_js_1.polyfill.console,
63
72
  write: function (entry) {
64
73
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,+CAAiD;AACjD,+CAA0C;AAC1C,6CAAwC;AAGxC,SAAgB,eAAe,CAAC,KAAa;IAC3C,QAAQ,IAAI,EAAE;QACZ,4CAA4C;QAC5C,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QACjC,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QAC/C,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,MAAM,CAAA;QAC7C,KAAK,CAAC,KAAK,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eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,MAAM,CAAC,WAAI,MAAM,EAAC;QACjC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAjBD,4DAiBC","sourcesContent":["import { unpartial } from 'type-plus'\nimport { consoleFormatter } from './formatter.js'\nimport { logLevels } from './logLevels.js'\nimport { polyfill } from './platform.js'\nimport type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport function toConsoleMethod(level: number) {\n switch (true) {\n // edge case in case none is somehow written\n case (level <= 0): return 'debug'\n case (level <= logLevels.error): return 'error'\n case (level <= logLevels.warn): return 'warn'\n case (level <= logLevels.info): return 'info'\n default: return 'debug'\n }\n}\n\n// istanbul ignore next\n/* eslint-disable no-console */\nfunction buildPolyfillConsole() {\n // old phantomjs does not have bind function\n const hasBind = !!console.log.bind as boolean\n if (hasBind) {\n return {\n // the `typeof` guards against IE where `console.log.apply()`\n // results in error `Object doesn't support property or method 'apply'`\n debug: (typeof console.info === 'function' ? console.debug : console.log).bind(console),\n info: (typeof console.info === 'function' ? console.info : console.log).bind(console),\n warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),\n error: (typeof console.error === 'function' ? console.error : console.log).bind(console)\n }\n }\n else {\n return {\n debug: buildFn(typeof console.debug === 'function' ? 'debug' : 'log'),\n info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),\n warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),\n error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),\n }\n }\n}\n\n// istanbul ignore next\nfunction buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {\n return function (...args: any[]) { console[name](...args) }\n}\n\n\nexport type ConsoleLogFormatter = LogFormatter<any[]>\nexport type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }\nexport type ConsoleLogReporterOptions = LogReporterOptions<any[]>\n\nexport function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {\n const { id, formatter, filter } = unpartial({ id: 'console', formatter: consoleFormatter }, options)\n if (!polyfill.console) polyfill.console = buildPolyfillConsole()\n\n return Object.freeze({\n id,\n isConsoleReporter: true,\n get formatter() { return formatter },\n get filter() { return filter },\n console: polyfill.console,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n const values = formatter(entry)\n const method = toConsoleMethod(entry.level)\n this.console[method](...values)\n }\n })\n}\n"]}
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,+CAAiD;AACjD,iDAA2C;AAC3C,6CAAwC;AAGxC,SAAgB,eAAe,CAAC,KAAa;IAC5C,QAAQ,IAAI,EAAE;QACb,4CAA4C;QAC5C,KAAK,KAAK,IAAI,CAAC;YACd,OAAO,OAAO,CAAA;QACf,KAAK,KAAK,IAAI,yBAAS,CAAC,KAAK;YAC5B,OAAO,OAAO,CAAA;QACf,KAAK,KAAK,IAAI,yBAAS,CAAC,IAAI;YAC3B,OAAO,MAAM,CAAA;QACd,KAAK,KAAK,IAAI,yBAAS,CAAC,IAAI;YAC3B,OAAO,MAAM,CAAA;QACd;YACC,OAAO,OAAO,CAAA;KACf;AACF,CAAC;AAdD,0CAcC;AAED,uBAAuB;AACvB,+BAA+B;AAC/B,SAAS,oBAAoB;IAC5B,4CAA4C;IAC5C,IAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAe,CAAA;IAC7C,IAAI,OAAO,EAAE;QACZ,OAAO;YACN,6DAA6D;YAC7D,uEAAuE;YACvE,KAAK,EAAE,CAAC,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;YACvF,IAAI,EAAE,CAAC,OAAO,OAAO,CAA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BAAwB,CAAC,OAAmC;IACrE,IAAA,KAA4B,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,+BAAgB,EAAE,EAAE,OAAO,CAAC,EAA5F,EAAE,QAAA,EAAE,SAAS,eAAA,EAAE,MAAM,YAAuE,CAAA;IACpG,IAAI,CAAC,sBAAQ,CAAC,OAAO;QAAE,sBAAQ,CAAC,OAAO,GAAG,oBAAoB,EAAE,CAAA;IAEhE,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,EAAE,IAAA;QACF,iBAAiB,EAAE,IAAI;QACvB,IAAI,SAAS;YACZ,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,IAAI,MAAM;YACT,OAAO,MAAM,CAAA;QACd,CAAC;QACD,OAAO,EAAE,sBAAQ,CAAC,OAAO;QACzB,KAAK,YAAC,KAAe;;YACpB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,IAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,MAAM,CAAC,WAAI,MAAM,EAAC;QAChC,CAAC;KACD,CAAC,CAAA;AACH,CAAC;AArBD,4DAqBC","sourcesContent":["import { unpartial } from 'type-plus'\nimport { consoleFormatter } from './formatter.js'\nimport { logLevels } from './log_levels.js'\nimport { polyfill } from './platform.js'\nimport type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport function toConsoleMethod(level: number) {\n\tswitch (true) {\n\t\t// edge case in case none is somehow written\n\t\tcase level <= 0:\n\t\t\treturn 'debug'\n\t\tcase level <= logLevels.error:\n\t\t\treturn 'error'\n\t\tcase level <= logLevels.warn:\n\t\t\treturn 'warn'\n\t\tcase level <= logLevels.info:\n\t\t\treturn 'info'\n\t\tdefault:\n\t\t\treturn 'debug'\n\t}\n}\n\n// istanbul ignore next\n/* eslint-disable no-console */\nfunction buildPolyfillConsole() {\n\t// old phantomjs does not have bind function\n\tconst hasBind = !!console.log.bind as boolean\n\tif (hasBind) {\n\t\treturn {\n\t\t\t// the `typeof` guards against IE where `console.log.apply()`\n\t\t\t// results in error `Object doesn't support property or method 'apply'`\n\t\t\tdebug: (typeof console.info === 'function' ? console.debug : console.log).bind(console),\n\t\t\tinfo: (typeof console.info === 'function' ? console.info : console.log).bind(console),\n\t\t\twarn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),\n\t\t\terror: (typeof console.error === 'function' ? console.error : console.log).bind(console)\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\tdebug: buildFn(typeof console.debug === 'function' ? 'debug' : 'log'),\n\t\t\tinfo: buildFn(typeof console.info === 'function' ? 'info' : 'log'),\n\t\t\twarn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),\n\t\t\terror: buildFn(typeof console.error === 'function' ? 'error' : 'log')\n\t\t}\n\t}\n}\n\n// istanbul ignore next\nfunction buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {\n\treturn function (...args: any[]) {\n\t\tconsole[name](...args)\n\t}\n}\n\nexport type ConsoleLogFormatter = LogFormatter<any[]>\nexport type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }\nexport type ConsoleLogReporterOptions = LogReporterOptions<any[]>\n\nexport function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {\n\tconst { id, formatter, filter } = unpartial({ id: 'console', formatter: consoleFormatter }, options)\n\tif (!polyfill.console) polyfill.console = buildPolyfillConsole()\n\n\treturn Object.freeze({\n\t\tid,\n\t\tisConsoleReporter: true,\n\t\tget formatter() {\n\t\t\treturn formatter\n\t\t},\n\t\tget filter() {\n\t\t\treturn filter\n\t\t},\n\t\tconsole: polyfill.console,\n\t\twrite(entry: LogEntry) {\n\t\t\tif (filter && !filter(entry)) return\n\t\t\tconst values = formatter(entry)\n\t\t\tconst method = toConsoleMethod(entry.level)\n\t\t\tthis.console[method](...values)\n\t\t}\n\t})\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEjD;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAG5D;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,gBAAgB;IAC1B,EAAE,EAAE,MAAM;gBAAV,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAG1D"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEjD;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;gBACpC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAG3D;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,gBAAgB;IAC3B,EAAE,EAAE,MAAM;gBAAV,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAGzD"}
package/cjs/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAAiD;AAEjD;;GAEG;AACH;IAAsC,oCAAW;IAC/C,0BAAY,WAAmB,EAAE,OAA0B;eACzD,kBAAM,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC;IAC7C,CAAC;IACH,uBAAC;AAAD,CAAC,AAJD,CAAsC,uBAAW,GAIhD;AAJY,4CAAgB;AAM7B;;GAEG;AACH;IAA+B,6BAAgB;IAC7C,mBAAmB,EAAU,EAAE,OAA0B;QAAzD,YACE,kBAAM,yFAAkF,EAAE,CAAE,EAAE,OAAO,CAAC,SACvG;;;;;mBAFkB;;;IAEnB,CAAC;IACH,gBAAC;AAAD,CAAC,AAJD,CAA+B,gBAAgB,GAI9C;AAJY,8BAAS","sourcesContent":["import { IsoError, ModuleError } from 'iso-error'\n\n/**\n * @deprecated No longer used since 11.2.0\n */\nexport class StandardLogError extends ModuleError {\n constructor(description: string, options?: IsoError.Options) {\n super('standard-log', description, options)\n }\n}\n\n/**\n * @deprecated no longer used since 11.2.0\n */\nexport class InvalidId extends StandardLogError {\n constructor(public id: string, options?: IsoError.Options) {\n super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAAiD;AAEjD;;GAEG;AACH;IAAsC,oCAAW;IAChD,0BAAY,WAAmB,EAAE,OAA0B;eAC1D,kBAAM,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC;IAC5C,CAAC;IACF,uBAAC;AAAD,CAAC,AAJD,CAAsC,uBAAW,GAIhD;AAJY,4CAAgB;AAM7B;;GAEG;AACH;IAA+B,6BAAgB;IAC9C,mBAAmB,EAAU,EAAE,OAA0B;QAAzD,YACC,kBAAM,yFAAkF,EAAE,CAAE,EAAE,OAAO,CAAC,SACtG;QAFW;;;;mBAAO,EAAE;WAAQ;;IAE7B,CAAC;IACF,gBAAC;AAAD,CAAC,AAJD,CAA+B,gBAAgB,GAI9C;AAJY,8BAAS","sourcesContent":["import { IsoError, ModuleError } from 'iso-error'\n\n/**\n * @deprecated No longer used since 11.2.0\n */\nexport class StandardLogError extends ModuleError {\n\tconstructor(description: string, options?: IsoError.Options) {\n\t\tsuper('standard-log', description, options)\n\t}\n}\n\n/**\n * @deprecated no longer used since 11.2.0\n */\nexport class InvalidId extends StandardLogError {\n\tconstructor(public id: string, options?: IsoError.Options) {\n\t\tsuper(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { LogEntry } from './types.js';
2
- export declare type TimestampFormat = 'none' | 'iso' | 'elapsed';
2
+ export type TimestampFormat = 'none' | 'iso' | 'elapsed';
3
3
  export declare function createTimestampFormatter(format: TimestampFormat): (timestamp: Date) => string | undefined;
4
4
  export declare function formatLogLevel(level: number): string;
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,oBAAY,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;AAExD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,CAAC,SAAS,EAAE,IAAI,KAAK,MAAM,GAAG,SAAS,CAgBzG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAE3C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,SAEzE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,SAElD"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;AAExD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,CAAC,SAAS,EAAE,IAAI,KAAK,MAAM,GAAG,SAAS,CAgBzG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAE3C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,SAEzE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,SAElD"}
package/cjs/formatter.js CHANGED
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.consoleFormatter = exports.plainLogFormatter = exports.formatLogLevel = exports.createTimestampFormatter = void 0;
16
16
  var ms_1 = __importDefault(require("ms"));
17
17
  var upper_case_1 = require("upper-case");
18
- var logLevels_js_1 = require("./logLevels.js");
18
+ var log_levels_js_1 = require("./log_levels.js");
19
19
  function createTimestampFormatter(format) {
20
20
  switch (format) {
21
21
  case 'none':
@@ -35,7 +35,7 @@ function createTimestampFormatter(format) {
35
35
  }
36
36
  exports.createTimestampFormatter = createTimestampFormatter;
37
37
  function formatLogLevel(level) {
38
- return "(".concat((0, upper_case_1.upperCase)((0, logLevels_js_1.toLogLevelName)(level)), ")");
38
+ return "(".concat((0, upper_case_1.upperCase)((0, log_levels_js_1.toLogLevelName)(level)), ")");
39
39
  }
40
40
  exports.formatLogLevel = formatLogLevel;
41
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAmB;AACnB,yCAAsC;AACtC,+CAA+C;AAK/C,SAAgB,wBAAwB,CAAC,MAAuB;IAC9D,QAAQ,MAAM,EAAE;QACd,KAAK,MAAM;YACT,OAAO,UAAC,UAAgB,IAAK,OAAA,SAAS,EAAT,CAAS,CAAA;QACxC,KAAK,KAAK;YACR,OAAO,UAAC,SAAe,IAAK,OAAA,SAAS,CAAC,WAAW,EAAE,EAAvB,CAAuB,CAAA;QACrD,KAAK,SAAS,CAAC,CAAC;YACd,IAAI,UAAgB,CAAA;YACpB,OAAO,UAAC,SAAe;gBACrB,IAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,CAAA;gBACnC,IAAM,MAAM,GAAG,IAAA,YAAE,EAAC,UAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,UAAQ,CAAC,CAAA;gBAClE,UAAQ,GAAG,OAAO,CAAA;gBAClB,OAAO,MAAM,CAAA;YACf,CAAC,CAAA;SACF;KACF;AACH,CAAC;AAhBD,4DAgBC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,OAAO,WAAI,IAAA,sBAAS,EAAC,IAAA,6BAAc,EAAC,KAAK,CAAC,CAAC,MAAG,CAAA;AAChD,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,EAAwC;QAAtC,EAAE,QAAA,EAAE,KAAK,WAAA,EAAE,IAAI,UAAA,EAAE,SAAS,eAAA;IAC5D,sBAAQ,SAAS,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,GAAK,IAAI,QAAC;AACtE,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,EAAkB;QAAhB,IAAI,UAAA;IACrC,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,4CAEC","sourcesContent":["import ms from 'ms'\nimport { upperCase } from 'upper-case'\nimport { toLogLevelName } from './logLevels.js'\nimport type { LogEntry } from './types.js'\n\nexport type TimestampFormat = 'none' | 'iso' | 'elapsed'\n\nexport function createTimestampFormatter(format: TimestampFormat): (timestamp: Date) => string | undefined {\n switch (format) {\n case 'none':\n return (_timestamp: Date) => undefined\n case 'iso':\n return (timestamp: Date) => timestamp.toISOString()\n case 'elapsed': {\n let lastTick: number\n return (timestamp: Date) => {\n const newTick = timestamp.getTime()\n const result = ms(lastTick === undefined ? 0 : newTick - lastTick)\n lastTick = newTick\n return result\n }\n }\n }\n}\n\nexport function formatLogLevel(level: number) {\n return `(${upperCase(toLogLevelName(level))})`\n}\n\n/**\n * Formats log entry as plain text with the following format:\n * `timestamp id level ...args`\n *\n * This is typically useful for writing logs to file\n */\nexport function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {\n return [timestamp.toISOString(), id, formatLogLevel(level), ...args]\n}\n\n/**\n * Formats log entry like default console log.\n */\nexport function consoleFormatter({ args }: LogEntry) {\n return args\n}\n"]}
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAmB;AACnB,yCAAsC;AACtC,iDAAgD;AAKhD,SAAgB,wBAAwB,CAAC,MAAuB;IAC/D,QAAQ,MAAM,EAAE;QACf,KAAK,MAAM;YACV,OAAO,UAAC,UAAgB,IAAK,OAAA,SAAS,EAAT,CAAS,CAAA;QACvC,KAAK,KAAK;YACT,OAAO,UAAC,SAAe,IAAK,OAAA,SAAS,CAAC,WAAW,EAAE,EAAvB,CAAuB,CAAA;QACpD,KAAK,SAAS,CAAC,CAAC;YACf,IAAI,UAAgB,CAAA;YACpB,OAAO,UAAC,SAAe;gBACtB,IAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,CAAA;gBACnC,IAAM,MAAM,GAAG,IAAA,YAAE,EAAC,UAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,UAAQ,CAAC,CAAA;gBAClE,UAAQ,GAAG,OAAO,CAAA;gBAClB,OAAO,MAAM,CAAA;YACd,CAAC,CAAA;SACD;KACD;AACF,CAAC;AAhBD,4DAgBC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC3C,OAAO,WAAI,IAAA,sBAAS,EAAC,IAAA,8BAAc,EAAC,KAAK,CAAC,CAAC,MAAG,CAAA;AAC/C,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,EAAwC;QAAtC,EAAE,QAAA,EAAE,KAAK,WAAA,EAAE,IAAI,UAAA,EAAE,SAAS,eAAA;IAC7D,sBAAQ,SAAS,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,GAAK,IAAI,QAAC;AACrE,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,EAAkB;QAAhB,IAAI,UAAA;IACtC,OAAO,IAAI,CAAA;AACZ,CAAC;AAFD,4CAEC","sourcesContent":["import ms from 'ms'\nimport { upperCase } from 'upper-case'\nimport { toLogLevelName } from './log_levels.js'\nimport type { LogEntry } from './types.js'\n\nexport type TimestampFormat = 'none' | 'iso' | 'elapsed'\n\nexport function createTimestampFormatter(format: TimestampFormat): (timestamp: Date) => string | undefined {\n\tswitch (format) {\n\t\tcase 'none':\n\t\t\treturn (_timestamp: Date) => undefined\n\t\tcase 'iso':\n\t\t\treturn (timestamp: Date) => timestamp.toISOString()\n\t\tcase 'elapsed': {\n\t\t\tlet lastTick: number\n\t\t\treturn (timestamp: Date) => {\n\t\t\t\tconst newTick = timestamp.getTime()\n\t\t\t\tconst result = ms(lastTick === undefined ? 0 : newTick - lastTick)\n\t\t\t\tlastTick = newTick\n\t\t\t\treturn result\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function formatLogLevel(level: number) {\n\treturn `(${upperCase(toLogLevelName(level))})`\n}\n\n/**\n * Formats log entry as plain text with the following format:\n * `timestamp id level ...args`\n *\n * This is typically useful for writing logs to file\n */\nexport function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {\n\treturn [timestamp.toISOString(), id, formatLogLevel(level), ...args]\n}\n\n/**\n * Formats log entry like default console log.\n */\nexport function consoleFormatter({ args }: LogEntry) {\n\treturn args\n}\n"]}
package/cjs/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export * from './console.js';
2
2
  export * from './errors.js';
3
3
  export * from './formatter.js';
4
- export * from './logLevels.js';
4
+ export * from './log_levels.js';
5
5
  export * from './memory.js';
6
- export { configGlobal, createStandardLog, createStandardLogForTest, getLogger, suppressLogs } from './standardLog.js';
7
- export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js';
8
- export type { ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel, LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter, StandardLogInstance, StandardLogOptions } from './types.js';
6
+ export { configGlobal, createStandardLog, getLogger, suppressLogs } from './standard_log.js';
7
+ export type { GetLogger, StandardLog } from './standard_log.js';
8
+ export type { ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, LogLevel, LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, Logger, LoggerOptions, ReporterFilter, StandardLogInstance, StandardLogOptions } from './types.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,OAAO,EACL,YAAY,EAAE,iBAAiB,EAAE,wBAAwB,EACzD,SAAS,EAAE,YAAY,EACxB,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAClF,YAAY,EACV,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAC5F,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EACzF,mBAAmB,EAAE,kBAAkB,EACxC,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC5F,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/D,YAAY,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,MAAM,EACN,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,YAAY,CAAA"}
package/cjs/index.js CHANGED
@@ -14,16 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.suppressLogs = exports.getLogger = exports.createStandardLogForTest = exports.createStandardLog = exports.configGlobal = void 0;
17
+ exports.suppressLogs = exports.getLogger = exports.createStandardLog = exports.configGlobal = void 0;
18
18
  __exportStar(require("./console.js"), exports);
19
19
  __exportStar(require("./errors.js"), exports);
20
20
  __exportStar(require("./formatter.js"), exports);
21
- __exportStar(require("./logLevels.js"), exports);
21
+ __exportStar(require("./log_levels.js"), exports);
22
22
  __exportStar(require("./memory.js"), exports);
23
- var standardLog_js_1 = require("./standardLog.js");
24
- Object.defineProperty(exports, "configGlobal", { enumerable: true, get: function () { return standardLog_js_1.configGlobal; } });
25
- Object.defineProperty(exports, "createStandardLog", { enumerable: true, get: function () { return standardLog_js_1.createStandardLog; } });
26
- Object.defineProperty(exports, "createStandardLogForTest", { enumerable: true, get: function () { return standardLog_js_1.createStandardLogForTest; } });
27
- Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return standardLog_js_1.getLogger; } });
28
- Object.defineProperty(exports, "suppressLogs", { enumerable: true, get: function () { return standardLog_js_1.suppressLogs; } });
23
+ var standard_log_js_1 = require("./standard_log.js");
24
+ Object.defineProperty(exports, "configGlobal", { enumerable: true, get: function () { return standard_log_js_1.configGlobal; } });
25
+ Object.defineProperty(exports, "createStandardLog", { enumerable: true, get: function () { return standard_log_js_1.createStandardLog; } });
26
+ Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return standard_log_js_1.getLogger; } });
27
+ Object.defineProperty(exports, "suppressLogs", { enumerable: true, get: function () { return standard_log_js_1.suppressLogs; } });
29
28
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,8CAA2B;AAC3B,iDAA8B;AAC9B,iDAA8B;AAC9B,8CAA2B;AAC3B,mDAGyB;AAFvB,8GAAA,YAAY,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAAE,0HAAA,wBAAwB,OAAA;AACzD,2GAAA,SAAS,OAAA;AAAE,8GAAA,YAAY,OAAA","sourcesContent":["export * from './console.js'\nexport * from './errors.js'\nexport * from './formatter.js'\nexport * from './logLevels.js'\nexport * from './memory.js'\nexport {\n configGlobal, createStandardLog, createStandardLogForTest,\n getLogger, suppressLogs\n} from './standardLog.js'\nexport type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'\nexport type {\n ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel,\n LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter,\n StandardLogInstance, StandardLogOptions\n} from './types.js'\n\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,8CAA2B;AAC3B,iDAA8B;AAC9B,kDAA+B;AAC/B,8CAA2B;AAC3B,qDAA4F;AAAnF,+GAAA,YAAY,OAAA;AAAE,oHAAA,iBAAiB,OAAA;AAAE,4GAAA,SAAS,OAAA;AAAE,+GAAA,YAAY,OAAA","sourcesContent":["export * from './console.js'\nexport * from './errors.js'\nexport * from './formatter.js'\nexport * from './log_levels.js'\nexport * from './memory.js'\nexport { configGlobal, createStandardLog, getLogger, suppressLogs } from './standard_log.js'\nexport type { GetLogger, StandardLog } from './standard_log.js'\nexport type {\n\tConsoleLike,\n\tLogEntry,\n\tLogFilter,\n\tLogFormatter,\n\tLogFunction,\n\tLogLevel,\n\tLogLevelEntry,\n\tLogMethod,\n\tLogMethodNames,\n\tLogReporter,\n\tLogReporterOptions,\n\tLogger,\n\tLoggerOptions,\n\tReporterFilter,\n\tStandardLogInstance,\n\tStandardLogOptions\n} from './types.js'\n"]}
@@ -78,4 +78,4 @@ export declare function toLogLevelName(level: number): "emergency" | "alert" | "
78
78
  */
79
79
  export declare function toLogLevel(name: string): number | undefined;
80
80
  export declare const DEFAULT_LOG_METHOD_NAMES: string[];
81
- //# sourceMappingURL=logLevels.d.ts.map
81
+ //# sourceMappingURL=log_levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_levels.d.ts","sourceRoot":"","sources":["../ts/log_levels.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;IACrB;;OAEG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;CAEH,CAAA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,4GAW3C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAW5C,CAAA"}
@@ -116,4 +116,4 @@ exports.DEFAULT_LOG_METHOD_NAMES = [
116
116
  'trace',
117
117
  'planck'
118
118
  ];
119
- //# sourceMappingURL=logLevels.js.map
119
+ //# sourceMappingURL=log_levels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_levels.js","sourceRoot":"","sources":["../ts/log_levels.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,CAAU;IAChB;;;;OAIG;IACH,SAAS,EAAE,GAAY;IACvB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,QAAQ,EAAE,GAAY;IACtB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,MAAM,EAAE,GAAY;IACpB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;;OAKG;IACH,MAAM,EAAE,QAAQ;IAChB;;OAEG;IACH,GAAG,EAAE,QAAQ;CACb,CAAA;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAa;IAC3C,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,WAAW,CAAA;IACpC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IACnC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,QAAQ,CAAA;IACjC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,OAAO,QAAQ,CAAA;AAChB,CAAC;AAXD,wCAWC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY;IACtC,OAAQ,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;AACpD,CAAC;AAFD,gCAEC;AAEY,QAAA,wBAAwB,GAAa;IACjD,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACR,CAAA","sourcesContent":["export const logLevels = {\n\t/**\n\t * none: 0\n\t */\n\tnone: 0 as const,\n\t/**\n\t * emergency: 100\n\t *\n\t * emergency -> alert\n\t */\n\temergency: 100 as const,\n\t/**\n\t * alert: 200\n\t *\n\t * emergency -> alert -> critical\n\t */\n\talert: 200 as const,\n\t/**\n\t * critical: 300\n\t *\n\t * alert -> critical -> error\n\t */\n\tcritical: 300 as const,\n\t/**\n\t * error: 400\n\t *\n\t * critical -> error -> warn\n\t */\n\terror: 400 as const,\n\t/**\n\t * warn: 500\n\t *\n\t * error -> warn -> notice\n\t */\n\twarn: 500 as const,\n\t/**\n\t * notice: 600\n\t *\n\t * warn -> notice -> info\n\t */\n\tnotice: 600 as const,\n\t/**\n\t * info: 700\n\t *\n\t * notice -> info -> debug\n\t */\n\tinfo: 700 as const,\n\t/**\n\t * debug: 800\n\t *\n\t * info -> debug -> trace\n\t */\n\tdebug: 800 as const,\n\t/**\n\t * trace: 900\n\t *\n\t * debug -> trace -> planck\n\t */\n\ttrace: 900 as const,\n\t/**\n\t * planck: Infinity\n\t * `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.\n\t *\n\t * trace -> planck\n\t */\n\tplanck: Infinity,\n\t/**\n\t * all: Infinity\n\t */\n\tall: Infinity\n}\n\n/**\n * Convert default log level value to log level name.\n */\nexport function toLogLevelName(level: number) {\n\tif (level <= 100) return 'emergency'\n\tif (level <= 200) return 'alert'\n\tif (level <= 300) return 'critical'\n\tif (level <= 400) return 'error'\n\tif (level <= 500) return 'warn'\n\tif (level <= 600) return 'notice'\n\tif (level <= 700) return 'info'\n\tif (level <= 800) return 'debug'\n\tif (level <= 900) return 'trace'\n\treturn 'planck'\n}\n\n/**\n * Convert default log level name to log level value.\n */\nexport function toLogLevel(name: string): number | undefined {\n\treturn (logLevels as any)[name.toLocaleLowerCase()]\n}\n\nexport const DEFAULT_LOG_METHOD_NAMES: string[] = [\n\t'emergency',\n\t'alert',\n\t'critical',\n\t'error',\n\t'warn',\n\t'notice',\n\t'info',\n\t'debug',\n\t'trace',\n\t'planck'\n]\n"]}
@@ -18,4 +18,4 @@ export declare function logLevelStore(options: LogLevelStoreOptions): {
18
18
  level: number;
19
19
  }[];
20
20
  };
21
- //# sourceMappingURL=logStore.d.ts.map
21
+ //# sourceMappingURL=log_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../ts/log_store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC/D,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GACtC,QAAQ,CAQV;AAED,MAAM,WAAW,QAAQ;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,EAAE,WAAW,EAAE,CAAA;IACxB,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA;CAC/C;AAED,MAAM,WAAW,oBAAoB;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB;mBAe1C,MAAM;mBAGN,MAAM;;;;;EAetB"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logLevelStore = exports.createLogStore = void 0;
4
4
  var type_plus_1 = require("type-plus");
5
5
  var console_js_1 = require("./console.js");
6
- var logLevels_js_1 = require("./logLevels.js");
6
+ var log_levels_js_1 = require("./log_levels.js");
7
7
  function createLogStore(options) {
8
8
  return {
9
9
  loggers: (0, type_plus_1.record)(),
@@ -26,20 +26,20 @@ function logLevelStore(options) {
26
26
  return {
27
27
  getName: function (level) {
28
28
  var _a;
29
- return (_a = store.customLevelsReverse[level]) !== null && _a !== void 0 ? _a : (0, logLevels_js_1.toLogLevelName)(level);
29
+ return (_a = store.customLevelsReverse[level]) !== null && _a !== void 0 ? _a : (0, log_levels_js_1.toLogLevelName)(level);
30
30
  },
31
31
  getLevel: function (name) {
32
32
  var _a;
33
- return (_a = store.customLevels[name]) !== null && _a !== void 0 ? _a : (0, logLevels_js_1.toLogLevel)(name);
33
+ return (_a = store.customLevels[name]) !== null && _a !== void 0 ? _a : (0, log_levels_js_1.toLogLevel)(name);
34
34
  },
35
35
  getAllLevels: function () {
36
- return (0, type_plus_1.reduceKey)(logLevels_js_1.logLevels, function (result, name) {
36
+ return (0, type_plus_1.reduceKey)(log_levels_js_1.logLevels, function (result, name) {
37
37
  if (name !== 'none' && name !== 'all')
38
- result.push({ name: name, level: logLevels_js_1.logLevels[name] });
38
+ result.push({ name: name, level: log_levels_js_1.logLevels[name] });
39
39
  return result;
40
40
  }, (0, type_plus_1.mapKey)(store.customLevels, function (name) { return ({ name: name, level: store.customLevels[name] }); }));
41
41
  }
42
42
  };
43
43
  }
44
44
  exports.logLevelStore = logLevelStore;
45
- //# sourceMappingURL=logStore.js.map
45
+ //# sourceMappingURL=log_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_store.js","sourceRoot":"","sources":["../ts/log_store.ts"],"names":[],"mappings":";;;AAAA,uCAAkE;AAClE,2CAAuD;AACvD,iDAAuE;AAGvE,SAAgB,cAAc,CAC7B,OAAwC;IAExC,OAAO;QACN,OAAO,EAAE,IAAA,kBAAM,GAAE;QACjB,iBAAiB,EAAE,IAAA,kBAAM,GAAE;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,IAAA,qCAAwB,GAAE,CAAC;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC;KACrC,CAAA;AACF,CAAC;AAVD,wCAUC;AAcD,SAAgB,aAAa,CAAC,OAA6B;IAC1D,IAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAA,kBAAM,GAAE,CAAA;IAErD,IAAM,KAAK,GAAG;QACb,YAAY,cAAA;QACZ,mBAAmB,EAAE,IAAA,uBAAW,EAC/B,YAAY,EACZ,UAAC,CAAC,EAAE,CAAC;YACJ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;YACtB,OAAO,CAAC,CAAA;QACT,CAAC,EACD,EAA4B,CAC5B;KACD,CAAA;IACD,OAAO;QACN,OAAO,YAAC,KAAa;;YACpB,OAAO,MAAA,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,mCAAI,IAAA,8BAAc,EAAC,KAAK,CAAC,CAAA;QACjE,CAAC;QACD,QAAQ,YAAC,IAAY;;YACpB,OAAO,MAAA,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,IAAA,0BAAU,EAAC,IAAI,CAAC,CAAA;QACpD,CAAC;QACD,YAAY;YACX,OAAO,IAAA,qBAAS,EACf,yBAAS,EACT,UAAC,MAAM,EAAE,IAAI;gBACZ,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK;oBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,yBAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAEpF,OAAO,MAAM,CAAA;YACd,CAAC,EACD,IAAA,kBAAM,EAAC,KAAK,CAAC,YAAY,EAAE,UAAA,IAAI,IAAI,OAAA,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAA3C,CAA2C,CAAC,CAC/E,CAAA;QACF,CAAC;KACD,CAAA;AACF,CAAC;AAjCD,sCAiCC","sourcesContent":["import { mapKey, record, reduceByKey, reduceKey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './log_levels.js'\nimport type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore<N extends string = LogMethodNames>(\n\toptions: Required<StandardLogOptions<N>>\n): LogStore {\n\treturn {\n\t\tloggers: record(),\n\t\tnonConsoleLoggers: record(),\n\t\treporters: options.reporters || [createConsoleLogReporter()],\n\t\tlogLevel: options.logLevel,\n\t\tlogLevelStore: logLevelStore(options)\n\t}\n}\n\nexport interface LogStore {\n\tloggers: Record<string, Logger>\n\tnonConsoleLoggers: Record<string, Logger>\n\treporters: LogReporter[]\n\tlogLevel: LogLevel\n\tlogLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n\tcustomLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n\tconst customLevels = options.customLevels || record()\n\n\tconst store = {\n\t\tcustomLevels,\n\t\tcustomLevelsReverse: reduceByKey(\n\t\t\tcustomLevels,\n\t\t\t(p, k) => {\n\t\t\t\tp[customLevels[k]] = k\n\t\t\t\treturn p\n\t\t\t},\n\t\t\t{} as Record<number, string>\n\t\t)\n\t}\n\treturn {\n\t\tgetName(level: number) {\n\t\t\treturn store.customLevelsReverse[level] ?? toLogLevelName(level)\n\t\t},\n\t\tgetLevel(name: string) {\n\t\t\treturn store.customLevels[name] ?? toLogLevel(name)\n\t\t},\n\t\tgetAllLevels() {\n\t\t\treturn reduceKey(\n\t\t\t\tlogLevels,\n\t\t\t\t(result, name) => {\n\t\t\t\t\tif (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n\t\t\t\t\treturn result\n\t\t\t\t},\n\t\t\t\tmapKey(store.customLevels, name => ({ name, level: store.customLevels[name] }))\n\t\t\t)\n\t\t}\n\t}\n}\n"]}
package/cjs/logger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LogStore } from './logStore.js';
1
+ import { LogStore } from './log_store.js';
2
2
  import type { Logger, LoggerOptions, LogMethodNames } from './types.js';
3
3
  export declare function createLogger<N extends string = LogMethodNames>(store: LogStore, id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
4
4
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAyB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAG3G,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC5D,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GACnD,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CAwD5B"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAyB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAG3G,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC7D,KAAK,EAAE,QAAQ,EACf,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CA4D5B"}
package/cjs/logger.js CHANGED
@@ -10,7 +10,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createLogger = void 0;
13
- var logLevels_js_1 = require("./logLevels.js");
13
+ var log_levels_js_1 = require("./log_levels.js");
14
14
  function createLogger(store, id, options) {
15
15
  var _a;
16
16
  id = sanitizeId(id);
@@ -33,19 +33,21 @@ function createLogger(store, id, options) {
33
33
  id: { value: id, writable: false },
34
34
  count: {
35
35
  writable: false,
36
- value: (function (counter) { return function () {
37
- var args = [];
38
- for (var _i = 0; _i < arguments.length; _i++) {
39
- args[_i] = arguments[_i];
40
- }
41
- if (shouldLog(store, logLevels_js_1.logLevels.debug, logger.level))
42
- write({
43
- id: id,
44
- level: logLevels_js_1.logLevels.debug,
45
- args: __spreadArray([++counter], args, true),
46
- timestamp: new Date()
47
- });
48
- }; })(0)
36
+ value: (function (counter) {
37
+ return function () {
38
+ var args = [];
39
+ for (var _i = 0; _i < arguments.length; _i++) {
40
+ args[_i] = arguments[_i];
41
+ }
42
+ if (shouldLog(store, log_levels_js_1.logLevels.debug, logger.level))
43
+ write({
44
+ id: id,
45
+ level: log_levels_js_1.logLevels.debug,
46
+ args: __spreadArray([++counter], args, true),
47
+ timestamp: new Date()
48
+ });
49
+ };
50
+ })(0)
49
51
  },
50
52
  on: {
51
53
  writable: false,
package/cjs/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";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AAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;YAClC,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE;gBAAC,cAAc;qBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;oBAAd,yBAAc;;gBACpB,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;oBAAE,KAAK,CAAC,EAAE,EAAE,IAAA,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC9F,CAAC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AA1DD,oCA0DC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,EAAE,CAAC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAwB,EAAE,QAAkB,EAAE,MAAuC;IAC7G,SAAS,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,EAAlB,CAAkB,CAAC,CAAA;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC1F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC","sourcesContent":["import { logLevels } from './logLevels.js'\nimport { LogStore } from './logStore.js'\nimport type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<N extends string = LogMethodNames>(\n store: LogStore, id: string, options?: LoggerOptions\n): Logger<N | LogMethodNames> {\n id = sanitizeId(id)\n const writeTo = options?.writeTo ?? (() => true)\n const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'\n ? [id => id === writeTo, store.reporters]\n : writeTo instanceof RegExp\n ? [id => writeTo.test(id), store.reporters]\n : typeof writeTo === 'function'\n ? [writeTo, store.reporters]\n : [() => true, [writeTo]]\n\n function write(entry: LogEntry) {\n writeToReporters(reporters, entry, filter)\n }\n\n const logger = {\n level: options?.level,\n write\n } as any\n\n Object.defineProperties(logger, {\n id: { value: id, writable: false },\n count: {\n writable: false,\n value: ((counter) => (...args: any[]) => {\n if (shouldLog(store, logLevels.debug, logger.level))\n write({\n id,\n level: logLevels.debug,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n if (shouldLog(store, logLevel, logger.level)) {\n const methodName = store.logLevelStore.getName(logLevel)\n const bindedMethod = logger[methodName].bind(logger)\n const result = logFn(bindedMethod, logger.level ?? store.logLevel)\n if (result) bindedMethod(result)\n }\n }\n }\n })\n store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n Object.defineProperty(logger, name, {\n writable: false,\n value: (...args: any[]) => {\n if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n }\n })\n })\n return logger\n}\n\nfunction sanitizeId(id: string) {\n return id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {\n reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n return target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ogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<N extends string = LogMethodNames>(\n\tstore: LogStore,\n\tid: string,\n\toptions?: LoggerOptions\n): Logger<N | LogMethodNames> {\n\tid = sanitizeId(id)\n\tconst writeTo = options?.writeTo ?? (() => true)\n\tconst [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] =\n\t\ttypeof writeTo === 'string'\n\t\t\t? [id => id === writeTo, store.reporters]\n\t\t\t: writeTo instanceof RegExp\n\t\t\t? [id => writeTo.test(id), store.reporters]\n\t\t\t: typeof writeTo === 'function'\n\t\t\t? [writeTo, store.reporters]\n\t\t\t: [() => true, [writeTo]]\n\n\tfunction write(entry: LogEntry) {\n\t\twriteToReporters(reporters, entry, filter)\n\t}\n\n\tconst logger = {\n\t\tlevel: options?.level,\n\t\twrite\n\t} as any\n\n\tObject.defineProperties(logger, {\n\t\tid: { value: id, writable: false },\n\t\tcount: {\n\t\t\twritable: false,\n\t\t\tvalue: (\n\t\t\t\tcounter =>\n\t\t\t\t(...args: any[]) => {\n\t\t\t\t\tif (shouldLog(store, logLevels.debug, logger.level))\n\t\t\t\t\t\twrite({\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tlevel: logLevels.debug,\n\t\t\t\t\t\t\targs: [++counter, ...args],\n\t\t\t\t\t\t\ttimestamp: new Date()\n\t\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t)(0)\n\t\t},\n\t\ton: {\n\t\t\twritable: false,\n\t\t\tvalue: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n\t\t\t\tconst logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n\t\t\t\tif (shouldLog(store, logLevel, logger.level)) {\n\t\t\t\t\tconst methodName = store.logLevelStore.getName(logLevel)\n\t\t\t\t\tconst bindedMethod = logger[methodName].bind(logger)\n\t\t\t\t\tconst result = logFn(bindedMethod, logger.level ?? store.logLevel)\n\t\t\t\t\tif (result) bindedMethod(result)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n\tstore.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n\t\tObject.defineProperty(logger, name, {\n\t\t\twritable: false,\n\t\t\tvalue: (...args: any[]) => {\n\t\t\t\tif (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n\t\t\t}\n\t\t})\n\t})\n\treturn logger\n}\n\nfunction sanitizeId(id: string) {\n\treturn id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(\n\treporters: LogReporter[],\n\tlogEntry: LogEntry,\n\tfilter: (reporterId: string) => boolean\n) {\n\treporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n\treturn targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
package/cjs/memory.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
2
- export declare type MemoryLogReporter = LogReporter<LogEntry> & {
2
+ export type MemoryLogReporter = LogReporter<LogEntry> & {
3
3
  logs: LogEntry[];
4
4
  /**
5
5
  * Gets a simple log message for testing.
@@ -11,7 +11,7 @@ export declare type MemoryLogReporter = LogReporter<LogEntry> & {
11
11
  getLogMessagesWithIdAndLevel(): string[];
12
12
  emit(): void;
13
13
  };
14
- export declare type MemoryLogFormatter = LogFormatter<LogEntry>;
14
+ export type MemoryLogFormatter = LogFormatter<LogEntry>;
15
15
  export declare function toMessageWithLevel(logs: LogEntry[]): string;
16
16
  export declare function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter;
17
17
  export declare function createMemoryWithConsoleLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,sBAAsB,IAAI,MAAM,CAAC;IACjC,4BAA4B,IAAI,MAAM,EAAE,CAAC;IACzC,IAAI,IAAI,IAAI,CAAA;CACb,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAEjG;AAoCD,wBAAgB,kCAAkC,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAK5G"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACvD,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAA;IACvB,cAAc,IAAI,MAAM,EAAE,CAAA;IAC1B,sBAAsB,IAAI,MAAM,CAAA;IAChC,4BAA4B,IAAI,MAAM,EAAE,CAAA;IACxC,IAAI,IAAI,IAAI,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAWlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAEjG;AA0CD,wBAAgB,kCAAkC,CACjD,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,iBAAiB,CAMnB"}
package/cjs/memory.js CHANGED
@@ -6,13 +6,14 @@ var platform_js_1 = require("./platform.js");
6
6
  var formatter_js_1 = require("./formatter.js");
7
7
  var console_js_1 = require("./console.js");
8
8
  function toMessageWithLevel(logs) {
9
- return logs.map(platform_js_1.toInspectLogEntry)
9
+ return (logs
10
+ .map(platform_js_1.toInspectLogEntry)
10
11
  .map(function (log) { return "".concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); })
11
12
  .join('\n')
12
13
  // if it has more than this log,
13
14
  // we assume it is running under tests,
14
15
  // and remove this log to simplify testing.
15
- .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '');
16
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, ''));
16
17
  }
17
18
  exports.toMessageWithLevel = toMessageWithLevel;
18
19
  function createMemoryLogReporter(options) {
@@ -24,8 +25,12 @@ function buildMemoryReporter(options) {
24
25
  var logs = [];
25
26
  return {
26
27
  id: id,
27
- get formatter() { return formatter; },
28
- get filter() { return filter; },
28
+ get formatter() {
29
+ return formatter;
30
+ },
31
+ get filter() {
32
+ return filter;
33
+ },
29
34
  logs: logs,
30
35
  write: function (entry) {
31
36
  if (filter && !filter(entry))
@@ -36,14 +41,16 @@ function buildMemoryReporter(options) {
36
41
  return this.getLogMessages().join('\n');
37
42
  },
38
43
  getLogMessages: function () {
39
- return logs.map(platform_js_1.toInspectLogEntry)
40
- .map(function (log) { return log.args.join(' '); });
44
+ return logs.map(platform_js_1.toInspectLogEntry).map(function (log) { return log.args.join(' '); });
41
45
  },
42
46
  getLogMessagesWithIdAndLevel: function () {
43
- return logs.map(platform_js_1.toInspectLogEntry)
47
+ return logs
48
+ .map(platform_js_1.toInspectLogEntry)
44
49
  .map(function (log) { return "".concat(log.id, " ").concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); });
45
50
  },
46
- getLogMessageWithLevel: function () { return toMessageWithLevel(logs); },
51
+ getLogMessageWithLevel: function () {
52
+ return toMessageWithLevel(logs);
53
+ },
47
54
  /**
48
55
  * emit the saved log to console for easy debugging
49
56
  */
package/cjs/memory.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,6CAAiD;AACjD,+CAA+C;AAE/C,2CAAuD;AAiBvD,SAAgB,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,+BAAiB,CAAC;SAC/B,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAApD,CAAoD,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAAA;AACrF,CAAC;AARD,gDAQC;AAED,SAAgB,uBAAuB,CAAC,OAAsC;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;AACjF,CAAC;AAFD,0DAEC;AAED,SAAS,mBAAmB,CAAC,OAAsC;IAC3D,IAAA,KAA4B,IAAA,oBAAQ,EAA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,qCAAwB,GAAE,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC,CAAA;QACtC,CAAC;KACF,CAAA;AACH,CAAC;AAED,SAAgB,kCAAkC,CAAC,OAAsC;IACvF,OAAO,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE;QACpF,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC,CAAA;AACP,CAAC;AALD,gFAKC","sourcesContent":["import { required, unpartial } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n logs: LogEntry[],\n /**\n * Gets a simple log message for testing.\n * The message only contains arguments for each log entry.\n */\n getLogMessage(): string,\n getLogMessages(): string[],\n getLogMessageWithLevel(): string,\n getLogMessagesWithIdAndLevel(): string[],\n emit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry)\n .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n .join('\\n')\n // if it has more than this log,\n // we assume it is running under tests,\n // and remove this log to simplify testing.\n .replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n return Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))\n}\n\nfunction buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {\n const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const logs: LogEntry[] = []\n return {\n id,\n get formatter() { return formatter },\n get filter() { return filter },\n logs,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n logs.push(formatter(entry))\n },\n getLogMessage() {\n return this.getLogMessages().join('\\n')\n },\n getLogMessages() {\n return logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n },\n getLogMessagesWithIdAndLevel() {\n return logs.map(toInspectLogEntry)\n .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n },\n getLogMessageWithLevel() { return toMessageWithLevel(logs) },\n /**\n * emit the saved log to console for easy debugging\n */\n emit() {\n const reporter = createConsoleLogReporter()\n logs.forEach(l => reporter.write(l))\n }\n }\n}\n\nexport function createMemoryWithConsoleLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n return Object.freeze(\n Object.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {\n isConsoleReporter: true\n }))\n}\n"]}
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,6CAAiD;AACjD,+CAA+C;AAE/C,2CAAuD;AAiBvD,SAAgB,kBAAkB,CAAC,IAAgB;IAClD,OAAO,CACN,IAAI;SACF,GAAG,CAAC,+BAAiB,CAAC;SACtB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAApD,CAAoD,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAClF,CAAA;AACF,CAAC;AAXD,gDAWC;AAED,SAAgB,uBAAuB,CAAC,OAAsC;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA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AE,EAA9D,CAA8D,CAAC,CAAA;QAC7E,CAAC;QACD,sBAAsB;YACrB,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QACD;;WAEG;QACH,IAAI;YACH,IAAM,QAAQ,GAAG,IAAA,qCAAwB,GAAE,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC,CAAA;QACrC,CAAC;KACD,CAAA;AACF,CAAC;AAED,SAAgB,kCAAkC,CACjD,OAAsC;IAEtC,OAAO,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE;QACrF,iBAAiB,EAAE,IAAI;KACvB,CAAC,CACF,CAAA;AACF,CAAC;AARD,gFAQC","sourcesContent":["import { required, unpartial } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n\tlogs: LogEntry[]\n\t/**\n\t * Gets a simple log message for testing.\n\t * The message only contains arguments for each log entry.\n\t */\n\tgetLogMessage(): string\n\tgetLogMessages(): string[]\n\tgetLogMessageWithLevel(): string\n\tgetLogMessagesWithIdAndLevel(): string[]\n\temit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n\treturn (\n\t\tlogs\n\t\t\t.map(toInspectLogEntry)\n\t\t\t.map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t\t.join('\\n')\n\t\t\t// if it has more than this log,\n\t\t\t// we assume it is running under tests,\n\t\t\t// and remove this log to simplify testing.\n\t\t\t.replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n\t)\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n\treturn Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))\n}\n\nfunction buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {\n\tconst { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n\tconst logs: LogEntry[] = []\n\treturn {\n\t\tid,\n\t\tget formatter() {\n\t\t\treturn formatter\n\t\t},\n\t\tget filter() {\n\t\t\treturn filter\n\t\t},\n\t\tlogs,\n\t\twrite(entry: LogEntry) {\n\t\t\tif (filter && !filter(entry)) return\n\t\t\tlogs.push(formatter(entry))\n\t\t},\n\t\tgetLogMessage() {\n\t\t\treturn this.getLogMessages().join('\\n')\n\t\t},\n\t\tgetLogMessages() {\n\t\t\treturn logs.map(toInspectLogEntry).map(log => log.args.join(' '))\n\t\t},\n\t\tgetLogMessagesWithIdAndLevel() {\n\t\t\treturn logs\n\t\t\t\t.map(toInspectLogEntry)\n\t\t\t\t.map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t},\n\t\tgetLogMessageWithLevel() {\n\t\t\treturn toMessageWithLevel(logs)\n\t\t},\n\t\t/**\n\t\t * emit the saved log to console for easy debugging\n\t\t */\n\t\temit() {\n\t\t\tconst reporter = createConsoleLogReporter()\n\t\t\tlogs.forEach(l => reporter.write(l))\n\t\t}\n\t}\n}\n\nexport function createMemoryWithConsoleLogReporter(\n\toptions?: LogReporterOptions<LogEntry>\n): MemoryLogReporter {\n\treturn Object.freeze(\n\t\tObject.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {\n\t\t\tisConsoleReporter: true\n\t\t})\n\t)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAEzC,CAAA;AAEJ,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAa,CAAA"}
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAE5C,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAa,CAAA"}
package/cjs/platform.js CHANGED
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polyfill = exports.toInspectLogEntry = void 0;
4
4
  var type_plus_1 = require("type-plus");
5
5
  var util_1 = require("util");
6
- var toInspectLogEntry = function (e) { return (e.args = e.args.map(function (value) { return typeof value === 'object' && value !== null ? (0, util_1.inspect)(value) : value; }),
7
- e); };
6
+ var toInspectLogEntry = function (e) { return ((e.args = e.args.map(function (value) { return (typeof value === 'object' && value !== null ? (0, util_1.inspect)(value) : value); })), e); };
8
7
  exports.toInspectLogEntry = toInspectLogEntry;
9
8
  exports.polyfill = (0, type_plus_1.record)();
10
9
  //# sourceMappingURL=platform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAClC,6BAA8B;AAGvB,IAAM,iBAAiB,GAAG,UAAC,CAAW,IAAK,OAAA,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAApE,CAAoE,CAAC;IAClG,CAAC,CAAC,EAF8C,CAE9C,CAAA;AAFS,QAAA,iBAAiB,qBAE1B;AAES,QAAA,QAAQ,GAA8B,IAAA,kBAAM,GAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),\n e)\n\nexport const polyfill: { console?: ConsoleLike } = record()\n"]}
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAClC,6BAA8B;AAGvB,IAAM,iBAAiB,GAAG,UAAC,CAAW,IAAK,OAAA,CACjD,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAtE,CAAsE,CAAC,CAAC,EAAE,CAAC,CACzG,EAFiD,CAEjD,CAAA;AAFY,QAAA,iBAAiB,qBAE7B;AAEY,QAAA,QAAQ,GAA8B,IAAA,kBAAM,GAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n\t(e.args = e.args.map(value => (typeof value === 'object' && value !== null ? inspect(value) : value))), e\n)\n\nexport const polyfill: { console?: ConsoleLike } = record()\n"]}
@@ -1,4 +1,4 @@
1
- import type { LogStore } from './logStore.js';
1
+ import type { LogStore } from './log_store.js';
2
2
  import type { LogMethodNames, StandardLogInstance } from './types.js';
3
3
  export declare const ctx: {
4
4
  configured?: boolean;
@@ -7,4 +7,4 @@ export declare const ctx: {
7
7
  standardLog: StandardLogInstance<LogMethodNames>;
8
8
  };
9
9
  };
10
- //# sourceMappingURL=standardLog.ctx.d.ts.map
10
+ //# sourceMappingURL=standard_log.ctx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.ctx.d.ts","sourceRoot":"","sources":["../ts/standard_log.ctx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,eAAO,MAAM,GAAG,EAAE;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;KAAE,CAAA;CAChE,CAAA"}