standard-log 11.5.2 → 12.0.1

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 (109) hide show
  1. package/README.md +2 -3
  2. package/cjs/console.js +4 -4
  3. package/cjs/console.js.map +1 -1
  4. package/cjs/formatter.js +2 -2
  5. package/cjs/formatter.js.map +1 -1
  6. package/cjs/index.d.ts +4 -4
  7. package/cjs/index.d.ts.map +1 -1
  8. package/cjs/index.js +7 -8
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/{logLevels.d.ts → log_levels.d.ts} +1 -1
  11. package/cjs/log_levels.d.ts.map +1 -0
  12. package/cjs/{logLevels.js → log_levels.js} +1 -1
  13. package/{esm/logLevels.js.map → cjs/log_levels.js.map} +1 -1
  14. package/{esm/logStore.d.ts → cjs/log_store.d.ts} +1 -1
  15. package/cjs/log_store.d.ts.map +1 -0
  16. package/cjs/{logStore.js → log_store.js} +6 -6
  17. package/cjs/log_store.js.map +1 -0
  18. package/cjs/logger.d.ts +1 -1
  19. package/cjs/logger.d.ts.map +1 -1
  20. package/cjs/logger.js +3 -3
  21. package/cjs/logger.js.map +1 -1
  22. package/cjs/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  23. package/cjs/standard_log.ctx.d.ts.map +1 -0
  24. package/cjs/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  25. package/cjs/standard_log.ctx.js.map +1 -0
  26. package/{esm/standardLog.d.ts → cjs/standard_log.d.ts} +3 -8
  27. package/cjs/standard_log.d.ts.map +1 -0
  28. package/cjs/{standardLog.js → standard_log.js} +20 -28
  29. package/cjs/standard_log.js.map +1 -0
  30. package/cjs/standard_log.mocks.d.ts +8 -0
  31. package/cjs/standard_log.mocks.d.ts.map +1 -0
  32. package/cjs/standard_log.mocks.js +32 -0
  33. package/cjs/standard_log.mocks.js.map +1 -0
  34. package/cjs/testing/index.d.ts +2 -0
  35. package/cjs/testing/index.d.ts.map +1 -0
  36. package/cjs/testing/index.js +6 -0
  37. package/cjs/testing/index.js.map +1 -0
  38. package/dist/standard-log.es5.js +56 -65
  39. package/dist/standard-log.es5.js.gz +0 -0
  40. package/dist/standard-log.es5.js.map +1 -1
  41. package/dist/standard-log.es5.js.map.gz +0 -0
  42. package/dist/standard-log.esm.js +58 -67
  43. package/dist/standard-log.esm.js.gz +0 -0
  44. package/dist/standard-log.esm.js.map +1 -1
  45. package/dist/standard-log.esm.js.map.gz +0 -0
  46. package/esm/console.js +1 -1
  47. package/esm/console.js.map +1 -1
  48. package/esm/formatter.js +1 -1
  49. package/esm/formatter.js.map +1 -1
  50. package/esm/index.d.ts +4 -4
  51. package/esm/index.d.ts.map +1 -1
  52. package/esm/index.js +2 -2
  53. package/esm/index.js.map +1 -1
  54. package/esm/{logLevels.d.ts → log_levels.d.ts} +1 -1
  55. package/esm/log_levels.d.ts.map +1 -0
  56. package/esm/{logLevels.js → log_levels.js} +1 -1
  57. package/esm/log_levels.js.map +1 -0
  58. package/{cjs/logStore.d.ts → esm/log_store.d.ts} +1 -1
  59. package/esm/log_store.d.ts.map +1 -0
  60. package/esm/{logStore.js → log_store.js} +2 -2
  61. package/esm/log_store.js.map +1 -0
  62. package/esm/logger.d.ts +1 -1
  63. package/esm/logger.d.ts.map +1 -1
  64. package/esm/logger.js +1 -1
  65. package/esm/logger.js.map +1 -1
  66. package/esm/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  67. package/esm/standard_log.ctx.d.ts.map +1 -0
  68. package/esm/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  69. package/esm/standard_log.ctx.js.map +1 -0
  70. package/{cjs/standardLog.d.ts → esm/standard_log.d.ts} +3 -8
  71. package/esm/standard_log.d.ts.map +1 -0
  72. package/esm/{standardLog.js → standard_log.js} +4 -10
  73. package/esm/standard_log.js.map +1 -0
  74. package/esm/standard_log.mocks.d.ts +8 -0
  75. package/esm/standard_log.mocks.d.ts.map +1 -0
  76. package/esm/standard_log.mocks.js +16 -0
  77. package/esm/standard_log.mocks.js.map +1 -0
  78. package/esm/testing/index.d.ts +2 -0
  79. package/esm/testing/index.d.ts.map +1 -0
  80. package/esm/testing/index.js +2 -0
  81. package/esm/testing/index.js.map +1 -0
  82. package/package.json +8 -7
  83. package/testing/index.d.ts +1 -0
  84. package/testing/index.js +1 -0
  85. package/ts/console.ts +1 -1
  86. package/ts/formatter.ts +1 -1
  87. package/ts/index.ts +5 -11
  88. package/ts/{logStore.ts → log_store.ts} +1 -1
  89. package/ts/logger.ts +2 -2
  90. package/ts/{standardLog.ctx.ts → standard_log.ctx.ts} +1 -1
  91. package/ts/standard_log.mocks.ts +22 -0
  92. package/ts/{standardLog.ts → standard_log.ts} +4 -18
  93. package/ts/testing/index.ts +1 -0
  94. package/cjs/logLevels.d.ts.map +0 -1
  95. package/cjs/logLevels.js.map +0 -1
  96. package/cjs/logStore.d.ts.map +0 -1
  97. package/cjs/logStore.js.map +0 -1
  98. package/cjs/standardLog.ctx.d.ts.map +0 -1
  99. package/cjs/standardLog.ctx.js.map +0 -1
  100. package/cjs/standardLog.d.ts.map +0 -1
  101. package/cjs/standardLog.js.map +0 -1
  102. package/esm/logLevels.d.ts.map +0 -1
  103. package/esm/logStore.d.ts.map +0 -1
  104. package/esm/logStore.js.map +0 -1
  105. package/esm/standardLog.ctx.d.ts.map +0 -1
  106. package/esm/standardLog.ctx.js.map +0 -1
  107. package/esm/standardLog.d.ts.map +0 -1
  108. package/esm/standardLog.js.map +0 -1
  109. /package/ts/{logLevels.ts → log_levels.ts} +0 -0
