standard-log 10.3.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/memory.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare type MemoryLogReporter = LogReporter<LogEntry> & {
9
9
  getLogMessages(): string[];
10
10
  getLogMessageWithLevel(): string;
11
11
  getLogMessagesWithIdAndLevel(): string[];
12
+ emit(): void;
12
13
  };
13
14
  export declare type MemoryLogFormatter = LogFormatter<LogEntry>;
14
15
  export declare function toMessageWithLevel(logs: LogEntry[]): string;
@@ -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;AAEzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,sBAAsB,IAAI,MAAM,CAAC;IACjC,4BAA4B,IAAI,MAAM,EAAE,CAAA;CACzC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAyBjG"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,sBAAsB,IAAI,MAAM,CAAC;IACjC,4BAA4B,IAAI,MAAM,EAAE,CAAC;IACzC,IAAI,IAAI,IAAI,CAAA;CACb,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAgCjG"}
package/cjs/memory.js CHANGED
@@ -4,6 +4,7 @@ exports.createMemoryLogReporter = exports.toMessageWithLevel = void 0;
4
4
  var type_plus_1 = require("type-plus");
5
5
  var platform_js_1 = require("./platform.js");
6
6
  var formatter_js_1 = require("./formatter.js");
7
+ var console_js_1 = require("./console.js");
7
8
  function toMessageWithLevel(logs) {
8
9
  return logs.map(platform_js_1.toInspectLogEntry)
9
10
  .map(function (log) { return "".concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); })
@@ -38,7 +39,14 @@ function createMemoryLogReporter(options) {
38
39
  return logs.map(platform_js_1.toInspectLogEntry)
39
40
  .map(function (log) { return "".concat(log.id, " ").concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); });
40
41
  },
41
- getLogMessageWithLevel: function () { return toMessageWithLevel(logs); }
42
+ getLogMessageWithLevel: function () { return toMessageWithLevel(logs); },
43
+ /**
44
+ * emit the saved log to console for easy debugging
45
+ */
46
+ emit: function () {
47
+ var reporter = (0, console_js_1.createConsoleLogReporter)();
48
+ logs.forEach(function (l) { return reporter.write(l); });
49
+ }
42
50
  });
43
51
  }
44
52
  exports.createMemoryLogReporter = createMemoryLogReporter;
package/cjs/memory.js.map CHANGED
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AI,CAAC,CAAA;QACzC,CAAC;QACD,cAAc;YACZ,OAAO,IAAI,CAAC,GAAG,CAAC,+BAAiB,CAAC;iBAC/B,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAlB,CAAkB,CAAC,CAAA;QACnC,CAAC;QACD,4BAA4B;YAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,+BAAiB,CAAC;iBAC/B,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;QAC/E,CAAC;QACD,sBAAsB,gBAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAC7D,CAAC,CAAA;AACJ,CAAC;AAzBD,0DAyBC","sourcesContent":["import { required } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n logs: LogEntry[],\n /**\n * Gets a simple log message for testing.\n * The message only contains arguments for each log entry.\n */\n getLogMessage(): string,\n getLogMessages(): string[],\n getLogMessageWithLevel(): string,\n getLogMessagesWithIdAndLevel(): string[]\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry)\n .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n .join('\\n')\n // if it has more than this log,\n // we assume it is running under tests,\n // and remove this log to simplify testing.\n .replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const logs: LogEntry[] = []\n return Object.freeze({\n id,\n get formatter() { return formatter },\n get filter() { return filter },\n logs,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n logs.push(formatter(entry))\n },\n getLogMessage() {\n return this.getLogMessages().join('\\n')\n },\n getLogMessages() {\n return logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n },\n getLogMessagesWithIdAndLevel() {\n return logs.map(toInspectLogEntry)\n .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n },\n getLogMessageWithLevel() { return toMessageWithLevel(logs) }\n })\n}\n"]}
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,6CAAiD;AACjD,+CAA+C;AAE/C,2CAAuD;AAiBvD,SAAgB,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,+BAAiB,CAAC;SAC/B,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAG,IAAA,6BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,cAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,EAApD,CAAoD,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAAA;AACrF,CAAC;AARD,gDAQC;AAED,SAAgB,uBAAuB,CAAC,OAAsC;IACtE,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,C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;AAhCD,0DAgCC","sourcesContent":["import { required } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n logs: LogEntry[],\n /**\n * Gets a simple log message for testing.\n * The message only contains arguments for each log entry.\n */\n getLogMessage(): string,\n getLogMessages(): string[],\n getLogMessageWithLevel(): string,\n getLogMessagesWithIdAndLevel(): string[],\n emit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry)\n .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n .join('\\n')\n // if it has more than this log,\n // we assume it is running under tests,\n // and remove this log to simplify testing.\n .replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const logs: LogEntry[] = []\n return Object.freeze({\n id,\n get formatter() { return formatter },\n get filter() { return filter },\n logs,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n logs.push(formatter(entry))\n },\n getLogMessage() {\n return this.getLogMessages().join('\\n')\n },\n getLogMessages() {\n return logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n },\n getLogMessagesWithIdAndLevel() {\n return logs.map(toInspectLogEntry)\n .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n },\n getLogMessageWithLevel() { return toMessageWithLevel(logs) },\n /**\n * emit the saved log to console for easy debugging\n */\n emit() {\n const reporter = createConsoleLogReporter()\n logs.forEach(l => reporter.write(l))\n }\n })\n}\n"]}
@@ -100,6 +100,16 @@ describe(index_js_1.createMemoryLogReporter.name, function () {
100
100
  ]);
