standard-log 12.0.5 → 12.1.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 (48) hide show
  1. package/cjs/logger.js.map +1 -1
  2. package/cjs/memory.d.ts +1 -0
  3. package/cjs/memory.d.ts.map +1 -1
  4. package/cjs/memory.js +5 -0
  5. package/cjs/memory.js.map +1 -1
  6. package/cjs/{standard_log.mocks.d.ts → standard_log.testing.d.ts} +10 -2
  7. package/cjs/standard_log.testing.d.ts.map +1 -0
  8. package/cjs/{standard_log.mocks.js → standard_log.testing.js} +7 -1
  9. package/cjs/standard_log.testing.js.map +1 -0
  10. package/cjs/testing/index.d.ts +1 -1
  11. package/cjs/testing/index.d.ts.map +1 -1
  12. package/cjs/testing/index.js +2 -2
  13. package/cjs/testing/index.js.map +1 -1
  14. package/cjs/types.d.ts +2 -2
  15. package/cjs/types.js.map +1 -1
  16. package/dist/standard-log.es5.js +220 -215
  17. package/dist/standard-log.es5.js.gz +0 -0
  18. package/dist/standard-log.es5.js.map +1 -1
  19. package/dist/standard-log.es5.js.map.gz +0 -0
  20. package/dist/standard-log.esm.js +17 -12
  21. package/dist/standard-log.esm.js.gz +0 -0
  22. package/dist/standard-log.esm.js.map +1 -1
  23. package/dist/standard-log.esm.js.map.gz +0 -0
  24. package/esm/logger.js.map +1 -1
  25. package/esm/memory.d.ts +1 -0
  26. package/esm/memory.d.ts.map +1 -1
  27. package/esm/memory.js +5 -0
  28. package/esm/memory.js.map +1 -1
  29. package/esm/{standard_log.mocks.d.ts → standard_log.testing.d.ts} +10 -2
  30. package/esm/standard_log.testing.d.ts.map +1 -0
  31. package/esm/{standard_log.mocks.js → standard_log.testing.js} +7 -1
  32. package/esm/standard_log.testing.js.map +1 -0
  33. package/esm/testing/index.d.ts +1 -1
  34. package/esm/testing/index.d.ts.map +1 -1
  35. package/esm/testing/index.js +1 -1
  36. package/esm/testing/index.js.map +1 -1
  37. package/esm/types.d.ts +2 -2
  38. package/esm/types.js.map +1 -1
  39. package/package.json +3 -2
  40. package/ts/logger.ts +1 -1
  41. package/ts/memory.ts +6 -0
  42. package/ts/{standard_log.mocks.ts → standard_log.testing.ts} +18 -1
  43. package/ts/testing/index.ts +5 -1
  44. package/ts/types.ts +2 -2
  45. package/cjs/standard_log.mocks.d.ts.map +0 -1
  46. package/cjs/standard_log.mocks.js.map +0 -1
  47. package/esm/standard_log.mocks.d.ts.map +0 -1
  48. package/esm/standard_log.mocks.js.map +0 -1
