standard-log 12.1.2 → 13.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 (144) hide show
  1. package/README.md +8 -8
  2. package/cjs/_virtual/_rolldown/runtime.js +23 -0
  3. package/cjs/console.d.ts +10 -7
  4. package/cjs/console.d.ts.map +1 -1
  5. package/cjs/console.js +53 -71
  6. package/cjs/console.js.map +1 -1
  7. package/cjs/errors.d.ts +9 -6
  8. package/cjs/errors.d.ts.map +1 -1
  9. package/cjs/errors.js +22 -45
  10. package/cjs/errors.js.map +1 -1
  11. package/cjs/formatter.d.ts +9 -6
  12. package/cjs/formatter.d.ts.map +1 -1
  13. package/cjs/formatter.js +41 -50
  14. package/cjs/formatter.js.map +1 -1
  15. package/cjs/index.d.ts +8 -9
  16. package/cjs/index.js +26 -28
  17. package/cjs/log_levels.d.ts +76 -73
  18. package/cjs/log_levels.d.ts.map +1 -1
  19. package/cjs/log_levels.js +104 -110
  20. package/cjs/log_levels.js.map +1 -1
  21. package/cjs/log_store.d.ts +20 -17
  22. package/cjs/log_store.d.ts.map +1 -1
  23. package/cjs/log_store.js +43 -39
  24. package/cjs/log_store.js.map +1 -1
  25. package/cjs/logger.d.ts +6 -3
  26. package/cjs/logger.d.ts.map +1 -1
  27. package/cjs/logger.js +66 -88
  28. package/cjs/logger.js.map +1 -1
  29. package/cjs/memory.d.ts +20 -17
  30. package/cjs/memory.d.ts.map +1 -1
  31. package/cjs/memory.js +54 -64
  32. package/cjs/memory.js.map +1 -1
  33. package/cjs/platform.browser.d.ts +7 -4
  34. package/cjs/platform.browser.d.ts.map +1 -1
  35. package/cjs/platform.browser.js +8 -6
  36. package/cjs/platform.browser.js.map +1 -1
  37. package/cjs/platform.d.ts +7 -4
  38. package/cjs/platform.d.ts.map +1 -1
  39. package/cjs/platform.js +9 -7
  40. package/cjs/platform.js.map +1 -1
  41. package/cjs/standard_log.ctx.d.ts +11 -8
  42. package/cjs/standard_log.ctx.d.ts.map +1 -1
  43. package/cjs/standard_log.ctx.js +6 -5
  44. package/cjs/standard_log.ctx.js.map +1 -1
  45. package/cjs/standard_log.d.ts +14 -12
  46. package/cjs/standard_log.d.ts.map +1 -1
  47. package/cjs/standard_log.js +83 -112
  48. package/cjs/standard_log.js.map +1 -1
  49. package/cjs/standard_log.testing.d.ts +16 -13
  50. package/cjs/standard_log.testing.d.ts.map +1 -1
  51. package/cjs/standard_log.testing.js +19 -35
  52. package/cjs/standard_log.testing.js.map +1 -1
  53. package/cjs/testing/index.d.ts +3 -3
  54. package/cjs/testing/index.js +3 -6
  55. package/cjs/types.d.ts +125 -124
  56. package/cjs/types.d.ts.map +1 -1
  57. package/cjs/types.js +0 -3
  58. package/dist/standard-log.esm.js +873 -1430
  59. package/dist/standard-log.esm.js.map +1 -1
  60. package/dist/standard-log.iife.js +952 -0
  61. package/dist/standard-log.iife.js.map +1 -0
  62. package/esm/console.d.ts +10 -7
  63. package/esm/console.d.ts.map +1 -1
  64. package/esm/console.js +54 -64
  65. package/esm/console.js.map +1 -1
  66. package/esm/errors.d.ts +9 -6
  67. package/esm/errors.d.ts.map +1 -1
  68. package/esm/errors.js +21 -21
  69. package/esm/errors.js.map +1 -1
  70. package/esm/formatter.d.ts +9 -6
  71. package/esm/formatter.d.ts.map +1 -1
  72. package/esm/formatter.js +38 -32
  73. package/esm/formatter.js.map +1 -1
  74. package/esm/index.d.ts +8 -9
  75. package/esm/index.js +7 -7
  76. package/esm/log_levels.d.ts +76 -73
  77. package/esm/log_levels.d.ts.map +1 -1
  78. package/esm/log_levels.js +102 -107
  79. package/esm/log_levels.js.map +1 -1
  80. package/esm/log_store.d.ts +20 -17
  81. package/esm/log_store.d.ts.map +1 -1
  82. package/esm/log_store.js +44 -37
  83. package/esm/log_store.js.map +1 -1
  84. package/esm/logger.d.ts +6 -3
  85. package/esm/logger.d.ts.map +1 -1
  86. package/esm/logger.js +66 -65
  87. package/esm/logger.js.map +1 -1
  88. package/esm/memory.d.ts +20 -17
  89. package/esm/memory.d.ts.map +1 -1
  90. package/esm/memory.js +55 -62
  91. package/esm/memory.js.map +1 -1
  92. package/esm/platform.browser.d.ts +7 -4
  93. package/esm/platform.browser.d.ts.map +1 -1
  94. package/esm/platform.browser.js +7 -3
  95. package/esm/platform.browser.js.map +1 -1
  96. package/esm/platform.d.ts +7 -4
  97. package/esm/platform.d.ts.map +1 -1
  98. package/esm/platform.js +8 -4
  99. package/esm/platform.js.map +1 -1
  100. package/esm/standard_log.ctx.d.ts +11 -8
  101. package/esm/standard_log.ctx.d.ts.map +1 -1
  102. package/esm/standard_log.ctx.js +6 -2
  103. package/esm/standard_log.ctx.js.map +1 -1
  104. package/esm/standard_log.d.ts +14 -12
  105. package/esm/standard_log.d.ts.map +1 -1
  106. package/esm/standard_log.js +83 -98
  107. package/esm/standard_log.js.map +1 -1
  108. package/esm/standard_log.testing.d.ts +16 -13
  109. package/esm/standard_log.testing.d.ts.map +1 -1
  110. package/esm/standard_log.testing.js +19 -20
  111. package/esm/standard_log.testing.js.map +1 -1
  112. package/esm/testing/index.d.ts +3 -3
  113. package/esm/testing/index.js +2 -2
  114. package/esm/types.d.ts +125 -124
  115. package/esm/types.d.ts.map +1 -1
  116. package/esm/types.js +0 -1
  117. package/package.json +21 -67
  118. package/ts/console.ts +7 -8
  119. package/ts/errors.ts +5 -2
  120. package/ts/formatter.ts +1 -2
  121. package/ts/index.ts +3 -3
  122. package/ts/log_levels.ts +2 -2
  123. package/ts/logger.ts +14 -7
  124. package/ts/memory.ts +3 -5
  125. package/ts/platform.ts +1 -1
  126. package/ts/standard_log.ts +2 -2
  127. package/ts/testing/index.ts +3 -3
  128. package/ts/types.ts +1 -1
  129. package/cjs/index.d.ts.map +0 -1
  130. package/cjs/index.js.map +0 -1
  131. package/cjs/testing/index.d.ts.map +0 -1
  132. package/cjs/testing/index.js.map +0 -1
  133. package/cjs/types.js.map +0 -1
  134. package/dist/standard-log.es5.js +0 -10184
  135. package/dist/standard-log.es5.js.gz +0 -0
  136. package/dist/standard-log.es5.js.map +0 -1
  137. package/dist/standard-log.es5.js.map.gz +0 -0
  138. package/dist/standard-log.esm.js.gz +0 -0
  139. package/dist/standard-log.esm.js.map.gz +0 -0
  140. package/esm/index.d.ts.map +0 -1
  141. package/esm/index.js.map +0 -1
  142. package/esm/testing/index.d.ts.map +0 -1
  143. package/esm/testing/index.js.map +0 -1
  144. package/esm/types.js.map +0 -1