package/esm/console.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { unpartial } from 'type-plus';
2
2
  import { consoleFormatter } from './formatter.js';
3
- import { logLevels } from './logLevels.js';
3
+ import { logLevels } from './log_levels.js';
4
4
  import { polyfill } from './platform.js';
5
5
  export function toConsoleMethod(level) {
6
6
  switch (true) {
@@ -1 +1 @@
1
- {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"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AM,CAAC,MAAM,CAAC;QACpB,EAAE;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,QAAQ,CAAC,OAAO;QACzB,KAAK,CAAC,KAAe;YACpB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAA;QAChC,CAAC;KACD,CAAC,CAAA;AACH,CAAC","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\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
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ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AAQ,CAAC,OAAO;QACzB,KAAK,CAAC,KAAe;YACpB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAA;QAChC,CAAC;KACD,CAAC,CAAA;AACH,CAAC","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"]}
package/esm/formatter.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import ms from 'ms';
2
2
  import { upperCase } from 'upper-case';
3
- import { toLogLevelName } from './logLevels.js';
3
+ import { toLogLevelName } from './log_levels.js';
4
4
  export function createTimestampFormatter(format) {
5
5
  switch (format) {
6
6
  case 'none':
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,MAAM,UAAU,wBAAwB,CAAC,MAAuB;IAC/D,QAAQ,MAAM,EAAE;QACf,KAAK,MAAM;YACV,OAAO,CAAC,UAAgB,EAAE,EAAE,CAAC,SAAS,CAAA;QACvC,KAAK,KAAK;YACT,OAAO,CAAC,SAAe,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,CAAA;QACpD,KAAK,SAAS,CAAC,CAAC;YACf,IAAI,QAAgB,CAAA;YACpB,OAAO,CAAC,SAAe,EAAE,EAAE;gBAC1B,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,CAAA;gBACnC,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAA;gBAClE,QAAQ,GAAG,OAAO,CAAA;gBAClB,OAAO,MAAM,CAAA;YACd,CAAC,CAAA;SACD;KACD;AACF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,IAAI,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,GAAG,CAAA;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAY;IACzE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;AACrE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAY;IAClD,OAAO,IAAI,CAAA;AACZ,CAAC","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\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"]}
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../ts/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAKhD,MAAM,UAAU,wBAAwB,CAAC,MAAuB;IAC/D,QAAQ,MAAM,EAAE;QACf,KAAK,MAAM;YACV,OAAO,CAAC,UAAgB,EAAE,EAAE,CAAC,SAAS,CAAA;QACvC,KAAK,KAAK;YACT,OAAO,CAAC,SAAe,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,CAAA;QACpD,KAAK,SAAS,CAAC,CAAC;YACf,IAAI,QAAgB,CAAA;YACpB,OAAO,CAAC,SAAe,EAAE,EAAE;gBAC1B,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE,CAAA;gBACnC,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAA;gBAClE,QAAQ,GAAG,OAAO,CAAA;gBAClB,OAAO,MAAM,CAAA;YACd,CAAC,CAAA;SACD;KACD;AACF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC3C,OAAO,IAAI,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,GAAG,CAAA;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAY;IACzE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;AACrE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAY;IAClD,OAAO,IAAI,CAAA;AACZ,CAAC","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/esm/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,EACN,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAClF,YAAY,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,EACN,aAAa,EACb,QAAQ,EACR,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,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/esm/index.js CHANGED
@@ -1,7 +1,7 @@
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';
6
+ export { configGlobal, createStandardLog, getLogger, suppressLogs } from './standard_log.js';
7
7
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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,EACN,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,MAAM,kBAAkB,CAAA","sourcesContent":["export * from './console.js'\nexport * from './errors.js'\nexport * from './formatter.js'\nexport * from './logLevels.js'\nexport * from './memory.js'\nexport {\n\tconfigGlobal,\n\tcreateStandardLog,\n\tcreateStandardLogForTest,\n\tgetLogger,\n\tsuppressLogs\n} from './standardLog.js'\nexport type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'\nexport type {\n\tConsoleLike,\n\tLogEntry,\n\tLogFilter,\n\tLogFormatter,\n\tLogFunction,\n\tLogger,\n\tLoggerOptions,\n\tLogLevel,\n\tLogLevelEntry,\n\tLogMethod,\n\tLogMethodNames,\n\tLogReporter,\n\tLogReporterOptions,\n\tReporterFilter,\n\tStandardLogInstance,\n\tStandardLogOptions\n} from './types.js'\n"]}
1
+ {"version":3,"file":"index.js","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","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"}
@@ -111,4 +111,4 @@ export const DEFAULT_LOG_METHOD_NAMES = [
111
111
  'trace',
112
112
  'planck'
113
113
  ];
114
- //# sourceMappingURL=logLevels.js.map
114
+ //# sourceMappingURL=log_levels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_levels.js","sourceRoot":"","sources":["../ts/log_levels.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,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;;;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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"}
@@ -1,6 +1,6 @@
1
1
  import { mapKey, record, reduceByKey, reduceKey } from 'type-plus';
2
2
  import { createConsoleLogReporter } from './console.js';
3
- import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js';
3
+ import { logLevels, toLogLevel, toLogLevelName } from './log_levels.js';
4
4
  export function createLogStore(options) {
5
5
  return {
6
6
  loggers: record(),
@@ -37,4 +37,4 @@ export function logLevelStore(options) {
37
37
  }
38
38
  };
39
39
  }
40
- //# sourceMappingURL=logStore.js.map
40
+ //# sourceMappingURL=log_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_store.js","sourceRoot":"","sources":["../ts/log_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGvE,MAAM,UAAU,cAAc,CAC7B,OAAwC;IAExC,OAAO;QACN,OAAO,EAAE,MAAM,EAAE;QACjB,iBAAiB,EAAE,MAAM,EAAE;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC;KACrC,CAAA;AACF,CAAC;AAcD,MAAM,UAAU,aAAa,CAAC,OAA6B;IAC1D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,MAAM,EAAE,CAAA;IAErD,MAAM,KAAK,GAAG;QACb,YAAY;QACZ,mBAAmB,EAAE,WAAW,CAC/B,YAAY,EACZ,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACR,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,CAAC,KAAa;;YACpB,OAAO,MAAA,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,mCAAI,cAAc,CAAC,KAAK,CAAC,CAAA;QACjE,CAAC;QACD,QAAQ,CAAC,IAAY;;YACpB,OAAO,MAAA,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,UAAU,CAAC,IAAI,CAAC,CAAA;QACpD,CAAC;QACD,YAAY;YACX,OAAO,SAAS,CACf,SAAS,EACT,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBAChB,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK;oBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAEpF,OAAO,MAAM,CAAA;YACd,CAAC,EACD,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAC/E,CAAA;QACF,CAAC;KACD,CAAA;AACF,CAAC","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/esm/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,EAC7D,KAAK,EAAE,QAAQ,EACf,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CA4D5B"}
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/esm/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- import { logLevels } from './logLevels.js';
1
+ import { logLevels } from './log_levels.js';
2
2
  export function createLogger(store, id, options) {
3
3
  var _a;
4
4
  id = sanitizeId(id);
package/esm/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK1C,MAAM,UAAU,YAAY,CAC3B,KAAe,EACf,EAAU,EACV,OAAuB;;IAEvB,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,MAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAChD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GACxB,OAAO,OAAO,KAAK,QAAQ;QAC1B,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;QACzC,CAAC,CAAC,OAAO,YAAY,MAAM;YAC3B,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;YAC3C,CAAC,CAAC,OAAO,OAAO,KAAK,UAAU;gBAC/B,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;gBAC5B,CAAC,C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,EAAE,WAAiC;IAC3F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACjF,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\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"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAK3C,MAAM,UAAU,YAAY,CAC3B,KAAe,EACf,EAAU,EACV,OAAuB;;IAEvB,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,MAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAChD,MAAM,C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CAAC;AAED,SAAS,UAAU,CAAC,EAAU;IAC7B,OAAO,EAAE,CAAC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;AACrD,CAAC;AAED,SAAS,gBAAgB,CACxB,SAAwB,EACxB,QAAkB,EAClB,MAAuC;IAEvC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAA;AACrE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC3F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACjF,CAAC","sourcesContent":["import { logLevels } from './log_levels.js'\nimport { LogStore } from './log_store.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\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"]}
@@ -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"}
@@ -1,3 +1,3 @@
1
1
  import { record } from 'type-plus';
2
2
  export const ctx = record();
3
- //# sourceMappingURL=standardLog.ctx.js.map
3
+ //# sourceMappingURL=standard_log.ctx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.ctx.js","sourceRoot":"","sources":["../ts/standard_log.ctx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAM,EAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport type { LogStore } from './log_store.js'\nimport type { LogMethodNames, StandardLogInstance } from './types.js'\n\nexport const ctx: {\n\tconfigured?: boolean\n\tgsl?: { store: LogStore; standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\n"]}
@@ -1,6 +1,5 @@
1
- import { LogStore } from './logStore.js';
2
- import { MemoryLogReporter } from './memory.js';
3
- import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js';
1
+ import { type LogStore } from './log_store.js';
2
+ import type { LogMethodNames, Logger, LoggerOptions, StandardLogInstance, StandardLogOptions } from './types.js';
4
3
  export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
5
4
  }
6
5
  export declare function createStandardLog<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): StandardLog<N>;
@@ -8,10 +7,6 @@ export declare function createStandardLogClosure<N extends string = LogMethodNam
8
7
  store: LogStore;
9
8
  standardLog: StandardLog<N>;
10
9
  };
11
- export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
12
- reporter: MemoryLogReporter;
13
- };
14
- export declare function createStandardLogForTest<N extends string = LogMethodNames>(logLevel?: LogLevel): StandardLogForTest<N>;
15
10
  /**
16
11
  * Suppress logging within the code block.
17
12
  */
@@ -19,4 +14,4 @@ export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Lo
19
14
  export type GetLogger<N extends string = LogMethodNames> = (id: string, options?: LoggerOptions) => Logger<LogMethodNames | N>;
20
15
  export declare function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions): Logger<LogMethodNames | N>;