101
101
  });
102
102
  });
103
+ describe(reporter.emit.name, function () {
104
+ it('emit saved logs to console', function () {
105
+ var r = (0, index_js_1.createMemoryLogReporter)();
106
+ r.write(mikuIsSinging);
107
+ r.write(lukaIsDancing);
108
+ r.write({ id: 'test-log', level: index_js_1.logLevels.info, args: ['the two messages above are expected'], timestamp: new Date() });
109
+ // inspect visually
110
+ r.emit();
111
+ });
112
+ });
103
113
  });
104
114
  describe(testUtil_js_1.logEntriesToString.name, function () {
105
115
  test('convert log entries to string', function () {
@@ -1 +1 @@
1
- {"version":3,"file":"memory.spec.js","sourceRoot":"","sources":["../ts/memory.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAyB;AACzB,uCAAkG;AAClG,6CAA6D;AAE7D,IAAM,aAAa,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;AACvH,IAAM,aAAa,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;AACvH,IAAM,QAAQ,GAAG,IAAA,kCAAuB,GAAE,CAAA;AAE1C,QAAQ,CAAC,kCAAuB,CAAC,IAAI,EAAE;IACrC,EAAE,CAAC,oBAAoB,EAAE;QACvB,IAAM,QAAQ,GAAG,IAAA,kCAAuB,GAAE,CAAA;QAC1C,IAAM,GAAG,GAAG,mBAAC,CAAC,MAAM,CAAC,cAAS,QAAgB,CAAC,MAAM,GAAG,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAA,CAAC,CAAC,EAAE,UAAA,GAAG,IAAI,OAAA,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,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AAM,GAAG,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAG,GAAG,8BAA2B,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import a from 'assertron'\nimport { createMemoryLogReporter, LogEntry, LogFilter, LogFormatter, logLevels } from './index.js'\nimport { assertSSF, logEntriesToString } from './testUtil.js'\n\nconst mikuIsSinging = { id: 'test-log', level: logLevels.info, args: ['miku', 'is', 'singing'], timestamp: new Date() }\nconst lukaIsDancing = { id: 'test-log', level: logLevels.warn, args: ['luka', 'is', 'dancing'], timestamp: new Date() }\nconst reporter = createMemoryLogReporter()\n\ndescribe(createMemoryLogReporter.name, () => {\n it('filter is readonly', () => {\n const reporter = createMemoryLogReporter()\n const err = a.throws(() => { (reporter as any).filter = () => true }, err => /only a getter/.test(err))\n\n assertSSF(err, __filename)\n })\n\n test('log entries are saved in the `logs` property', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['some messages'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.logs).toEqual([entry])\n })\n\n test('can override id', () => {\n const reporter = createMemoryLogReporter({ id: 'custom-id-mem' })\n expect(reporter.id).toBe('custom-id-mem')\n })\n\n test('can filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n const reporter = createMemoryLogReporter({ filter })\n expect(reporter.filter).toBe(filter)\n reporter.write({ id: 'ok', level: 1, args: ['some messages'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: 1, args: ['some messages'], timestamp: new Date() })\n expect(reporter.logs.length).toBe(1)\n })\n\n test('formatter can be used to pre-process the log', () => {\n const formatter: LogFormatter<LogEntry> = (entry) => ({\n ...entry,\n args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)\n })\n const reporter = createMemoryLogReporter({ formatter })\n expect(reporter.formatter).toBe(formatter)\n\n const entry = { id: 'log', level: 1, args: ['a', 'secret', 'b'], timestamp: new Date() }\n reporter.write(entry)\n\n expect(reporter.logs[0].args[1]).toBe('<censored>')\n })\n\n describe(reporter.getLogMessages.name, () => {\n it('maps each log entries to string', () => {\n const r = createMemoryLogReporter()\n r.write(mikuIsSinging)\n r.write(lukaIsDancing)\n expect(r.getLogMessages()).toEqual([\n 'miku is singing',\n 'luka is dancing'\n ])\n })\n })\n describe(reporter.getLogMessage.name, () => {\n test('empty logs returns empty string', () => {\n const reporter = createMemoryLogReporter()\n\n expect(reporter.getLogMessage()).toEqual('')\n })\n\n test('print args', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['miku', 'is', 'singing'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual('miku is singing')\n })\n\n test('print object arg', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: [{ 'miku': 'sing' }], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual(\"{ miku: 'sing' }\")\n })\n })\n describe(reporter.getLogMessageWithLevel.name, () => {\n test('print with level', () => {\n const reporter = createMemoryLogReporter()\n reporter.write({ id: 'log', level: logLevels.info, args: ['msg 1'], timestamp: new Date() })\n reporter.write({ id: 'log', level: logLevels.warn, args: ['msg 2'], timestamp: new Date() })\n expect(reporter.getLogMessageWithLevel()).toEqual(`(INFO) msg 1\\n(WARN) msg 2`)\n })\n })\n\n describe(reporter.getLogMessagesWithIdAndLevel.name, () => {\n it('does what the name says', () => {\n const r = createMemoryLogReporter()\n r.write(mikuIsSinging)\n r.write(lukaIsDancing)\n expect(r.getLogMessagesWithIdAndLevel()).toEqual([\n 'test-log (INFO) miku is singing',\n 'test-log (WARN) luka is dancing'\n ])\n })\n })\n})\n\ndescribe(logEntriesToString.name, () => {\n test('convert log entries to string', () => {\n const timestamp = new Date(2019, 6)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.emergency, args: ['emergency'], timestamp },\n { id: 'log', level: logLevels.critical, args: ['critical'], timestamp },\n { id: 'log', level: logLevels.alert, args: ['alert'], timestamp },\n { id: 'log', level: logLevels.error, args: ['error'], timestamp },\n { id: 'log', level: logLevels.warn, args: ['warn'], timestamp },\n { id: 'log', level: logLevels.notice, args: ['notice'], timestamp },\n { id: 'log', level: logLevels.info, args: ['info'], timestamp },\n { id: 'log', level: logLevels.debug, args: ['debug'], timestamp },\n { id: 'log', level: logLevels.trace, args: ['trace'], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(EMERGENCY),emergency\n${iso},log,(CRITICAL),critical\n${iso},log,(ALERT),alert\n${iso},log,(ERROR),error\n${iso},log,(WARN),warn\n${iso},log,(NOTICE),notice\n${iso},log,(INFO),info\n${iso},log,(DEBUG),debug\n${iso},log,(TRACE),trace`)\n })\n\n test('print out object', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', { a: 1 }], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,{ a: 1 }`)\n })\n\n test('print out array', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', [1, 2, 3]], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,[ 1, 2, 3 ]`)\n })\n})\n"]}
1
+ {"version":3,"file":"memory.spec.js","sourceRoot":"","sources":["../ts/memory.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAyB;AACzB,uCAAkG;AAClG,6CAA6D;AAE7D,IAAM,aAAa,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;AACvH,IAAM,aAAa,GAAG,E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AC,CAAC,CAAA","sourcesContent":["import a from 'assertron'\nimport { createMemoryLogReporter, LogEntry, LogFilter, LogFormatter, logLevels } from './index.js'\nimport { assertSSF, logEntriesToString } from './testUtil.js'\n\nconst mikuIsSinging = { id: 'test-log', level: logLevels.info, args: ['miku', 'is', 'singing'], timestamp: new Date() }\nconst lukaIsDancing = { id: 'test-log', level: logLevels.warn, args: ['luka', 'is', 'dancing'], timestamp: new Date() }\nconst reporter = createMemoryLogReporter()\n\ndescribe(createMemoryLogReporter.name, () => {\n it('filter is readonly', () => {\n const reporter = createMemoryLogReporter()\n const err = a.throws(() => { (reporter as any).filter = () => true }, err => /only a getter/.test(err))\n\n assertSSF(err, __filename)\n })\n\n test('log entries are saved in the `logs` property', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['some messages'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.logs).toEqual([entry])\n })\n\n test('can override id', () => {\n const reporter = createMemoryLogReporter({ id: 'custom-id-mem' })\n expect(reporter.id).toBe('custom-id-mem')\n })\n\n test('can filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n const reporter = createMemoryLogReporter({ filter })\n expect(reporter.filter).toBe(filter)\n reporter.write({ id: 'ok', level: 1, args: ['some messages'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: 1, args: ['some messages'], timestamp: new Date() })\n expect(reporter.logs.length).toBe(1)\n })\n\n test('formatter can be used to pre-process the log', () => {\n const formatter: LogFormatter<LogEntry> = (entry) => ({\n ...entry,\n args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)\n })\n const reporter = createMemoryLogReporter({ formatter })\n expect(reporter.formatter).toBe(formatter)\n\n const entry = { id: 'log', level: 1, args: ['a', 'secret', 'b'], timestamp: new Date() }\n reporter.write(entry)\n\n expect(reporter.logs[0].args[1]).toBe('<censored>')\n })\n\n describe(reporter.getLogMessages.name, () => {\n it('maps each log entries to string', () => {\n const r = createMemoryLogReporter()\n r.write(mikuIsSinging)\n r.write(lukaIsDancing)\n expect(r.getLogMessages()).toEqual([\n 'miku is singing',\n 'luka is dancing'\n ])\n })\n })\n\n describe(reporter.getLogMessage.name, () => {\n test('empty logs returns empty string', () => {\n const reporter = createMemoryLogReporter()\n\n expect(reporter.getLogMessage()).toEqual('')\n })\n\n test('print args', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['miku', 'is', 'singing'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual('miku is singing')\n })\n\n test('print object arg', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: [{ 'miku': 'sing' }], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual(\"{ miku: 'sing' }\")\n })\n })\n\n describe(reporter.getLogMessageWithLevel.name, () => {\n test('print with level', () => {\n const reporter = createMemoryLogReporter()\n reporter.write({ id: 'log', level: logLevels.info, args: ['msg 1'], timestamp: new Date() })\n reporter.write({ id: 'log', level: logLevels.warn, args: ['msg 2'], timestamp: new Date() })\n expect(reporter.getLogMessageWithLevel()).toEqual(`(INFO) msg 1\\n(WARN) msg 2`)\n })\n })\n\n describe(reporter.getLogMessagesWithIdAndLevel.name, () => {\n it('does what the name says', () => {\n const r = createMemoryLogReporter()\n r.write(mikuIsSinging)\n r.write(lukaIsDancing)\n expect(r.getLogMessagesWithIdAndLevel()).toEqual([\n 'test-log (INFO) miku is singing',\n 'test-log (WARN) luka is dancing'\n ])\n })\n })\n\n describe(reporter.emit.name, () => {\n it('emit saved logs to console', () => {\n const r = createMemoryLogReporter()\n r.write(mikuIsSinging)\n r.write(lukaIsDancing)\n r.write({ id: 'test-log', level: logLevels.info, args: ['the two messages above are expected'], timestamp: new Date() })\n\n // inspect visually\n r.emit()\n })\n })\n})\n\ndescribe(logEntriesToString.name, () => {\n test('convert log entries to string', () => {\n const timestamp = new Date(2019, 6)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.emergency, args: ['emergency'], timestamp },\n { id: 'log', level: logLevels.critical, args: ['critical'], timestamp },\n { id: 'log', level: logLevels.alert, args: ['alert'], timestamp },\n { id: 'log', level: logLevels.error, args: ['error'], timestamp },\n { id: 'log', level: logLevels.warn, args: ['warn'], timestamp },\n { id: 'log', level: logLevels.notice, args: ['notice'], timestamp },\n { id: 'log', level: logLevels.info, args: ['info'], timestamp },\n { id: 'log', level: logLevels.debug, args: ['debug'], timestamp },\n { id: 'log', level: logLevels.trace, args: ['trace'], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(EMERGENCY),emergency\n${iso},log,(CRITICAL),critical\n${iso},log,(ALERT),alert\n${iso},log,(ERROR),error\n${iso},log,(WARN),warn\n${iso},log,(NOTICE),notice\n${iso},log,(INFO),info\n${iso},log,(DEBUG),debug\n${iso},log,(TRACE),trace`)\n })\n\n test('print out object', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', { a: 1 }], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,{ a: 1 }`)\n })\n\n test('print out array', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', [1, 2, 3]], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,[ 1, 2, 3 ]`)\n })\n})\n"]}
@@ -6340,6 +6340,7 @@ exports.createMemoryLogReporter = exports.toMessageWithLevel = void 0;
6340
6340
  var type_plus_1 = __webpack_require__(/*! type-plus */ "../../node_modules/.pnpm/type-plus@4.13.1/node_modules/type-plus/cjs/index.js");
6341
6341
  var platform_js_1 = __webpack_require__(/*! ./platform.js */ "./ts/platform.browser.ts");
6342
6342
  var formatter_js_1 = __webpack_require__(/*! ./formatter.js */ "./ts/formatter.ts");
6343
+ var console_js_1 = __webpack_require__(/*! ./console.js */ "./ts/console.ts");
6343
6344
  function toMessageWithLevel(logs) {
6344
6345
  return logs.map(platform_js_1.toInspectLogEntry)
6345
6346
  .map(function (log) { return "".concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); })
@@ -6374,7 +6375,14 @@ function createMemoryLogReporter(options) {
6374
6375
  return logs.map(platform_js_1.toInspectLogEntry)
6375
6376
  .map(function (log) { return "".concat(log.id, " ").concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); });
6376
6377
  },
6377
- getLogMessageWithLevel: function () { return toMessageWithLevel(logs); }
6378
+ getLogMessageWithLevel: function () { return toMessageWithLevel(logs); },
6379
+ /**
6380
+ * emit the saved log to console for easy debugging
6381
+ */
6382
+ emit: function () {
6383
+ var reporter = (0, console_js_1.createConsoleLogReporter)();
6384
+ logs.forEach(function (l) { return reporter.write(l); });
6385
+ }
6378
6386
  });
6379
6387
  }
6380
6388
  exports.createMemoryLogReporter = createMemoryLogReporter;
Binary file