@@ -1,108 +1,93 @@
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';
4
- import { createLogger } from './logger.js';
5
- import { ctx } from './standard_log.ctx.js';
6
- export function createStandardLog(options) {
7
- var _a;
8
- const closure = createStandardLogClosure(options);
9
- if ((_a = options === null || options === void 0 ? void 0 : options.reporters) === null || _a === void 0 ? void 0 : _a.some(r => !r.id)) {
10
- const log = closure.standardLog.getLogger('standard-log');
11
- log.critical(`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.`);
12
- }
13
- if (!ctx.gsl)
14
- ctx.gsl = closure;
15
- return closure.standardLog;
1
+ import { DEFAULT_LOG_METHOD_NAMES, logLevels } from "./log_levels.js";
2
+ import { createLogStore } from "./log_store.js";
3
+ import { createLogger } from "./logger.js";
4
+ import { ctx } from "./standard_log.ctx.js";
5
+ import { record, required } from "type-plus";
6
+ //#region ts/standard_log.ts
7
+ function createStandardLog(options) {
8
+ const closure = createStandardLogClosure(options);
9
+ if (options?.reporters?.some((r) => !r.id)) closure.standardLog.getLogger("standard-log").critical(`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.`);
10
+ if (!ctx.gsl) ctx.gsl = closure;
11
+ return closure.standardLog;
16
12
  }
17
- function noop() { }
18
- export function createStandardLogClosure(options) {
19
- var _a, _b, _c;
20
- // TODO reporter.id must not be empty
21
- const store = createLogStore(required({ logLevel: logLevels.info }, options));
22
- const nonConsoleReporters = (_b = (_a = options === null || options === void 0 ? void 0 : options.reporters) === null || _a === void 0 ? void 0 : _a.filter(r => !r.isConsoleReporter).map(r => r.id)) !== null && _b !== void 0 ? _b : [];
23
- const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys((_c = options === null || options === void 0 ? void 0 : options.customLevels) !== null && _c !== void 0 ? _c : {})).concat([
24
- 'on',
25
- 'count',
26
- 'write'
27
- ]);
28
- return {
29
- store,
30
- standardLog: {
31
- get logLevel() {
32
- return store.logLevel;
33
- },
34
- toLogLevelName(level) {
35
- return store.logLevelStore.getName(level);
36
- },
37
- toLogLevel(name) {
38
- return store.logLevelStore.getLevel(name);
39
- },
40
- getLogger(id, options) {
41
- if (store.loggers[id])
42
- return store.loggers[id];
43
- return (store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }));
44
- },
45
- getNonConsoleLogger(id, options) {
46
- if (store.nonConsoleLoggers[id])
47
- return store.nonConsoleLoggers[id];
48
- if (store.loggers[id]) {
49
- const log = this.getLogger('standard-log');
50
- log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`);
51
- return (store.nonConsoleLoggers[id] = createDummyLogger(logMethods));
52
- }
53
- return (store.nonConsoleLoggers[id] =
54
- nonConsoleReporters.length === 0
55
- ? createDummyLogger(logMethods)
56
- : createLogger(store, id, {
57
- ssf: this.getNonConsoleLogger,
58
- ...options,
59
- writeTo(reporterId) {
60
- return nonConsoleReporters.indexOf(reporterId) >= 0;
61
- }
62
- }));
63
- }
64
- }
65
- };
13
+ function noop() {}
14
+ function createStandardLogClosure(options) {
15
+ const store = createLogStore(required({ logLevel: logLevels.info }, options));
16
+ const nonConsoleReporters = options?.reporters?.filter((r) => !r.isConsoleReporter).map((r) => r.id) ?? [];
17
+ const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([
18
+ "on",
19
+ "count",
20
+ "write"
21
+ ]);
22
+ return {
23
+ store,
24
+ standardLog: {
25
+ get logLevel() {
26
+ return store.logLevel;
27
+ },
28
+ toLogLevelName(level) {
29
+ return store.logLevelStore.getName(level);
30
+ },
31
+ toLogLevel(name) {
32
+ return store.logLevelStore.getLevel(name);
33
+ },
34
+ getLogger(id, options) {
35
+ if (store.loggers[id]) return store.loggers[id];
36
+ return store.loggers[id] = createLogger(store, id, {
37
+ ssf: this.getLogger,
38
+ ...options
39
+ });
40
+ },
41
+ getNonConsoleLogger(id, options) {
42
+ if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id];
43
+ if (store.loggers[id]) {
44
+ this.getLogger("standard-log").warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`);
45
+ return store.nonConsoleLoggers[id] = createDummyLogger(logMethods);
46
+ }
47
+ return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0 ? createDummyLogger(logMethods) : createLogger(store, id, {
48
+ ssf: this.getNonConsoleLogger,
49
+ ...options,
50
+ writeTo(reporterId) {
51
+ return nonConsoleReporters.indexOf(reporterId) >= 0;
52
+ }
53
+ });
54
+ }
55
+ }
56
+ };
66
57
  }