21
16
  export declare function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>): void;
22
- //# sourceMappingURL=standardLog.d.ts.map
17
+ //# sourceMappingURL=standard_log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.d.ts","sourceRoot":"","sources":["../ts/standard_log.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAG9D,OAAO,KAAK,EACX,cAAc,EACd,MAAM,EACN,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,CAAE,SAAQ,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CAAG;AAE3G,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAClE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,WAAW,CAAC,CAAC,CAAC,CAWhB;AAID,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACzE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CAgDlD;AASD;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;AASlF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,CAC1D,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,aAAa,KACnB,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,CAAA;AAE/B,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,8BAE/F;AAQD,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,QAqB7E"}
@@ -1,9 +1,8 @@
1
1
  import { record, required } from 'type-plus';
2
+ import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './log_levels.js';
3
+ import { createLogStore } from './log_store.js';
2
4
  import { createLogger } from './logger.js';
3
- import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js';
4
- import { createLogStore } from './logStore.js';
5
- import { createMemoryLogReporter } from './memory.js';
6
- import { ctx } from './standardLog.ctx.js';
5
+ import { ctx } from './standard_log.ctx.js';
7
6
  export function createStandardLog(options) {
8
7
  var _a;
9
8
  const closure = createStandardLogClosure(options);
@@ -71,11 +70,6 @@ function createDummyLogger(logMethods) {
71
70
  return p;
72
71
  }, record());
