standard-log 8.0.0 → 8.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.
- package/cjs/config.js +1 -1
- package/cjs/config.js.map +1 -1
- package/cjs/config.spec.js +6 -0
- package/cjs/config.spec.js.map +1 -1
- package/cjs/console/createConsoleLogReporter.d.ts.map +1 -1
- package/cjs/console/createConsoleLogReporter.js +2 -2
- package/cjs/console/createConsoleLogReporter.js.map +1 -1
- package/cjs/console/createConsoleLogReporter.spec.js +13 -0
- package/cjs/console/createConsoleLogReporter.spec.js.map +1 -1
- package/cjs/errors.d.ts +3 -3
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +6 -6
- package/cjs/errors.js.map +1 -1
- package/cjs/getLogModeFromEnvironment.js +1 -1
- package/cjs/getLogModeFromEnvironment.js.map +1 -1
- package/cjs/getLogModeFromEnvironment.spec.js +6 -0
- package/cjs/getLogModeFromEnvironment.spec.js.map +1 -1
- package/cjs/getLogger.js +1 -1
- package/cjs/getLogger.js.map +1 -1
- package/cjs/getLogger.spec.js +4 -0
- package/cjs/getLogger.spec.js.map +1 -1
- package/cjs/logReporter.js +2 -2
- package/cjs/logReporter.js.map +1 -1
- package/cjs/logReporter.spec.js +12 -0
- package/cjs/logReporter.spec.js.map +1 -1
- package/cjs/memory/MemoryLogReporter.d.ts.map +1 -1
- package/cjs/memory/MemoryLogReporter.js +2 -2
- package/cjs/memory/MemoryLogReporter.js.map +1 -1
- package/cjs/memory/MemoryLogReporter.spec.js +13 -0
- package/cjs/memory/MemoryLogReporter.spec.js.map +1 -1
- package/cjs/testUtil.d.ts +1 -0
- package/cjs/testUtil.d.ts.map +1 -1
- package/cjs/testUtil.js +7 -1
- package/cjs/testUtil.js.map +1 -1
- package/cjs/utils.d.ts +2 -1
- package/cjs/utils.d.ts.map +1 -1
- package/cjs/utils.js +3 -2
- package/cjs/utils.js.map +1 -1
- package/dist/standard-log.es5.js +17 -16
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +17 -16
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/config.js +1 -1
- package/esm/config.js.map +1 -1
- package/esm/config.spec.js +6 -0
- package/esm/config.spec.js.map +1 -1
- package/esm/console/createConsoleLogReporter.d.ts.map +1 -1
- package/esm/console/createConsoleLogReporter.js +2 -2
- package/esm/console/createConsoleLogReporter.js.map +1 -1
- package/esm/console/createConsoleLogReporter.spec.js +13 -0
- package/esm/console/createConsoleLogReporter.spec.js.map +1 -1
- package/esm/errors.d.ts +3 -3
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +6 -6
- package/esm/errors.js.map +1 -1
- package/esm/getLogModeFromEnvironment.js +1 -1
- package/esm/getLogModeFromEnvironment.js.map +1 -1
- package/esm/getLogModeFromEnvironment.spec.js +6 -0
- package/esm/getLogModeFromEnvironment.spec.js.map +1 -1
- package/esm/getLogger.js +1 -1
- package/esm/getLogger.js.map +1 -1
- package/esm/getLogger.spec.js +5 -1
- package/esm/getLogger.spec.js.map +1 -1
- package/esm/logReporter.js +2 -2
- package/esm/logReporter.js.map +1 -1
- package/esm/logReporter.spec.js +12 -0
- package/esm/logReporter.spec.js.map +1 -1
- package/esm/memory/MemoryLogReporter.d.ts.map +1 -1
- package/esm/memory/MemoryLogReporter.js +2 -2
- package/esm/memory/MemoryLogReporter.js.map +1 -1
- package/esm/memory/MemoryLogReporter.spec.js +13 -0
- package/esm/memory/MemoryLogReporter.spec.js.map +1 -1
- package/esm/testUtil.d.ts +1 -0
- package/esm/testUtil.d.ts.map +1 -1
- package/esm/testUtil.js +4 -0
- package/esm/testUtil.js.map +1 -1
- package/esm/utils.d.ts +2 -1
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +3 -2
- package/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/ts/config.ts +1 -1
- package/ts/console/createConsoleLogReporter.ts +8 -2
- package/ts/errors.ts +6 -6
- package/ts/getLogModeFromEnvironment.ts +1 -1
- package/ts/getLogger.ts +1 -1
- package/ts/logReporter.ts +2 -2
- package/ts/memory/MemoryLogReporter.ts +8 -2
- package/ts/utils.ts +4 -2
- package/ts/testUtil.ts +0 -19
package/esm/logReporter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logReporter.js","sourceRoot":"","sources":["../ts/logReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,UAAU,cAAc,CAAC,QAAqB;IAClD,4BAA4B,CAAC,gBAAgB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"logReporter.js","sourceRoot":"","sources":["../ts/logReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,UAAU,cAAc,CAAC,QAAqB;IAClD,4BAA4B,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;IAC9D,sBAAsB,CAAC,QAAQ,CAAC,CAAA;AAClC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,4BAA4B,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;IACpE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["import { addLogReporterInternal } from './logReporterInternal.js'\nimport { store } from './store.js'\nimport { LogReporter } from './types.js'\nimport { assertLogModeIsNotProduction } from './utils.js'\n\nexport function addLogReporter(reporter: LogReporter) {\n assertLogModeIsNotProduction('addLogReporter', addLogReporter)\n addLogReporterInternal(reporter)\n}\n\nexport function getLogReporter(id: string) {\n return store.value.reporters.find(r => r.id === id)\n}\n\nexport function hasConsoleReporter() {\n return store.value.reporters.some(r => r.isConsoleReporter)\n}\n\nexport function getConsoleReporter() {\n return store.value.reporters.find(r => r.isConsoleReporter)\n}\n\nexport function clearLogReporters() {\n assertLogModeIsNotProduction('clearLogReporters', clearLogReporters)\n store.value.reporters.splice(0, store.value.reporters.length)\n}\n"]}
|
package/esm/logReporter.spec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import a from 'assertron';
|
|
2
2
|
import { addLogReporter, clearLogReporters, config, createConsoleLogReporter, createMemoryLogReporter, getConsoleReporter, getLogReporter, hasConsoleReporter, logLevels, ProhibitedDuringProduction } from './index.js';
|
|
3
3
|
import { store } from './store.js';
|
|
4
|
+
import { assertSSF } from './testUtil.js';
|
|
4
5
|
describe('production checks', () => {
|
|
5
6
|
beforeEach(() => store.reset());
|
|
6
7
|
describe('addLogReporter()', () => {
|
|
@@ -9,12 +10,23 @@ describe('production checks', () => {
|
|
|
9
10
|
const reporter = createMemoryLogReporter();
|
|
10
11
|
a.throws(() => addLogReporter(reporter), ProhibitedDuringProduction);
|
|
11
12
|
});
|
|
13
|
+
it('throw with ssf at call site', () => {
|
|
14
|
+
config({ mode: 'production' });
|
|
15
|
+
const reporter = createMemoryLogReporter();
|
|
16
|
+
const err = a.throws(() => addLogReporter(reporter), ProhibitedDuringProduction);
|
|
17
|
+
assertSSF(err, __filename);
|
|
18
|
+
});
|
|
12
19
|
});
|
|
13
20
|
describe('clearLogReporters()', () => {
|
|
14
21
|
test('throws in production mode', () => {
|
|
15
22
|
config({ mode: 'production' });
|
|
16
23
|
a.throws(() => clearLogReporters(), ProhibitedDuringProduction);
|
|
17
24
|
});
|
|
25
|
+
it('throw with ssf at call site', () => {
|
|
26
|
+
config({ mode: 'production' });
|
|
27
|
+
const err = a.throws(() => clearLogReporters(), ProhibitedDuringProduction);
|
|
28
|
+
assertSSF(err, __filename);
|
|
29
|
+
});
|
|
18
30
|
});
|
|
19
31
|
});
|
|
20
32
|
describe('unit tests', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logReporter.spec.js","sourceRoot":"","sources":["../ts/logReporter.spec.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,WAAW,CAAA;AACzB,OAAO,EACL,cAAc,EAAE,iBAAiB,EAAE,MAAM,EACzC,wBAAwB,EAAE,uBAAuB,EACjD,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAC3C,SAAS,EAAE,0BAA0B,EACjD,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"logReporter.spec.js","sourceRoot":"","sources":["../ts/logReporter.spec.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,WAAW,CAAA;AACzB,OAAO,EACL,cAAc,EAAE,iBAAiB,EAAE,MAAM,EACzC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CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import a from 'assertron'\nimport {\n addLogReporter, clearLogReporters, config,\n createConsoleLogReporter, createMemoryLogReporter,\n getConsoleReporter, getLogReporter, hasConsoleReporter,\n LogFilter, logLevels, ProhibitedDuringProduction\n} from './index.js'\nimport { store } from './store.js'\nimport { assertSSF } from './testUtil.js'\n\ndescribe('production checks', () => {\n beforeEach(() => store.reset())\n\n describe('addLogReporter()', () => {\n test('throws in production mode', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n a.throws(() => addLogReporter(reporter), ProhibitedDuringProduction)\n })\n\n it('throw with ssf at call site', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n const err = a.throws(() => addLogReporter(reporter), ProhibitedDuringProduction)\n\n assertSSF(err, __filename)\n })\n })\n\n describe('clearLogReporters()', () => {\n test('throws in production mode', () => {\n config({ mode: 'production' })\n a.throws(() => clearLogReporters(), ProhibitedDuringProduction)\n })\n it('throw with ssf at call site', () => {\n config({ mode: 'production' })\n const err = a.throws(() => clearLogReporters(), ProhibitedDuringProduction)\n\n assertSSF(err, __filename)\n })\n })\n})\n\ndescribe('unit tests', () => {\n beforeEach(() => {\n store.reset()\n config({ mode: 'test' })\n })\n\n describe('addLogReporter()', () => {\n test('adds log reporter', () => {\n const count = store.value.reporters.length\n const reporter = createMemoryLogReporter()\n addLogReporter(reporter)\n\n expect(store.value.reporters.length).toBe(count + 1)\n })\n\n describe('add another console reporter', () => {\n test('will not replace existing one', () => {\n expect(getLogReporter('console')).toBeDefined()\n addLogReporter(createConsoleLogReporter({ id: 'c2' }))\n expect(getLogReporter('c2')).toBeUndefined()\n expect(getLogReporter('console')).toBeDefined()\n })\n\n test('will carry over existing filter', () => {\n const filter: LogFilter = entry => entry.level < logLevels.alert\n addLogReporter(createConsoleLogReporter({ id: 'c2', filter }))\n addLogReporter(createConsoleLogReporter({ id: 'c3' }))\n const c3 = getConsoleReporter()!\n expect(c3.filter).toBe(filter)\n })\n\n test('will combine existing filter and new filter', () => {\n addLogReporter(createConsoleLogReporter({ id: 'c2', filter: entry => entry.level > logLevels.critical }))\n addLogReporter(createConsoleLogReporter({ id: 'c3', filter: entry => entry.level < logLevels.error }))\n const c2 = getConsoleReporter()!\n expect(c2.filter!({ level: logLevels.info } as any)).toBe(false)\n expect(c2.filter!({ level: logLevels.alert } as any)).toBe(false)\n })\n })\n })\n\n describe('getLogReporter()', () => {\n test('get log reporter by id', () => {\n expect(getLogReporter('console')).toBeDefined()\n })\n\n test('get log reporter with unknown id gets undefined', () => {\n expect(getLogReporter('blah')).toBeUndefined()\n })\n })\n\n describe('clearLogReporters()', () => {\n test('removes all reporters', () => {\n clearLogReporters()\n\n expect(store.value.reporters.length).toBe(0)\n })\n })\n\n describe('hasConsoleReporter()', () => {\n test('returns true if there is a console reporter', () => {\n expect(hasConsoleReporter()).toBeTruthy()\n })\n test('returns false if there is no console reporter', () => {\n clearLogReporters()\n expect(hasConsoleReporter()).toBeFalsy()\n addLogReporter(createMemoryLogReporter())\n expect(hasConsoleReporter()).toBeFalsy()\n })\n })\n})\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../ts/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIhG,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"MemoryLogReporter.d.ts","sourceRoot":"","sources":["../../ts/memory/MemoryLogReporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAa,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIhG,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAUvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAkCjG"}
|
|
@@ -28,14 +28,14 @@ export function createMemoryLogReporter(options) {
|
|
|
28
28
|
return formatter;
|
|
29
29
|
},
|
|
30
30
|
set formatter(value) {
|
|
31
|
-
assertLogModeIsNotProduction('set Reporter.formatter');
|
|
31
|
+
assertLogModeIsNotProduction('set Reporter.formatter', Object.getOwnPropertyDescriptor(this, 'formatter').set);
|
|
32
32
|
formatter = value;
|
|
33
33
|
},
|
|
34
34
|
get filter() {
|
|
35
35
|
return filter;
|
|
36
36
|
},
|
|
37
37
|
set filter(value) {
|
|
38
|
-
assertLogModeIsNotProduction('set Reporter.filter');
|
|
38
|
+
assertLogModeIsNotProduction('set Reporter.filter', Object.getOwnPropertyDescriptor(this, 'filter').set);
|
|
39
39
|
filter = value;
|
|
40
40
|
},
|
|
41
41
|
logs: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryLogReporter.js","sourceRoot":"","sources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,CAAC,CAAA;IAC9E,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAA;IAClB,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IAC/B,OAAO;QACL,EAAE;QACF,IAAI,SAAS;YACX,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,IAAI,SAAS,CAAC,KAAyB;YACrC,4BAA4B,CAC1B,wBAAwB,EACxB,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAE,CAAC,GAAI,CACzD,CAAA;YACD,SAAS,GAAG,KAAK,CAAA;QACnB,CAAC;QACD,IAAI,MAAM;YACR,OAAO,MAAM,CAAA;QACf,CAAC;QACD,IAAI,MAAM,CAAC,KAAgB;YACzB,4BAA4B,CAC1B,qBAAqB,EACrB,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,QAAQ,CAAE,CAAC,GAAI,CACtD,CAAA;YACD,MAAM,GAAG,KAAK,CAAA;QAChB,CAAC;QACD,IAAI,EAAE,EAAE;QACR,KAAK,CAAC,KAAK;YACT,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAClC,CAAC;QACD,aAAa,EAAE,mBAAmB,EAAE;QACpC,sBAAsB,KAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAClE,CAAA;AACH,CAAC","sourcesContent":["import { required } from 'type-plus'\nimport { formatLogLevel } from '../formatter/index.js'\nimport { LogEntry, LogFilter, LogFormatter, LogReporter, LogReporterOptions } from '../types.js'\nimport { assertLogModeIsNotProduction } from '../utils.js'\nimport { toInspectLogEntry } from './toInspectStringForObject.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 getLogMessageWithLevel(): string\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nfunction createGetLogMessage() {\n return function getLogMessage(this: { logs: LogEntry[] }) {\n return this.logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n .join('\\n')\n }\n}\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\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n const opt = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const { id } = opt\n let { formatter, filter } = opt\n return {\n id,\n get formatter() {\n return formatter\n },\n set formatter(value: MemoryLogFormatter) {\n assertLogModeIsNotProduction(\n 'set Reporter.formatter',\n Object.getOwnPropertyDescriptor(this, 'formatter')!.set!\n )\n formatter = value\n },\n get filter() {\n return filter\n },\n set filter(value: LogFilter) {\n assertLogModeIsNotProduction(\n 'set Reporter.filter',\n Object.getOwnPropertyDescriptor(this, 'filter')!.set!\n )\n filter = value\n },\n logs: [],\n write(entry) {\n if (filter && !filter(entry)) return\n this.logs.push(formatter(entry))\n },\n getLogMessage: createGetLogMessage(),\n getLogMessageWithLevel() { return toMessageWithLevel(this.logs) }\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { config, createMemoryLogReporter, logLevels, ProhibitedDuringProduction
|
|
|
3
3
|
import { configForTest } from '../configForTest.js';
|
|
4
4
|
import { getLogger } from '../getLogger.js';
|
|
5
5
|
import { store } from '../store.js';
|
|
6
|
+
import { assertSSF } from '../testUtil.js';
|
|
6
7
|
describe('production checks', () => {
|
|
7
8
|
beforeEach(() => store.reset());
|
|
8
9
|
test('set formatter in production mode throws', () => {
|
|
@@ -10,11 +11,23 @@ describe('production checks', () => {
|
|
|
10
11
|
const reporter = createMemoryLogReporter();
|
|
11
12
|
a.throws(() => { reporter.formatter = e => e; }, ProhibitedDuringProduction);
|
|
12
13
|
});
|
|
14
|
+
it('set formatter throws with ssf at call site', () => {
|
|
15
|
+
config({ mode: 'production' });
|
|
16
|
+
const reporter = createMemoryLogReporter();
|
|
17
|
+
const err = a.throws(() => { reporter.formatter = e => e; }, ProhibitedDuringProduction);
|
|
18
|
+
assertSSF(err, __filename);
|
|
19
|
+
});
|
|
13
20
|
test('set filter in production mode throws', () => {
|
|
14
21
|
config({ mode: 'production' });
|
|
15
22
|
const reporter = createMemoryLogReporter();
|
|
16
23
|
a.throws(() => { reporter.filter = () => true; }, ProhibitedDuringProduction);
|
|
17
24
|
});
|
|
25
|
+
it('set filter throws with ssf at call site', () => {
|
|
26
|
+
config({ mode: 'production' });
|
|
27
|
+
const reporter = createMemoryLogReporter();
|
|
28
|
+
const err = a.throws(() => { reporter.filter = () => true; }, ProhibitedDuringProduction);
|
|
29
|
+
assertSSF(err, __filename);
|
|
30
|
+
});
|
|
18
31
|
describe('getLogMessageWithLevel()', () => {
|
|
19
32
|
test('the production log is omitted', () => {
|
|
20
33
|
const { reporter } = configForTest();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryLogReporter.spec.js","sourceRoot":"","sources":["../../ts/memory/MemoryLogReporter.spec.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,WAAW,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,UAAU,CAAC,GAAG,EAA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,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;YACxF,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACrB,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE;YAC5B,MAAM,QAAQ,GAAG,uBAAuB,EAAE,CAAA;YAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC5F,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC5F,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAA;QACjF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import a from 'assertron'\nimport { config, createMemoryLogReporter, logLevels, ProhibitedDuringProduction } from '../index.js'\nimport { configForTest } from '../configForTest.js'\nimport { getLogger } from '../getLogger.js'\nimport { store } from '../store.js'\n\ndescribe('production checks', () => {\n beforeEach(() => store.reset())\n test('set formatter in production mode throws', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n\n a.throws(() => { reporter.formatter = e => e }, ProhibitedDuringProduction)\n })\n\n test('set filter in production mode throws', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n a.throws(() => { reporter.filter = () => true }, ProhibitedDuringProduction)\n })\n\n describe('getLogMessageWithLevel()', () => {\n test('the production log is omitted', () => {\n const { reporter } = configForTest()\n config({ mode: 'production' })\n getLogger('test').warn('some test warnings')\n expect(reporter.getLogMessageWithLevel()).toEqual(`(WARN) some test warnings`)\n })\n })\n})\n\ndescribe('unit tests', () => {\n beforeEach(() => {\n store.reset()\n config({ mode: 'test' })\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 reporter = createMemoryLogReporter({ filter(entry) { return entry.id !== 'secret' } })\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('can change filter', () => {\n const reporter = createMemoryLogReporter()\n const filter = reporter.filter\n reporter.filter = entry => entry.id !== 'secret'\n expect(reporter.filter).not.toEqual(filter)\n })\n\n test('formatter can be used to pre-process the log', () => {\n const reporter = createMemoryLogReporter({\n formatter: (entry) => ({\n ...entry,\n args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)\n })\n })\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 test('can change formatter', () => {\n const reporter = createMemoryLogReporter()\n const formatter = reporter.formatter\n reporter.formatter = e => ({ ...e, args: e.args.reverse() })\n expect(reporter.formatter).not.toEqual(formatter)\n })\n\n describe('getLogMessages()', () => {\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('getLogMessageWithLevel', () => {\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"]}
|
|
1
|
+
{"version":3,"file":"MemoryLogReporter.spec.js","sourceRoot":"","sources":["../../ts/memory/MemoryLogReporter.spec.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,WAAW,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;IAC/B,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACnD,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EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC5F,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC5F,MAAM,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAA;QACjF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import a from 'assertron'\nimport { config, createMemoryLogReporter, logLevels, ProhibitedDuringProduction } from '../index.js'\nimport { configForTest } from '../configForTest.js'\nimport { getLogger } from '../getLogger.js'\nimport { store } from '../store.js'\nimport { assertSSF } from '../testUtil.js'\n\ndescribe('production checks', () => {\n beforeEach(() => store.reset())\n test('set formatter in production mode throws', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n\n a.throws(() => { reporter.formatter = e => e }, ProhibitedDuringProduction)\n })\n it('set formatter throws with ssf at call site', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n\n const err = a.throws(() => { reporter.formatter = e => e }, ProhibitedDuringProduction)\n\n assertSSF(err, __filename)\n })\n\n test('set filter in production mode throws', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n a.throws(() => { reporter.filter = () => true }, ProhibitedDuringProduction)\n })\n\n it('set filter throws with ssf at call site', () => {\n config({ mode: 'production' })\n const reporter = createMemoryLogReporter()\n const err = a.throws(() => { reporter.filter = () => true }, ProhibitedDuringProduction)\n\n assertSSF(err, __filename)\n })\n\n describe('getLogMessageWithLevel()', () => {\n test('the production log is omitted', () => {\n const { reporter } = configForTest()\n config({ mode: 'production' })\n getLogger('test').warn('some test warnings')\n expect(reporter.getLogMessageWithLevel()).toEqual(`(WARN) some test warnings`)\n })\n })\n})\n\ndescribe('unit tests', () => {\n beforeEach(() => {\n store.reset()\n config({ mode: 'test' })\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 reporter = createMemoryLogReporter({ filter(entry) { return entry.id !== 'secret' } })\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('can change filter', () => {\n const reporter = createMemoryLogReporter()\n const filter = reporter.filter\n reporter.filter = entry => entry.id !== 'secret'\n expect(reporter.filter).not.toEqual(filter)\n })\n\n test('formatter can be used to pre-process the log', () => {\n const reporter = createMemoryLogReporter({\n formatter: (entry) => ({\n ...entry,\n args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)\n })\n })\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 test('can change formatter', () => {\n const reporter = createMemoryLogReporter()\n const formatter = reporter.formatter\n reporter.formatter = e => ({ ...e, args: e.args.reverse() })\n expect(reporter.formatter).not.toEqual(formatter)\n })\n\n describe('getLogMessages()', () => {\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('getLogMessageWithLevel', () => {\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"]}
|
package/esm/testUtil.d.ts
CHANGED
package/esm/testUtil.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtil.d.ts","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,WAErE;AAED,wBAAgB,iBAAiB;;;EAUhC"}
|
|
1
|
+
{"version":3,"file":"testUtil.d.ts","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,WAErE;AAED,wBAAgB,iBAAiB;;;EAUhC;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAGrD"}
|
package/esm/testUtil.js
CHANGED
package/esm/testUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,OAAO,CAAA;AAErB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAW,EAAE,QAAa;IACpE,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,CAAA;IAChC,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACvC,OAAO;QACL,IAAI;QACJ,KAAK;YACH,gBAAgB,CAAC,EAAE,GAAG,IAAI,CAAA;QAC5B,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import R from 'ramda'\nimport { LogEntry } from './types.js'\nimport { writeToReporters } from './writeToReporters.js'\n\nexport function rangeEntries(start: number, end: number, expected: any) {\n return R.range(start, end).map(value => ([value, expected]))\n}\n\nexport function captureWrittenLog() {\n const logs: LogEntry[] = []\n const orig = writeToReporters.fn\n writeToReporters.fn = l => logs.push(l)\n return {\n logs,\n reset() {\n writeToReporters.fn = orig\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,OAAO,CAAA;AAErB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAW,EAAE,QAAa;IACpE,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,CAAA;IAChC,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACvC,OAAO;QACL,IAAI;QACJ,KAAK;YACH,gBAAgB,CAAC,EAAE,GAAG,IAAI,CAAA;QAC5B,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAU,EAAE,QAAgB;IACpD,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["import R from 'ramda'\nimport { LogEntry } from './types.js'\nimport { writeToReporters } from './writeToReporters.js'\n\nexport function rangeEntries(start: number, end: number, expected: any) {\n return R.range(start, end).map(value => ([value, expected]))\n}\n\nexport function captureWrittenLog() {\n const logs: LogEntry[] = []\n const orig = writeToReporters.fn\n writeToReporters.fn = l => logs.push(l)\n return {\n logs,\n reset() {\n writeToReporters.fn = orig\n }\n }\n}\n\nexport function assertSSF(err: Error, filename: string) {\n const firstStackTrace = err.stack?.split('\\n')[1]\n expect(firstStackTrace).toMatch(filename)\n}\n"]}
|
package/esm/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AnyFunction } from 'type-plus';
|
|
1
2
|
/**
|
|
2
3
|
* Helper function to assert the system is not in production mode.
|
|
3
4
|
*/
|
|
4
|
-
export declare function assertLogModeIsNotProduction(action: string): void;
|
|
5
|
+
export declare function assertLogModeIsNotProduction(action: string, ssf: AnyFunction): void;
|
|
5
6
|
//# sourceMappingURL=utils.d.ts.map
|
package/esm/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../ts/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../ts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAIvC;;GAEG;AAEH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,QAE5E"}
|
package/esm/utils.js
CHANGED
|
@@ -3,8 +3,9 @@ import { store } from './store.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Helper function to assert the system is not in production mode.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
7
|
+
export function assertLogModeIsNotProduction(action, ssf) {
|
|
7
8
|
if (store.value.mode === 'production')
|
|
8
|
-
throw new ProhibitedDuringProduction(action);
|
|
9
|
+
throw new ProhibitedDuringProduction(action, { ssf });
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../ts/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../ts/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC;;GAEG;AACH,wDAAwD;AACxD,MAAM,UAAU,4BAA4B,CAAC,MAAc,EAAE,GAAgB;IAC3E,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY;QAAE,MAAM,IAAI,0BAA0B,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;AAC9F,CAAC","sourcesContent":["import { AnyFunction } from 'type-plus'\nimport { ProhibitedDuringProduction } from './errors.js'\nimport { store } from './store.js'\n\n/**\n * Helper function to assert the system is not in production mode.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function assertLogModeIsNotProduction(action: string, ssf: AnyFunction) {\n if (store.value.mode === 'production') throw new ProhibitedDuringProduction(action, { ssf })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "standard-log",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "The standard log library",
|
|
5
5
|
"homepage": "https://github.com/unional/standard-log/tree/master/packages/log",
|
|
6
6
|
"bugs": {
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"dist",
|
|
37
37
|
"esm",
|
|
38
38
|
"ts",
|
|
39
|
-
"!ts/**/*.spec.ts"
|
|
39
|
+
"!ts/**/*.spec.ts",
|
|
40
|
+
"!ts/testUtil.ts"
|
|
40
41
|
],
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "npm-run-all build:clean -p build:cjs build:esm build:tslib bundle:es5 bundle:esm",
|
package/ts/config.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ConfigOptions = {
|
|
|
16
16
|
export const config: { (options?: Partial<ConfigOptions>): void, readonly isLocked: boolean } = function config(options: Partial<ConfigOptions> = {}) {
|
|
17
17
|
if (store.value.configured) {
|
|
18
18
|
if (store.value.mode === 'production') {
|
|
19
|
-
throw new ProhibitedDuringProduction('config')
|
|
19
|
+
throw new ProhibitedDuringProduction('config', { ssf: config })
|
|
20
20
|
}
|
|
21
21
|
if (store.value.mode === 'test' && options.mode !== 'test') {
|
|
22
22
|
const log = getLogger('standard-log')
|
|
@@ -21,14 +21,20 @@ export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): C
|
|
|
21
21
|
return formatter
|
|
22
22
|
},
|
|
23
23
|
set formatter(value: ConsoleLogFormatter) {
|
|
24
|
-
assertLogModeIsNotProduction(
|
|
24
|
+
assertLogModeIsNotProduction(
|
|
25
|
+
'set Reporter.formatter',
|
|
26
|
+
Object.getOwnPropertyDescriptor(this, 'formatter')!.set!
|
|
27
|
+
)
|
|
25
28
|
formatter = value
|
|
26
29
|
},
|
|
27
30
|
get filter() {
|
|
28
31
|
return filter
|
|
29
32
|
},
|
|
30
33
|
set filter(value: LogFilter) {
|
|
31
|
-
assertLogModeIsNotProduction(
|
|
34
|
+
assertLogModeIsNotProduction(
|
|
35
|
+
'set Reporter.filter',
|
|
36
|
+
Object.getOwnPropertyDescriptor(this, 'filter')!.set!
|
|
37
|
+
)
|
|
32
38
|
filter = value
|
|
33
39
|
},
|
|
34
40
|
console: polyfilledConsole,
|
package/ts/errors.ts
CHANGED
|
@@ -6,19 +6,19 @@ export class StandardLogError extends ModuleError {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
export class InvalidId extends StandardLogError {
|
|
9
|
-
constructor(public id: string) {
|
|
10
|
-
super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}
|
|
9
|
+
constructor(public id: string, options?: IsoError.Options) {
|
|
10
|
+
super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class ProhibitedDuringProduction extends StandardLogError {
|
|
15
|
-
constructor(public action: string) {
|
|
16
|
-
super(`Cannot perform ${action} during production
|
|
15
|
+
constructor(public action: string, options?: IsoError.Options) {
|
|
16
|
+
super(`Cannot perform ${action} during production`, options)
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class InvalidEnvVar extends StandardLogError {
|
|
21
|
-
constructor(public name: string, public value: string, public possibleValues: string[]) {
|
|
22
|
-
super(`${name} contains invalid value '${value}'${` valid values: [${possibleValues.join()}]`}
|
|
21
|
+
constructor(public name: string, public value: string, public possibleValues: string[], options?: IsoError.Options) {
|
|
22
|
+
super(`${name} contains invalid value '${value}'${` valid values: [${possibleValues.join()}]`}`, options)
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -8,7 +8,7 @@ export function getLogModeFromEnvironment(): LogMode | undefined {
|
|
|
8
8
|
if (mode === undefined || isLogMode(mode)) {
|
|
9
9
|
return mode as LogMode
|
|
10
10
|
}
|
|
11
|
-
throw new InvalidEnvVar('STANDARD_LOG', mode, logModeValues)
|
|
11
|
+
throw new InvalidEnvVar('STANDARD_LOG', mode, logModeValues, { ssf: getLogModeFromEnvironment })
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function isLogMode(mode: string): mode is LogMode {
|
package/ts/getLogger.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function getLogger<T extends string = LogMethodNames>(
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function validateId(id: string) {
|
|
29
|
-
if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id)) throw new InvalidId(id)
|
|
29
|
+
if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id)) throw new InvalidId(id, { ssf: getLogger })
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function createLoggerClosure<T extends string>(id: string, { level, writeTo = () => true }: getLogger.Options = {}): LoggerClosure<T> {
|
package/ts/logReporter.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { LogReporter } from './types.js'
|
|
|
4
4
|
import { assertLogModeIsNotProduction } from './utils.js'
|
|
5
5
|
|
|
6
6
|
export function addLogReporter(reporter: LogReporter) {
|
|
7
|
-
assertLogModeIsNotProduction('addLogReporter')
|
|
7
|
+
assertLogModeIsNotProduction('addLogReporter', addLogReporter)
|
|
8
8
|
addLogReporterInternal(reporter)
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -21,6 +21,6 @@ export function getConsoleReporter() {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function clearLogReporters() {
|
|
24
|
-
assertLogModeIsNotProduction('clearLogReporters')
|
|
24
|
+
assertLogModeIsNotProduction('clearLogReporters', clearLogReporters)
|
|
25
25
|
store.value.reporters.splice(0, store.value.reporters.length)
|
|
26
26
|
}
|
|
@@ -45,14 +45,20 @@ export function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>):
|
|
|
45
45
|
return formatter
|
|
46
46
|
},
|
|
47
47
|
set formatter(value: MemoryLogFormatter) {
|
|
48
|
-
assertLogModeIsNotProduction(
|
|
48
|
+
assertLogModeIsNotProduction(
|
|
49
|
+
'set Reporter.formatter',
|
|
50
|
+
Object.getOwnPropertyDescriptor(this, 'formatter')!.set!
|
|
51
|
+
)
|
|
49
52
|
formatter = value
|
|
50
53
|
},
|
|
51
54
|
get filter() {
|
|
52
55
|
return filter
|
|
53
56
|
},
|
|
54
57
|
set filter(value: LogFilter) {
|
|
55
|
-
assertLogModeIsNotProduction(
|
|
58
|
+
assertLogModeIsNotProduction(
|
|
59
|
+
'set Reporter.filter',
|
|
60
|
+
Object.getOwnPropertyDescriptor(this, 'filter')!.set!
|
|
61
|
+
)
|
|
56
62
|
filter = value
|
|
57
63
|
},
|
|
58
64
|
logs: [],
|
package/ts/utils.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { AnyFunction } from 'type-plus'
|
|
1
2
|
import { ProhibitedDuringProduction } from './errors.js'
|
|
2
3
|
import { store } from './store.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Helper function to assert the system is not in production mode.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
9
|
+
export function assertLogModeIsNotProduction(action: string, ssf: AnyFunction) {
|
|
10
|
+
if (store.value.mode === 'production') throw new ProhibitedDuringProduction(action, { ssf })
|
|
9
11
|
}
|
package/ts/testUtil.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import R from 'ramda'
|
|
2
|
-
import { LogEntry } from './types.js'
|
|
3
|
-
import { writeToReporters } from './writeToReporters.js'
|
|
4
|
-
|
|
5
|
-
export function rangeEntries(start: number, end: number, expected: any) {
|
|
6
|
-
return R.range(start, end).map(value => ([value, expected]))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function captureWrittenLog() {
|
|
10
|
-
const logs: LogEntry[] = []
|
|
11
|
-
const orig = writeToReporters.fn
|
|
12
|
-
writeToReporters.fn = l => logs.push(l)
|
|
13
|
-
return {
|
|
14
|
-
logs,
|
|
15
|
-
reset() {
|
|
16
|
-
writeToReporters.fn = orig
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|