67
58
  function createDummyLogger(logMethods) {
68
- return logMethods.reduce((p, m) => {
69
- p[m] = noop;
70
- return p;
71
- }, record());
59
+ return logMethods.reduce((p, m) => {
60
+ p[m] = noop;
61
+ return p;
62
+ }, record());
72
63
  }
73
- export function suppressLogs(block, ...logs) {
74
- const origLevels = logs.map(l => l.level);
75
- logs.forEach(l => (l.level = logLevels.none));
76
- const result = block();
77
- logs.forEach((l, i) => (l.level = origLevels[i]));
78
- return result;
64
+ function suppressLogs(block, ...logs) {
65
+ const origLevels = logs.map((l) => l.level);
66
+ logs.forEach((l) => l.level = logLevels.none);
67
+ const result = block();
68
+ logs.forEach((l, i) => l.level = origLevels[i]);
69
+ return result;
79
70
  }
80
- export function getLogger(id, options) {
81
- return getGlobalSL().getLogger(id, options);
71
+ function getLogger(id, options) {
72
+ return getGlobalSL().getLogger(id, options);
82
73
  }
83
74
  function getGlobalSL() {
84
- if (!ctx.gsl)
85
- ctx.gsl = createStandardLogClosure();
86
- return ctx.gsl.standardLog;
75
+ if (!ctx.gsl) ctx.gsl = createStandardLogClosure();
76
+ return ctx.gsl.standardLog;
87
77
  }
88
- export function configGlobal(options) {
89
- if (ctx.configured) {
90
- const log = ctx.gsl.standardLog.getLogger('standard-log');
91
- log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
92
- }
93
- if (ctx.gsl) {
94
- if (options.logLevel) {
95
- ctx.gsl.store.logLevel = options.logLevel;
96
- }
97
- if (options.reporters) {
98
- const reporters = ctx.gsl.store.reporters;
99
- reporters.length = 0;
100
- reporters.push(...options.reporters);
101
- }
102
- }
103
- else {
104
- ctx.gsl = createStandardLogClosure(options);
105
- }
106
- ctx.configured = true;
78
+ function configGlobal(options) {
79
+ if (ctx.configured) ctx.gsl.standardLog.getLogger("standard-log").warn("configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.");
80
+ if (ctx.gsl) {
81
+ if (options.logLevel) ctx.gsl.store.logLevel = options.logLevel;
82
+ if (options.reporters) {
83
+ const reporters = ctx.gsl.store.reporters;
84
+ reporters.length = 0;
85
+ reporters.push(...options.reporters);
86
+ }
87
+ } else ctx.gsl = createStandardLogClosure(options);
88
+ ctx.configured = true;
107
89
  }
90
+ //#endregion
91
+ export { configGlobal, createStandardLog, createStandardLogClosure, getLogger, suppressLogs };
92
+
108
93
  //# sourceMappingURL=standard_log.js.map
@@ -1 +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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AAC,GAAG,GAAG,wBAAwB,EAAE,CAAA;IAElD,OAAO,GAAG,CAAC,GAAI,CAAC,WAAqC,CAAA;AACtD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAiD;IAC7E,IAAI,GAAG,CAAC,UAAU,EAAE;QACnB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAI,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QAC1D,GAAG,CAAC,IAAI,CACP,kJAAkJ,CAClJ,CAAA;KACD;IAED,IAAI,GAAG,CAAC,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"]}
1
+ {"version":3,"file":"standard_log.js","names":[],"sources":["../ts/standard_log.ts"],"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\tLogger,\n\tLoggerOptions,\n\tLogMethodNames,\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\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"],"mappings":";;;;;;AAeA,SAAgB,kBACf,SACiB;CACjB,MAAM,UAAU,yBAAyB,OAAO;CAChD,IAAI,SAAS,WAAW,MAAK,MAAK,CAAC,EAAE,EAAE,GAEtC,QADoB,YAAY,UAAU,cACxC,CAAC,CAAC,SACH,+JACD;CAGD,IAAI,CAAC,IAAI,KAAK,IAAI,MAAM;CACxB,OAAO,QAAQ;AAChB;AAEA,SAAS,OAAO,CAAC;AAEjB,SAAgB,yBACf,SACmD;CAEnD,MAAM,QAAQ,eAAe,SAAS,EAAE,UAAU,UAAU,KAAK,GAAG,OAAO,CAAC;CAC5E,MAAM,sBAAsB,SAAS,WAAW,QAAO,MAAK,CAAC,EAAE,i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QAAQ,UAAU,IAAK;CAC5C,MAAM,SAAS,MAAM;CACrB,KAAK,SAAS,GAAG,MAAO,EAAE,QAAQ,WAAW,EAAG;CAChD,OAAO;AACR;AAOA,SAAgB,UAA6C,IAAY,SAAyB;CACjG,OAAO,YAAe,CAAC,CAAC,UAAU,IAAI,OAAO;AAC9C;AAEA,SAAS,cAAyE;CACjF,IAAI,CAAC,IAAI,KAAK,IAAI,MAAM,yBAAyB;CAEjD,OAAO,IAAI,IAAK;AACjB;AAEA,SAAgB,aAAa,SAAmD;CAC/E,IAAI,IAAI,YAEP,IADgB,IAAK,YAAY,UAAU,cACzC,CAAC,CAAC,KACH,kJACD;CAGD,IAAI,IAAI,KAAK;EACZ,IAAI,QAAQ,UACX,IAAI,IAAI,MAAM,WAAW,QAAQ;EAElC,IAAI,QAAQ,WAAW;GACtB,MAAM,YAAY,IAAI,IAAI,MAAM;GAChC,UAAU,SAAS;GACnB,UAAU,KAAK,GAAG,QAAQ,SAAS;EACpC;CACD,OACC,IAAI,MAAM,yBAAyB,OAAO;CAE3C,IAAI,aAAa;AAClB"}
@@ -1,16 +1,19 @@
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 StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {
5
- /**
6
- * Send the logs to console for easy debugging.
7
- *
8
- * @default false
9
- */
10
- emitLog?: boolean;
1
+ import { LogMethodNames, StandardLogOptions } from "./types.js";
2
+ import { MemoryLogReporter } from "./memory.js";
3
+ import { StandardLog } from "./standard_log.js";
4
+ //#region ts/standard_log.testing.d.ts
5
+ type StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {
6
+ /**
7
+ * Send the logs to console for easy debugging.
8
+ *
9
+ * @default false
10
+ */
11
+ emitLog?: boolean;
11
12
  };
12
- export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
13
- reporter: MemoryLogReporter;
13
+ type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
14
+ reporter: MemoryLogReporter;
14
15
  };
15
- export declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogForTestOptions<N>): StandardLogForTest<N>;
16
+ declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogForTestOptions<N>): StandardLogForTest<N>;
17
+ //#endregion
18
+ export { StandardLogForTest, StandardLogForTestOptions, createStandardLogForTest };
16
19
  //# sourceMappingURL=standard_log.testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standard_log.testing.d.ts","sourceRoot":"","sources":["../ts/standard_log.testing.ts"],"names":[],"mappings":"AAEA,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,yBAAyB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAClG;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,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,yBAAyB,CAAC,CAAC,CAAM,GACxC,kBAAkB,CAAC,CAAC,CAAC,CAiBvB"}