73
72
  }
74
- export function createStandardLogForTest(logLevel = logLevels.debug) {
75
- const reporter = createMemoryLogReporter();
76
- const closure = createStandardLogClosure({ reporters: [reporter], logLevel });
77
- return { ...closure.standardLog, reporter };
78
- }
79
73
  export function suppressLogs(block, ...logs) {
80
74
  const origLevels = logs.map(l => l.level);
81
75
  logs.forEach(l => (l.level = logLevels.none));
@@ -111,4 +105,4 @@ export function configGlobal(options) {
111
105
  }
112
106
  ctx.configured = true;
113
107
  }
114
- //# sourceMappingURL=standardLog.js.map
108
+ //# sourceMappingURL=standard_log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.js","sourceRoot":"","sources":["../ts/standard_log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAW3C,MAAM,UAAU,iBAAiB,CAChC,OAA+B;;IAE/B,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QACzC,MAAM,GAAG,GAAG,OAAO,C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GAAG,EAAE;QACZ,IAAI,OAAO,CAAC,QAAQ,EAAE;YACrB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SACzC;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACtB,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAA;YACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;YACpB,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;SACpC;KACD;SAAM;QACN,GAAG,CAAC,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;KAC3C;IACD,GAAG,CAAC,UAAU,GAAG,IAAI,CAAA;AACtB,CAAC","sourcesContent":["import { record, required } from 'type-plus'\nimport { DEFAULT_LOG_METHOD_NAMES, logLevels } from './log_levels.js'\nimport { createLogStore, type LogStore } from './log_store.js'\nimport { createLogger } from './logger.js'\nimport { ctx } from './standard_log.ctx.js'\nimport type {\n\tLogMethodNames,\n\tLogger,\n\tLoggerOptions,\n\tStandardLogInstance,\n\tStandardLogOptions\n} from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n\toptions?: StandardLogOptions<N>\n): StandardLog<N> {\n\tconst closure = createStandardLogClosure(options)\n\tif (options?.reporters?.some(r => !r.id)) {\n\t\tconst log = closure.standardLog.getLogger('standard-log')\n\t\tlog.critical(\n\t\t\t`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`\n\t\t)\n\t}\n\n\tif (!ctx.gsl) ctx.gsl = closure as any\n\treturn closure.standardLog\n}\n\nfunction noop() {}\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n\toptions?: StandardLogOptions<N>\n): { store: LogStore; standardLog: StandardLog<N> } {\n\t// TODO reporter.id must not be empty\n\tconst store = createLogStore(required({ logLevel: logLevels.info }, options))\n\tconst nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []\n\tconst logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([\n\t\t'on',\n\t\t'count',\n\t\t'write'\n\t])\n\treturn {\n\t\tstore,\n\t\tstandardLog: {\n\t\t\tget logLevel() {\n\t\t\t\treturn store.logLevel\n\t\t\t},\n\n\t\t\ttoLogLevelName(level: number) {\n\t\t\t\treturn store.logLevelStore.getName(level)\n\t\t\t},\n\t\t\ttoLogLevel(name: string) {\n\t\t\t\treturn store.logLevelStore.getLevel(name)\n\t\t\t},\n\t\t\tgetLogger(id: string, options?: LoggerOptions) {\n\t\t\t\tif (store.loggers[id]) return store.loggers[id] as any\n\t\t\t\treturn (store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any)\n\t\t\t},\n\t\t\tgetNonConsoleLogger(id, options?) {\n\t\t\t\tif (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any\n\n\t\t\t\tif (store.loggers[id]) {\n\t\t\t\t\tconst log = this.getLogger('standard-log')\n\t\t\t\t\tlog.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)\n\t\t\t\t\treturn (store.nonConsoleLoggers[id] = createDummyLogger(logMethods))\n\t\t\t\t}\n\n\t\t\t\treturn (store.nonConsoleLoggers[id] =\n\t\t\t\t\tnonConsoleReporters.length === 0\n\t\t\t\t\t\t? createDummyLogger(logMethods)\n\t\t\t\t\t\t: createLogger(store, id, {\n\t\t\t\t\t\t\t\tssf: this.getNonConsoleLogger,\n\t\t\t\t\t\t\t\t...options,\n\t\t\t\t\t\t\t\twriteTo(reporterId) {\n\t\t\t\t\t\t\t\t\treturn nonConsoleReporters.indexOf(reporterId) >= 0\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t }))\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction createDummyLogger(logMethods: string[]) {\n\treturn logMethods.reduce((p, m) => {\n\t\tp[m] = noop\n\t\treturn p\n\t}, record()) as Logger\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n\tconst origLevels = logs.map(l => l.level)\n\tlogs.forEach(l => (l.level = logLevels.none))\n\tconst result = block()\n\tlogs.forEach((l, i) => (l.level = origLevels[i]))\n\treturn result\n}\n\nexport type GetLogger<N extends string = LogMethodNames> = (\n\tid: string,\n\toptions?: LoggerOptions\n) => Logger<LogMethodNames | N>\n\nexport function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n\treturn getGlobalSL<N>().getLogger(id, options)\n}\n\nfunction getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {\n\tif (!ctx.gsl) ctx.gsl = createStandardLogClosure()\n\n\treturn ctx.gsl!.standardLog as StandardLogInstance<N>\n}\n\nexport function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {\n\tif (ctx.configured) {\n\t\tconst log = ctx.gsl!.standardLog.getLogger('standard-log')\n\t\tlog.warn(\n\t\t\t'configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.'\n\t\t)\n\t}\n\n\tif (ctx.gsl) {\n\t\tif (options.logLevel) {\n\t\t\tctx.gsl.store.logLevel = options.logLevel\n\t\t}\n\t\tif (options.reporters) {\n\t\t\tconst reporters = ctx.gsl.store.reporters\n\t\t\treporters.length = 0\n\t\t\treporters.push(...options.reporters)\n\t\t}\n\t} else {\n\t\tctx.gsl = createStandardLogClosure(options)\n\t}\n\tctx.configured = true\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { type MemoryLogReporter } from './memory.js';
2
+ import { type StandardLog } from './standard_log.js';
3
+ import type { LogMethodNames, StandardLogOptions } from './types.js';
4
+ export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
5
+ reporter: MemoryLogReporter;
6
+ };
7
+ export declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): StandardLogForTest<N>;
8
+ //# sourceMappingURL=standard_log.mocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.mocks.d.ts","sourceRoot":"","sources":["../ts/standard_log.mocks.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IACpF,QAAQ,EAAE,iBAAiB,CAAA;CAC3B,CAAA;AAED,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACzE,OAAO,GAAE,kBAAkB,CAAC,CAAC,CAAM,GACjC,kBAAkB,CAAC,CAAC,CAAC,CAUvB"}
@@ -0,0 +1,16 @@
1
+ import { logLevels } from './log_levels.js';
2
+ import { createMemoryLogReporter } from './memory.js';
3
+ import { createStandardLogClosure } from './standard_log.js';
4
+ export function createStandardLogForTest(options = {}) {
5
+ var _a, _b;
6
+ options.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : logLevels.debug;
7
+ options.reporters = (_b = options.reporters) !== null && _b !== void 0 ? _b : [];
8
+ const existingReporter = options.reporters.find(r => r.id === 'memory');
9
+ const reporter = existingReporter !== null && existingReporter !== void 0 ? existingReporter : createMemoryLogReporter();
10
+ if (!existingReporter) {
11
+ options.reporters.push(reporter);
12
+ }
13
+ const closure = createStandardLogClosure(options);
14
+ return { ...closure.standardLog, reporter };
15
+ }
16
+ //# sourceMappingURL=standard_log.mocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.mocks.js","sourceRoot":"","sources":["../ts/standard_log.mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,uBAAuB,EAA0B,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,wBAAwB,EAAoB,MAAM,mBAAmB,CAAA;AAO9E,MAAM,UAAU,wBAAwB,CACvC,UAAiC,EAAE;;IAEnC,OAAO,CAAC,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,SAAS,CAAC,KAAK,CAAA;IACtD,OAAO,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAA;IAC3C,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAsB,CAAA;IAC5F,MAAM,QAAQ,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,uBAAuB,EAAE,CAAA;IAC9D,IAAI,CAAC,gBAAgB,EAAE;QACtB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAChC;IACD,MAAM,OAAO,GAAG,wBAAwB,CAAI,OAAO,CAAC,CAAA;IACpD,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAA;AAC5C,CAAC","sourcesContent":["import { logLevels } from './log_levels.js'\nimport { createMemoryLogReporter, type MemoryLogReporter } from './memory.js'\nimport { createStandardLogClosure, type StandardLog } from './standard_log.js'\nimport type { LogMethodNames, StandardLogOptions } from './types.js'\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {\n\treporter: MemoryLogReporter\n}\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n\toptions: StandardLogOptions<N> = {}\n): StandardLogForTest<N> {\n\toptions.logLevel = options.logLevel ?? logLevels.debug\n\toptions.reporters = options.reporters ?? []\n\tconst existingReporter = options.reporters.find(r => r.id === 'memory') as MemoryLogReporter\n\tconst reporter = existingReporter ?? createMemoryLogReporter()\n\tif (!existingReporter) {\n\t\toptions.reporters.push(reporter)\n\t}\n\tconst closure = createStandardLogClosure<N>(options)\n\treturn { ...closure.standardLog, reporter }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { createStandardLogForTest } from '../standard_log.mocks.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAA2B,MAAM,0BAA0B,CAAA","sourcesContent":["export { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standard-log",
3
- "version": "11.5.2",
3
+ "version": "12.0.1",
4
4
  "description": "The standard log library",