package/cjs/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA2C;AAK3C,SAAgB,YAAY,CAC3B,KAAe,EACf,EAAU,EACV,OAAuB;;IAEvB,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAC1C,IAAA,KACL,OAAO,OAAO,KAAK,QAAQ;QAC1B,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,EAAE,KAAK,OAAO,EAAd,CAAc,EAAE,KAAK,CAAC,SAAS,CAAC;QACzC,CAAC,CAAC,OAAO,YAAY,MAAM;YAC3B,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAhB,CAAgB,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,CAAC,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,CAAC,OAAO,CAAC,CAAC,EAPpB,MAAM,QAAA,EAAE,SAAS,QAOG,CAAA;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,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
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA2C;AAK3C,SAAgB,YAAY,CAC3B,KAAe,EACf,EAAU,EACV,OAAuB;;IAEvB,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CA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C;oBAAE,KAAK,CAAC,EAAE,EAAE,IAAA,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC7F,CAAC;SACD,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACd,CAAC;AAhED,oCAgEC;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,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,EAAlB,CAAkB,CAAC,CAAA;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[]): void => {\n\t\t\t\t\tif (shouldLog(store, logLevels.debug, logger.level))\n\t\t\t\t\t\twrite({\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tlevel: logLevels.debug,\n\t\t\t\t\t\t\targs: [++counter, ...args],\n\t\t\t\t\t\t\ttimestamp: new Date()\n\t\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t)(0)\n\t\t},\n\t\ton: {\n\t\t\twritable: false,\n\t\t\tvalue: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n\t\t\t\tconst logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n\t\t\t\tif (shouldLog(store, logLevel, logger.level)) {\n\t\t\t\t\tconst methodName = store.logLevelStore.getName(logLevel)\n\t\t\t\t\tconst bindedMethod = logger[methodName].bind(logger)\n\t\t\t\t\tconst result = logFn(bindedMethod, logger.level ?? store.logLevel)\n\t\t\t\t\tif (result) bindedMethod(result)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n\tstore.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n\t\tObject.defineProperty(logger, name, {\n\t\t\twritable: false,\n\t\t\tvalue: (...args: any[]) => {\n\t\t\t\tif (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n\t\t\t}\n\t\t})\n\t})\n\treturn logger\n}\n\nfunction sanitizeId(id: string) {\n\treturn id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(\n\treporters: LogReporter[],\n\tlogEntry: LogEntry,\n\tfilter: (reporterId: string) => boolean\n) {\n\treporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n\treturn targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
package/cjs/memory.d.ts CHANGED
@@ -8,6 +8,7 @@ export type MemoryLogReporter = LogReporter<LogEntry> & {
8
8
  getLogMessage(): string;
9
9
  getLogMessages(): string[];
10
10
  getLogMessageWithLevel(): string;
11
+ getLogMessagesWithLevel(): string[];
11
12
  getLogMessagesWithIdAndLevel(): string[];
12
13
  emit(): void;
13
14
  };
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACvD,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAA;IACvB,cAAc,IAAI,MAAM,EAAE,CAAA;IAC1B,sBAAsB,IAAI,MAAM,CAAA;IAChC,4BAA4B,IAAI,MAAM,EAAE,CAAA;IACxC,IAAI,IAAI,IAAI,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAWlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAEjG;AA0CD,wBAAgB,kCAAkC,CACjD,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,iBAAiB,CAMnB"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACvD,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAA;IACvB,cAAc,IAAI,MAAM,EAAE,CAAA;IAC1B,sBAAsB,IAAI,MAAM,CAAA;IAChC,uBAAuB,IAAI,MAAM,EAAE,CAAA;IACnC,4BAA4B,IAAI,MAAM,EAAE,CAAA;IACxC,IAAI,IAAI,IAAI,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAWlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAEjG;AA+CD,wBAAgB,kCAAkC,CACjD,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,iBAAiB,CAMnB"}
package/cjs/memory.js CHANGED
@@ -43,6 +43,11 @@ function buildMemoryReporter(options) {
43
43
  getLogMessages: function () {
44
44
  return logs.map(platform_js_1.toInspectLogEntry).map(function (log) { return log.args.join(' '); });
45
45
  },
46
+ getLogMessagesWithLevel: function () {
47
+ return logs
48
+ .map(platform_js_1.toInspectLogEntry)
49
+ .map(function (log) { return "".concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); });
50
+ },
46
51
  getLogMessagesWithIdAndLevel: function () {
47
52
  return logs
48
53
  .map(platform_js_1.toInspectLogEntry)
package/cjs/memory.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,6CAAiD;AACjD,+CAA+C;AAE/C,2CAAuD;AAiBvD,SAAgB,kBAAkB,CAAC,IAAgB;IAClD,OAAO,CACN,IAAI;SACF,GAAG,CAAC,+BAAiB,CAAC;SACtB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAApD,CAAoD,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAClF,CAAA;AACF,CAAC;AAXD,gDAWC;AAED,SAAgB,uBAAuB,CAAC,OAAsC;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;AAChF,CAAC;AAFD,0DAEC;AAED,SAAS,mBAAmB,CAAC,OAAsC;IAC5D,IAAA,KAA4B,IAAA,oBAAQ,EAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAC,CAAW,IAAK,OAAA,CAAC,EAAD,CAAC,EAAE,EAAE,OAAO,CAAC,EAA5F,EAAE,QAAA,EAAE,SAAS,eAAA,EAAE,MAAM,YAAuE,CAAA;IACpG,IAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,OAAO;QACN,EAAE,IAAA;QACF,IAAI,SAAS;YACZ,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,IAAI,MAAM;YACT,OAAO,MAAM,CAAA;QACd,CA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CAAC,EAAE;QACrF,iBAAiB,EAAE,IAAI;KACvB,CAAC,CACF,CAAA;AACF,CAAC;AARD,gFAQC","sourcesContent":["import { required, unpartial } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n\tlogs: LogEntry[]\n\t/**\n\t * Gets a simple log message for testing.\n\t * The message only contains arguments for each log entry.\n\t */\n\tgetLogMessage(): string\n\tgetLogMessages(): string[]\n\tgetLogMessageWithLevel(): string\n\tgetLogMessagesWithIdAndLevel(): string[]\n\temit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n\treturn (\n\t\tlogs\n\t\t\t.map(toInspectLogEntry)\n\t\t\t.map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t\t.join('\\n')\n\t\t\t// if it has more than this log,\n\t\t\t// we assume it is running under tests,\n\t\t\t// and remove this log to simplify testing.\n\t\t\t.replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n\t)\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n\treturn Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))\n}\n\nfunction buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {\n\tconst { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n\tconst logs: LogEntry[] = []\n\treturn {\n\t\tid,\n\t\tget formatter() {\n\t\t\treturn formatter\n\t\t},\n\t\tget filter() {\n\t\t\treturn filter\n\t\t},\n\t\tlogs,\n\t\twrite(entry: LogEntry) {\n\t\t\tif (filter && !filter(entry)) return\n\t\t\tlogs.push(formatter(entry))\n\t\t},\n\t\tgetLogMessage() {\n\t\t\treturn this.getLogMessages().join('\\n')\n\t\t},\n\t\tgetLogMessages() {\n\t\t\treturn logs.map(toInspectLogEntry).map(log => log.args.join(' '))\n\t\t},\n\t\tgetLogMessagesWithIdAndLevel() {\n\t\t\treturn logs\n\t\t\t\t.map(toInspectLogEntry)\n\t\t\t\t.map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t},\n\t\tgetLogMessageWithLevel() {\n\t\t\treturn toMessageWithLevel(logs)\n\t\t},\n\t\t/**\n\t\t * emit the saved log to console for easy debugging\n\t\t */\n\t\temit() {\n\t\t\tconst reporter = createConsoleLogReporter()\n\t\t\tlogs.forEach(l => reporter.write(l))\n\t\t}\n\t}\n}\n\nexport function createMemoryWithConsoleLogReporter(\n\toptions?: LogReporterOptions<LogEntry>\n): MemoryLogReporter {\n\treturn Object.freeze(\n\t\tObject.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {\n\t\t\tisConsoleReporter: true\n\t\t})\n\t)\n}\n"]}
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,6CAAiD;AACjD,+CAA+C;AAE/C,2CAAuD;AAkBvD,SAAgB,kBAAkB,CAAC,IAAgB;IAClD,OAAO,CACN,IAAI;SACF,GAAG,CAAC,+BAAiB,CAAC;SACtB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAApD,CAAoD,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAClF,CAAA;AACF,CAAC;AAXD,gDAWC;AAED,SAAgB,uBAAuB,CAAC,OAAsC;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC,m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D,CAAoD,CAAC,CAAA;QACnE,CAAC;QACD,4BAA4B;YAC3B,OAAO,IAAI;iBACT,GAAG,CAAC,+BAAiB,CAAC;iBACtB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,GAAG,CAAC,EAAE,cAAI,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAA9D,CAA8D,CAAC,CAAA;QAC7E,CAAC;QACD,sBAAsB;YACrB,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QACD;;WAEG;QACH,IAAI;YACH,IAAM,QAAQ,GAAG,IAAA,qCAAwB,GAAE,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC,CAAA;QACrC,CAAC;KACD,CAAA;AACF,CAAC;AAED,SAAgB,kCAAkC,CACjD,OAAsC;IAEtC,OAAO,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE;QACrF,iBAAiB,EAAE,IAAI;KACvB,CAAC,CACF,CAAA;AACF,CAAC;AARD,gFAQC","sourcesContent":["import { required, unpartial } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n\tlogs: LogEntry[]\n\t/**\n\t * Gets a simple log message for testing.\n\t * The message only contains arguments for each log entry.\n\t */\n\tgetLogMessage(): string\n\tgetLogMessages(): string[]\n\tgetLogMessageWithLevel(): string\n\tgetLogMessagesWithLevel(): string[]\n\tgetLogMessagesWithIdAndLevel(): string[]\n\temit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n\treturn (\n\t\tlogs\n\t\t\t.map(toInspectLogEntry)\n\t\t\t.map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t\t.join('\\n')\n\t\t\t// if it has more than this log,\n\t\t\t// we assume it is running under tests,\n\t\t\t// and remove this log to simplify testing.\n\t\t\t.replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n\t)\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n\treturn Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))\n}\n\nfunction buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {\n\tconst { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n\tconst logs: LogEntry[] = []\n\treturn {\n\t\tid,\n\t\tget formatter() {\n\t\t\treturn formatter\n\t\t},\n\t\tget filter() {\n\t\t\treturn filter\n\t\t},\n\t\tlogs,\n\t\twrite(entry: LogEntry) {\n\t\t\tif (filter && !filter(entry)) return\n\t\t\tlogs.push(formatter(entry))\n\t\t},\n\t\tgetLogMessage() {\n\t\t\treturn this.getLogMessages().join('\\n')\n\t\t},\n\t\tgetLogMessages() {\n\t\t\treturn logs.map(toInspectLogEntry).map(log => log.args.join(' '))\n\t\t},\n\t\tgetLogMessagesWithLevel() {\n\t\t\treturn logs\n\t\t\t\t.map(toInspectLogEntry)\n\t\t\t\t.map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t},\n\t\tgetLogMessagesWithIdAndLevel() {\n\t\t\treturn logs\n\t\t\t\t.map(toInspectLogEntry)\n\t\t\t\t.map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n\t\t},\n\t\tgetLogMessageWithLevel() {\n\t\t\treturn toMessageWithLevel(logs)\n\t\t},\n\t\t/**\n\t\t * emit the saved log to console for easy debugging\n\t\t */\n\t\temit() {\n\t\t\tconst reporter = createConsoleLogReporter()\n\t\t\tlogs.forEach(l => reporter.write(l))\n\t\t}\n\t}\n}\n\nexport function createMemoryWithConsoleLogReporter(\n\toptions?: LogReporterOptions<LogEntry>\n): MemoryLogReporter {\n\treturn Object.freeze(\n\t\tObject.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {\n\t\t\tisConsoleReporter: true\n\t\t})\n\t)\n}\n"]}
@@ -1,8 +1,16 @@
1
1
  import { type MemoryLogReporter } from './memory.js';
2
2
  import { type StandardLog } from './standard_log.js';
3
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 to easy debugging.
7
+ *
8
+ * @default false
9
+ */
10
+ emitLog?: boolean;
11
+ };
4
12
  export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
5
13
  reporter: MemoryLogReporter;
6
14
  };
7
- export declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): StandardLogForTest<N>;
8
- //# sourceMappingURL=standard_log.mocks.d.ts.map
15
+ export declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogForTestOptions<N>): StandardLogForTest<N>;
16
+ //# sourceMappingURL=standard_log.testing.d.ts.map
@@ -0,0 +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"}
@@ -12,6 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createStandardLogForTest = void 0;
15
+ var console_js_1 = require("./console.js");
15
16
  var log_levels_js_1 = require("./log_levels.js");
16
17
  var memory_js_1 = require("./memory.js");
17
18
  var standard_log_js_1 = require("./standard_log.js");
@@ -20,6 +21,11 @@ function createStandardLogForTest(options) {
20
21
  if (options === void 0) { options = {}; }
21
22
  options.logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : log_levels_js_1.logLevels.debug;
22
23
  options.reporters = (_b = options.reporters) !== null && _b !== void 0 ? _b : [];
24
+ if (options.emitLog && !options.reporters.some(function (r) { return r.isConsoleReporter; })) {
25
+ // this is used for debugging,
26
+ // so no need to use color reporter.
27
+ options.reporters.push((0, console_js_1.createConsoleLogReporter)());
28
+ }
23
29
  var existingReporter = options.reporters.find(function (r) { return r.id === 'memory'; });
24
30
  var reporter = existingReporter !== null && existingReporter !== void 0 ? existingReporter : (0, memory_js_1.createMemoryLogReporter)();
25
31
  if (!existingReporter) {
@@ -29,4 +35,4 @@ function createStandardLogForTest(options) {
29
35
  return __assign(__assign({}, closure.standardLog), { reporter: reporter });
30
36
  }
31
37
  exports.createStandardLogForTest = createStandardLogForTest;
32
- //# sourceMappingURL=standard_log.mocks.js.map
38
+ //# sourceMappingURL=standard_log.testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard_log.testing.js","sourceRoot":"","sources":["../ts/standard_log.testing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2CAAuD;AACvD,iDAA2C;AAC3C,yCAA6E;AAC7E,qDAA8E;AAgB9E,SAAgB,wBAAwB,CACvC,OAA0C;;IAA1C,wBAAA,EAAA,YAA0C;IAE1C,OAAO,CAAC,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,yBAAS,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,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,iBAAiB,EAAnB,CAAmB,CAAC,EAAE;QACzE,8BAA8B;QAC9B,oCAAoC;QACpC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAA,qCAAwB,GAAE,CAAC,CAAA;KAClD;IAED,IAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,EAAE,KAAK,QAAQ,EAAjB,CAAiB,CAAsB,CAAA;IAC5F,IAAM,QAAQ,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAA,mCAAuB,GAAE,CAAA;IAC9D,IAAI,CAAC,gBAAgB,EAAE;QACtB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAChC;IACD,IAAM,OAAO,GAAG,IAAA,0CAAwB,EAAI,OAAO,CAAC,CAAA;IACpD,6BAAY,OAAO,CAAC,WAAW,KAAE,QAAQ,UAAA,IAAE;AAC5C,CAAC;AAnBD,4DAmBC","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 to 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,3 +1,3 @@
1
1
  export { type MemoryLogReporter } from '../memory.js';
2
- export { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js';
2
+ export { createStandardLogForTest, type StandardLogForTestOptions, type StandardLogForTest } from '../standard_log.testing.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EACN,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,MAAM,4BAA4B,CAAA"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStandardLogForTest = void 0;
4
- var standard_log_mocks_js_1 = require("../standard_log.mocks.js");
5
- Object.defineProperty(exports, "createStandardLogForTest", { enumerable: true, get: function () { return standard_log_mocks_js_1.createStandardLogForTest; } });
4
+ var standard_log_testing_js_1 = require("../standard_log.testing.js");
5
+ Object.defineProperty(exports, "createStandardLogForTest", { enumerable: true, get: function () { return standard_log_testing_js_1.createStandardLogForTest; } });
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":";;;AACA,kEAA4F;AAAnF,iIAAA,wBAAwB,OAAA","sourcesContent":["export { type MemoryLogReporter } from '../memory.js'\nexport { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":";;;AACA,sEAImC;AAHlC,mIAAA,wBAAwB,OAAA","sourcesContent":["export { type MemoryLogReporter } from '../memory.js'\nexport {\n\tcreateStandardLogForTest,\n\ttype StandardLogForTestOptions,\n\ttype StandardLogForTest\n} from '../standard_log.testing.js'\n"]}
package/cjs/types.d.ts CHANGED
@@ -71,7 +71,7 @@ export interface StandardLogInstance<N extends string = LogMethodNames> {
71
71
  * Get a logger instance with the specified id.
72
72
  *
73
73
  * ```ts
74
- * const logger = sl.getLogger('my-logger')
74
+ * const logger = getLogger('my-logger')
75
75
  *
76
76
  * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
77
77
  * ```
@@ -83,7 +83,7 @@ export interface StandardLogInstance<N extends string = LogMethodNames> {
83
83
  * The resulting logger will only send to the reporters that are not console reporters.
84
84
  *
85
85
  * ```ts
86
- * const logger = sl.getNonConsoleLogger('my-logger')
86
+ * const logger = getNonConsoleLogger('my-logger')
87
87
  *
88
88
  * logger.info('Hello world!') // will not send to any console reporter
89
89
  * ```
package/cjs/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\t/**\n\t * A map of custom log levels.\n\t *\n\t * Each logger created will have a method for each custom level.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ customLevels: { foo: 100 } })\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!\n\t * ```\n\t */\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\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\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\t/**\n\t * The current log level.\n\t */\n\tlogLevel: number\n\t/**\n\t * Convert log level number to log level name.\n\t */\n\ttoLogLevelName(level: number): string\n\t/**\n\t * Convert log level name to log level number.\n\t */\n\ttoLogLevel(name: N): number\n\t/**\n\t * Get a logger instance with the specified id.\n\t *\n\t * ```ts\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!\n\t * ```\n\t */\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\t/**\n\t * Get a non-console logger instance with the specified id.\n\t *\n\t * The resulting logger will only send to the reporters that are not console reporters.\n\t *\n\t * ```ts\n\t * const logger = sl.getNonConsoleLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // will not send to any console reporter\n\t * ```\n\t */\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t * Indicates if this is a console reporter.\n\t * There is only one console reporter can be present in the system.\n\t */\n\treadonly isConsoleReporter?: boolean\n\twrite(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n\tid?: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\tformatter?: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\tfilter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n\tdebug(...args: any[]): void\n\tinfo(...args: any[]): void\n\twarn(...args: any[]): void\n\terror(...args: any[]): void\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\t/**\n\t * A map of custom log levels.\n\t *\n\t * Each logger created will have a method for each custom level.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ customLevels: { foo: 100 } })\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!\n\t * ```\n\t */\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\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\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\t/**\n\t * The current log level.\n\t */\n\tlogLevel: number\n\t/**\n\t * Convert log level number to log level name.\n\t */\n\ttoLogLevelName(level: number): string\n\t/**\n\t * Convert log level name to log level number.\n\t */\n\ttoLogLevel(name: N): number\n\t/**\n\t * Get a logger instance with the specified id.\n\t *\n\t * ```ts\n\t * const logger = getLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!\n\t * ```\n\t */\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\t/**\n\t * Get a non-console logger instance with the specified id.\n\t *\n\t * The resulting logger will only send to the reporters that are not console reporters.\n\t *\n\t * ```ts\n\t * const logger = getNonConsoleLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // will not send to any console reporter\n\t * ```\n\t */\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t * Indicates if this is a console reporter.\n\t * There is only one console reporter can be present in the system.\n\t */\n\treadonly isConsoleReporter?: boolean\n\twrite(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n\tid?: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\tformatter?: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\tfilter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n\tdebug(...args: any[]): void\n\tinfo(...args: any[]): void\n\twarn(...args: any[]): void\n\terror(...args: any[]): void\n}\n"]}