1
+ {"version":3,"file":"standard_log.testing.d.ts","names":[],"sources":["../ts/standard_log.testing.ts"],"mappings":";;;;KAMY,0BAA0B,mBAAmB,kBAAkB,mBAAmB;;;;;;EAM7F;;KAGW,mBAAmB,mBAAmB,kBAAkB,YAAY;EAC/E,UAAU;;iBAGK,yBAAyB,mBAAmB,gBAC3D,UAAS,0BAA0B,KACjC,mBAAmB"}
@@ -1,22 +1,21 @@
1
- import { createConsoleLogReporter } from './console.js';
2
- import { logLevels } from './log_levels.js';
3
- import { createMemoryLogReporter } from './memory.js';
4
- import { createStandardLogClosure } from './standard_log.js';
5
- export function createStandardLogForTest(options = {}) {
6
- var _a, _b;
7
- options.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : logLevels.debug;
8
- options.reporters = (_b = options.reporters) !== null && _b !== void 0 ? _b : [];
9
- if (options.emitLog && !options.reporters.some(r => r.isConsoleReporter)) {
10
- // this is used for debugging,
11
- // so no need to use color reporter.
12
- options.reporters.push(createConsoleLogReporter());
13
- }
14
- const existingReporter = options.reporters.find(r => r.id === 'memory');
15
- const reporter = existingReporter !== null && existingReporter !== void 0 ? existingReporter : createMemoryLogReporter();
16
- if (!existingReporter) {
17
- options.reporters.push(reporter);
18
- }
19
- const closure = createStandardLogClosure(options);
20
- return { ...closure.standardLog, reporter };
1
+ import { logLevels } from "./log_levels.js";
2
+ import { createConsoleLogReporter } from "./console.js";
3
+ import { createMemoryLogReporter } from "./memory.js";
4
+ import { createStandardLogClosure } from "./standard_log.js";
5
+ //#region ts/standard_log.testing.ts
6
+ function createStandardLogForTest(options = {}) {
7
+ options.logLevel = options.logLevel ?? logLevels.debug;
8
+ options.reporters = options.reporters ?? [];
9
+ if (options.emitLog && !options.reporters.some((r) => r.isConsoleReporter)) options.reporters.push(createConsoleLogReporter());
10
+ const existingReporter = options.reporters.find((r) => r.id === "memory");
11
+ const reporter = existingReporter ?? createMemoryLogReporter();
12
+ if (!existingReporter) options.reporters.push(reporter);
13
+ return {
14
+ ...createStandardLogClosure(options).standardLog,
15
+ reporter
16
+ };
21
17
  }
18
+ //#endregion
19
+ export { createStandardLogForTest };
20
+
22
21
  //# sourceMappingURL=standard_log.testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"standard_log.testing.js","sourceRoot":"","sources":["../ts/standard_log.testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,uBAAuB,EAA0B,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,wBAAwB,EAAoB,MAAM,mBAAmB,CAAA;AAgB9E,MAAM,UAAU,wBAAwB,CACvC,UAAwC,EAAE;;IAE1C,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;IAE3C,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,EAAE;QACzE,8BAA8B;QAC9B,oCAAoC;QACpC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC,CAAA;KAClD;IAED,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 { createConsoleLogReporter } from './console.js'\nimport { 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 StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {\n\t/**\n\t * Send the logs to console for easy debugging.\n\t *\n\t * @default false\n\t */\n\temitLog?: boolean\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {\n\treporter: MemoryLogReporter\n}\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n\toptions: StandardLogForTestOptions<N> = {}\n): StandardLogForTest<N> {\n\toptions.logLevel = options.logLevel ?? logLevels.debug\n\toptions.reporters = options.reporters ?? []\n\n\tif (options.emitLog && !options.reporters.some(r => r.isConsoleReporter)) {\n\t\t// this is used for debugging,\n\t\t// so no need to use color reporter.\n\t\toptions.reporters.push(createConsoleLogReporter())\n\t}\n\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"]}
1
+ {"version":3,"file":"standard_log.testing.js","names":[],"sources":["../ts/standard_log.testing.ts"],"sourcesContent":["import { createConsoleLogReporter } from './console.js'\nimport { 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 StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {\n\t/**\n\t * Send the logs to console for easy debugging.\n\t *\n\t * @default false\n\t */\n\temitLog?: boolean\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {\n\treporter: MemoryLogReporter\n}\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n\toptions: StandardLogForTestOptions<N> = {}\n): StandardLogForTest<N> {\n\toptions.logLevel = options.logLevel ?? logLevels.debug\n\toptions.reporters = options.reporters ?? []\n\n\tif (options.emitLog && !options.reporters.some(r => r.isConsoleReporter)) {\n\t\t// this is used for debugging,\n\t\t// so no need to use color reporter.\n\t\toptions.reporters.push(createConsoleLogReporter())\n\t}\n\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"],"mappings":";;;;;AAmBA,SAAgB,yBACf,UAAwC,CAAC,GACjB;CACxB,QAAQ,WAAW,QAAQ,YAAY,UAAU;CACjD,QAAQ,YAAY,QAAQ,aAAa,CAAC;CAE1C,IAAI,QAAQ,WAAW,CAAC,QAAQ,UAAU,MAAK,MAAK,EAAE,iBAAiB,GAGtE,QAAQ,UAAU,KAAK,yBAAyB,CAAC;CAGlD,MAAM,mBAAmB,QAAQ,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ;CACtE,MAAM,WAAW,oBAAoB,wBAAwB;CAC7D,IAAI,CAAC,kBACJ,QAAQ,UAAU,KAAK,QAAQ;CAGhC,OAAO;EAAE,GADO,yBAA4B,OAC1B,CAAC,CAAC;EAAa;CAAS;AAC3C"}
@@ -1,3 +1,3 @@
1
- export { type MemoryLogReporter } from '../memory.js';
2
- export { createStandardLogForTest, type StandardLogForTestOptions, type StandardLogForTest } from '../standard_log.testing.js';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { MemoryLogReporter } from "../memory.js";
2
+ import { StandardLogForTest, StandardLogForTestOptions, createStandardLogForTest } from "../standard_log.testing.js";
3
+ export { type MemoryLogReporter, type StandardLogForTest, type StandardLogForTestOptions, createStandardLogForTest };
@@ -1,2 +1,2 @@
1
- export { createStandardLogForTest } from '../standard_log.testing.js';
2
- //# sourceMappingURL=index.js.map
1
+ import { createStandardLogForTest } from "../standard_log.testing.js";
2
+ export { createStandardLogForTest };
package/esm/types.d.ts CHANGED
@@ -1,144 +1,145 @@
1
- import type { StackTraceMeta } from '@just-func/types';
2
- export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
3
- /**
4
- * A map of custom log levels.
5
- *
6
- * Each logger created will have a method for each custom level.
7
- *
8
- * ```ts
9
- * import { createStandardLog } from 'standard-log'
10
- *
11
- * const sl = createStandardLog({ customLevels: { foo: 100 } })
12
- * const logger = sl.getLogger('my-logger')
13
- *
14
- * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
15
- * ```
16
- */
17
- customLevels?: Record<CustomLevelNames, number>;
18
- logLevel?: number;
19
- reporters?: LogReporter[];
1
+ import { StackTraceMeta } from "@just-func/types";
2
+ //#region ts/types.d.ts
3
+ type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
4
+ /**
5
+ * A map of custom log levels.
6
+ *
7
+ * Each logger created will have a method for each custom level.
8
+ *
9
+ * ```ts
10
+ * import { createStandardLog } from 'standard-log'
11
+ *
12
+ * const sl = createStandardLog({ customLevels: { foo: 100 } })
13
+ * const logger = sl.getLogger('my-logger')
14
+ *
15
+ * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
16
+ * ```
17
+ */
18
+ customLevels?: Record<CustomLevelNames, number>;
19
+ logLevel?: number;
20
+ reporters?: LogReporter[];
20
21
  };