5
5
  "homepage": "https://github.com/unional/standard-log/tree/main/packages/log",
6
6
  "bugs": {
@@ -40,15 +40,16 @@
40
40
  "cjs",
41
41
  "dist",
42
42
  "esm",
43
+ "testing",
43
44
  "ts",
44
- "!**/*.spec.*",
45
- "!**/testUtil.*"
45
+ "!**/*.{spec,test,unit,accept,integrate,system}.*",
46
+ "!**/test_utils.*"
46
47
  ],
47
48
  "dependencies": {
48
49
  "@just-func/types": "^0.5.0",
49
50
  "iso-error": "^6.0.0",
50
51
  "ms": "^2.1.3",
51
- "type-plus": "^6.0.0",
52
+ "type-plus": "^6.5.0",
52
53
  "upper-case": "^2.0.2"
53
54
  },
54
55
  "devDependencies": {
@@ -73,8 +74,8 @@
73
74
  "npm-run-all": "^4.1.5",
74
75
  "param-case": "^3.0.4",
75
76
  "pascal-case": "^3.1.2",
76
- "ramda": "^0.28.0",
77
- "rimraf": "^3.0.2",
77
+ "ramda": "^0.29.0",
78
+ "rimraf": "^5.0.0",
78
79
  "size-limit": "^8.1.0",
79
80
  "ts-jest": "^29.0.3",
80
81
  "ts-loader": "^9.4.1",
@@ -107,7 +108,7 @@
107
108
  "bundle": "run-p bundle:es5 bundle:esm",
108
109
  "bundle:es5": "webpack -c ./webpack.es5.cjs",
109
110
  "bundle:esm": "webpack -c ./webpack.esm.cjs",
110
- "clean": "rimraf cjs coverage dist esm lib libm tslib *.tsbuildinfo",
111
+ "clean": "rimraf cjs coverage dist esm lib libm tslib --glob *.tsbuildinfo",
111
112
  "coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
112
113
  "depcheck": "depcheck",
113
114
  "lint": "cross-env TIMING=1 eslint --ext=ts,js,cjs,mjs .",
@@ -0,0 +1 @@
1
+ export * from '../cjs/testing'
@@ -0,0 +1 @@
1
+ module.exports = require('../cjs/testing')
package/ts/console.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { unpartial } from 'type-plus'
2
2
  import { consoleFormatter } from './formatter.js'
3
- import { logLevels } from './logLevels.js'
3
+ import { logLevels } from './log_levels.js'
4
4
  import { polyfill } from './platform.js'
5
5
  import type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
6
6
 
package/ts/formatter.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ms from 'ms'
2
2
  import { upperCase } from 'upper-case'
3
- import { toLogLevelName } from './logLevels.js'
3
+ import { toLogLevelName } from './log_levels.js'
4
4
  import type { LogEntry } from './types.js'
5
5
 
6
6
  export type TimestampFormat = 'none' | 'iso' | 'elapsed'
package/ts/index.ts CHANGED
@@ -1,30 +1,24 @@
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 {
7
- configGlobal,
8
- createStandardLog,
9
- createStandardLogForTest,
10
- getLogger,
11
- suppressLogs
12
- } from './standardLog.js'
13
- export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'
6
+ export { configGlobal, createStandardLog, getLogger, suppressLogs } from './standard_log.js'
7
+ export type { GetLogger, StandardLog } from './standard_log.js'
14
8
  export type {
15
9
  ConsoleLike,
16
10
  LogEntry,
17
11
  LogFilter,
18
12
  LogFormatter,
19
13
  LogFunction,
20
- Logger,
21
- LoggerOptions,
22
14
  LogLevel,
23
15
  LogLevelEntry,
24
16
  LogMethod,
25
17
  LogMethodNames,
26
18
  LogReporter,
27
19
  LogReporterOptions,
20
+ Logger,
21
+ LoggerOptions,
28
22
  ReporterFilter,
29
23
  StandardLogInstance,
30
24
  StandardLogOptions
@@ -1,6 +1,6 @@
1
1
  import { mapKey, record, reduceByKey, reduceKey } from 'type-plus'
2
2
  import { createConsoleLogReporter } from './console.js'
3
- import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'
3
+ import { logLevels, toLogLevel, toLogLevelName } from './log_levels.js'
4
4
  import type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'
5
5
 
6
6
  export function createLogStore<N extends string = LogMethodNames>(
package/ts/logger.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { logLevels } from './logLevels.js'
2
- import { LogStore } from './logStore.js'
1
+ import { logLevels } from './log_levels.js'
2
+ import { LogStore } from './log_store.js'
3
3
  import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'
4
4
  import { LogLevel } from './types.js'
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { record } from 'type-plus'
2
- import type { LogStore } from './logStore.js'
2
+ import type { LogStore } from './log_store.js'
3
3
  import type { LogMethodNames, StandardLogInstance } from './types.js'
4
4
 
5
5
  export const ctx: {
@@ -0,0 +1,22 @@
1
+ import { logLevels } from './log_levels.js'
2
+ import { createMemoryLogReporter, type MemoryLogReporter } from './memory.js'
3
+ import { createStandardLogClosure, type StandardLog } from './standard_log.js'
4
+ import type { LogMethodNames, StandardLogOptions } from './types.js'
5
+
6
+ export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
7
+ reporter: MemoryLogReporter
8
+ }
9
+
10
+ export function createStandardLogForTest<N extends string = LogMethodNames>(
11
+ options: StandardLogOptions<N> = {}
12
+ ): StandardLogForTest<N> {
13
+ options.logLevel = options.logLevel ?? logLevels.debug
14
+ options.reporters = options.reporters ?? []
15
+ const existingReporter = options.reporters.find(r => r.id === 'memory') as MemoryLogReporter
16
+ const reporter = existingReporter ?? createMemoryLogReporter()
17
+ if (!existingReporter) {
18
+ options.reporters.push(reporter)
19
+ }
20
+ const closure = createStandardLogClosure<N>(options)
21
+ return { ...closure.standardLog, reporter }
22
+ }
@@ -1,14 +1,12 @@
1
1
  import { record, required } from 'type-plus'
2
+ import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './log_levels.js'
3
+ import { createLogStore, type LogStore } from './log_store.js'
2
4
  import { createLogger } from './logger.js'
3
- import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'
4
- import { createLogStore, LogStore } from './logStore.js'
5
- import { createMemoryLogReporter, MemoryLogReporter } from './memory.js'
6
- import { ctx } from './standardLog.ctx.js'
5
+ import { ctx } from './standard_log.ctx.js'
7
6
  import type {
7
+ LogMethodNames,
8
8
  Logger,
9
9
  LoggerOptions,
10
- LogLevel,
11
- LogMethodNames,
12
10
  StandardLogInstance,
13
11
  StandardLogOptions
14
12
  } from './types.js'
@@ -91,18 +89,6 @@ function createDummyLogger(logMethods: string[]) {
91
89
  }, record()) as Logger
92
90
  }
93
91
 
94
- export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
95
- reporter: MemoryLogReporter
96
- }
97
-
98
- export function createStandardLogForTest<N extends string = LogMethodNames>(
99
- logLevel: LogLevel = logLevels.debug
100
- ): StandardLogForTest<N> {
101
- const reporter = createMemoryLogReporter()
102
- const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })
103
- return { ...closure.standardLog, reporter }
104
- }
105
-
106
92
  /**
107
93
  * Suppress logging within the code block.
108
94
  */
@@ -0,0 +1 @@
1
+ export { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js'
@@ -1 +0,0 @@
1
- {"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../ts/logLevels.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"}