21
- export interface LoggerOptions extends StackTraceMeta {
22
- level?: number;
23
- writeTo?: LogReporter | ReporterFilter;
22
+ interface LoggerOptions extends StackTraceMeta {
23
+ level?: number;
24
+ writeTo?: LogReporter | ReporterFilter;
24
25
  }
25
- export type Logger<N extends string = LogMethodNames> = {
26
- readonly id: string;
27
- /**
28
- * Logger local log level.
29
- */
30
- level?: number;
31
- /**
32
- * Logs with an increment counter.
33
- * This is useful during debugging to check for steps executed.
34
- */
35
- count(...args: any[]): void;
36
- on(level: number | N, logFunction: LogFunction): void;
37
- /**
38
- * Write custom log entries.
39
- */
40
- write(entry: LogEntry): void;
41
- } & {
42
- [k in N]: LogMethod;
43
- };
26
+ type Logger<N extends string = LogMethodNames> = {
27
+ readonly id: string;
28
+ /**
29
+ * Logger local log level.
30
+ */
31
+ level?: number;
32
+ /**
33
+ * Logs with an increment counter.
34
+ * This is useful during debugging to check for steps executed.
35
+ */
36
+ count(...args: any[]): void;
37
+ on(level: number | N, logFunction: LogFunction): void;
38
+ /**
39
+ * Write custom log entries.
40
+ */
41
+ write(entry: LogEntry): void;
42
+ } & { [k in N]: LogMethod; };
44
43
  /**
45
44
  * Names of the standard log methods.
46
45
  */
47
- export type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
48
- export type LogEntry = {
49
- id: string;
50
- level: number;
51
- args: any[];
52
- timestamp: Date;
46
+ type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
47
+ type LogEntry = {
48
+ id: string;
49
+ level: number;
50
+ args: any[];
51
+ timestamp: Date;
53
52
  };
54
- export type LogMethod = (...args: any[]) => void;
55
- export type LogFunction = (log: LogMethod, logLevel: number) => string | void;
56
- export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
57
- export interface StandardLogInstance<N extends string = LogMethodNames> {
58
- /**
59
- * The current log level.
60
- */
61
- logLevel: number;
62
- /**
63
- * Convert log level number to log level name.
64
- */
65
- toLogLevelName(level: number): string;
66
- /**
67
- * Convert log level name to log level number.
68
- */
69
- toLogLevel(name: N): number;
70
- /**
71
- * Get a logger instance with the specified id.
72
- *
73
- * ```ts
74
- * const logger = getLogger('my-logger')
75
- *
76
- * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
77
- * ```
78
- */
79
- getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
80
- /**
81
- * Get a non-console logger instance with the specified id.
82
- *
83
- * The resulting logger will only send to the reporters that are not console reporters.
84
- *
85
- * ```ts
86
- * const logger = getNonConsoleLogger('my-logger')
87
- *
88
- * logger.info('Hello world!') // will not send to any console reporter
89
- * ```
90
- */
91
- getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
53
+ type LogMethod = (...args: any[]) => void;
54
+ type LogFunction = (log: LogMethod, logLevel: number) => string | undefined | void;
55
+ type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
56
+ interface StandardLogInstance<N extends string = LogMethodNames> {
57
+ /**
58
+ * The current log level.
59
+ */
60
+ logLevel: number;
61
+ /**
62
+ * Convert log level number to log level name.
63
+ */
64
+ toLogLevelName(level: number): string;
65
+ /**
66
+ * Convert log level name to log level number.
67
+ */
68
+ toLogLevel(name: N): number;
69
+ /**
70
+ * Get a logger instance with the specified id.
71
+ *
72
+ * ```ts
73
+ * const logger = getLogger('my-logger')
74
+ *
75
+ * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
76
+ * ```
77
+ */
78
+ getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
79
+ /**
80
+ * Get a non-console logger instance with the specified id.
81
+ *
82
+ * The resulting logger will only send to the reporters that are not console reporters.
83
+ *
84
+ * ```ts
85
+ * const logger = getNonConsoleLogger('my-logger')
86
+ *
87
+ * logger.info('Hello world!') // will not send to any console reporter
88
+ * ```
89
+ */
90
+ getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
92
91
  }
93
92
  /**
94
93
  * Formats a log entry.
95
94
  * Depends on the reporter, it can expect a different return type.
96
95
  * By default the return type is `any[]` which the `console` accepts.
97
96
  */
98
- export type LogFormatter<T = any[]> = (entry: LogEntry) => T;
97
+ type LogFormatter<T = any[]> = (entry: LogEntry) => T;
99
98
  /**
100
99
  * Determines whether the entry should be written.
101
100
  */
102
- export type LogFilter = (entry: LogEntry) => boolean;
103
- export type LogLevelEntry = {
104
- name: string;
105
- level: number;
101
+ type LogFilter = (entry: LogEntry) => boolean;
102
+ type LogLevelEntry = {
103
+ name: string;
104
+ level: number;
106
105
  };
107
- export interface LogReporter<T = any> {
108
- readonly id: string;
109
- /**
110
- * Specifies the formatter to be used by the reporter.
111
- * Using this you can customize how the reporter writes the log entry.
112
- */
113
- readonly formatter: LogFormatter<T>;
114
- /**
115
- * Specifies a filter to determine should the log be written.
116
- */
117
- readonly filter?: LogFilter;
118
- /**
119
- * Indicates if this is a console reporter.
120
- * There is only one console reporter can be present in the system.
121
- */
122
- readonly isConsoleReporter?: boolean;
123
- write(entry: LogEntry): void;
106
+ interface LogReporter<T = any> {
107
+ readonly id: string;
108
+ /**
109
+ * Specifies the formatter to be used by the reporter.
110
+ * Using this you can customize how the reporter writes the log entry.
111
+ */
112
+ readonly formatter: LogFormatter<T>;
113
+ /**
114
+ * Specifies a filter to determine should the log be written.
115
+ */
116
+ readonly filter?: LogFilter;
117
+ /**
118
+ * Indicates if this is a console reporter.
119
+ * There is only one console reporter can be present in the system.
120
+ */
121
+ readonly isConsoleReporter?: boolean;
122
+ write(entry: LogEntry): void;
124
123
  }
125
- export type LogReporterOptions<T = any> = {
126
- id?: string;
127
- /**
128
- * Specifies the formatter to be used by the reporter.
129
- * Using this you can customize how the reporter writes the log entry.
130
- */
131
- formatter?: LogFormatter<T>;
132
- /**
133
- * Specifies a filter to determine should the log be written.
134
- */
135
- filter?: LogFilter;
124
+ type LogReporterOptions<T = any> = {
125
+ id?: string;
126
+ /**
127
+ * Specifies the formatter to be used by the reporter.
128
+ * Using this you can customize how the reporter writes the log entry.
129
+ */
130
+ formatter?: LogFormatter<T>;
131
+ /**
132
+ * Specifies a filter to determine should the log be written.
133
+ */
134
+ filter?: LogFilter;
136
135
  };
137
- export type LogLevel = number;
138
- export interface ConsoleLike {
139
- debug(...args: any[]): void;
140
- info(...args: any[]): void;
141
- warn(...args: any[]): void;
142
- error(...args: any[]): void;
136
+ type LogLevel = number;
137
+ interface ConsoleLike {
138
+ debug(...args: any[]): void;
139
+ info(...args: any[]): void;
140
+ warn(...args: any[]): void;
141
+ error(...args: any[]): void;
143
142
  }
143
+ //#endregion
144
+ export { ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, LogLevel, LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, Logger, LoggerOptions, ReporterFilter, StandardLogInstance, StandardLogOptions };
144
145
  //# sourceMappingURL=types.d.ts.map