standard-log 7.1.0 → 9.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/LICENSE +1 -1
- package/README.md +57 -133
- package/{libm/console/createConsoleLogReporter.d.ts → cjs/console.d.ts} +5 -5
- package/cjs/console.d.ts.map +1 -0
- package/cjs/console.js +76 -0
- package/cjs/console.js.map +1 -0
- package/cjs/console.spec.d.ts +2 -0
- package/cjs/console.spec.d.ts.map +1 -0
- package/cjs/console.spec.js +177 -0
- package/cjs/console.spec.js.map +1 -0
- package/cjs/errors.d.ts +9 -0
- package/cjs/errors.d.ts.map +1 -0
- package/cjs/errors.js +43 -0
- package/cjs/errors.js.map +1 -0
- package/cjs/formatter.d.ts +6 -0
- package/cjs/formatter.d.ts.map +1 -0
- package/cjs/formatter.js +46 -0
- package/cjs/formatter.js.map +1 -0
- package/cjs/formatter.spec.d.ts +2 -0
- package/cjs/formatter.spec.d.ts.map +1 -0
- package/cjs/formatter.spec.js +32 -0
- package/cjs/formatter.spec.js.map +1 -0
- package/cjs/index.d.ts +8 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +24 -0
- package/cjs/index.js.map +1 -0
- package/cjs/logLevels.d.ts +60 -0
- package/cjs/logLevels.d.ts.map +1 -0
- package/cjs/logLevels.js +87 -0
- package/cjs/logLevels.js.map +1 -0
- package/cjs/logStore.d.ts +20 -0
- package/cjs/logStore.d.ts.map +1 -0
- package/cjs/logStore.js +44 -0
- package/cjs/logStore.js.map +1 -0
- package/cjs/logStore.spec.d.ts +2 -0
- package/cjs/logStore.spec.d.ts.map +1 -0
- package/cjs/logStore.spec.js +93 -0
- package/cjs/logStore.spec.js.map +1 -0
- package/cjs/logger.d.ts +6 -0
- package/cjs/logger.d.ts.map +1 -0
- package/cjs/logger.js +97 -0
- package/cjs/logger.js.map +1 -0
- package/{lib/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
- package/cjs/memory.d.ts.map +1 -0
- package/cjs/memory.js +39 -0
- package/cjs/memory.js.map +1 -0
- package/cjs/memory.spec.d.ts +2 -0
- package/cjs/memory.spec.d.ts.map +1 -0
- package/cjs/memory.spec.js +115 -0
- package/cjs/memory.spec.js.map +1 -0
- package/cjs/package.json +1 -0
- package/cjs/platform.browser.d.ts +7 -0
- package/cjs/platform.browser.d.ts.map +1 -0
- package/cjs/platform.browser.js +11 -0
- package/cjs/platform.browser.js.map +1 -0
- package/cjs/platform.d.ts +8 -0
- package/cjs/platform.d.ts.map +1 -0
- package/cjs/platform.js +26 -0
- package/cjs/platform.js.map +1 -0
- package/cjs/platform.spec.d.ts +2 -0
- package/cjs/platform.spec.d.ts.map +1 -0
- package/cjs/platform.spec.js +22 -0
- package/cjs/platform.spec.js.map +1 -0
- package/cjs/standardLog.d.ts +21 -0
- package/cjs/standardLog.d.ts.map +1 -0
- package/cjs/standardLog.js +59 -0
- package/cjs/standardLog.js.map +1 -0
- package/cjs/standardLog.spec.d.ts +2 -0
- package/cjs/standardLog.spec.d.ts.map +1 -0
- package/cjs/standardLog.spec.js +536 -0
- package/cjs/standardLog.spec.js.map +1 -0
- package/cjs/testUtil.d.ts +10 -0
- package/cjs/testUtil.d.ts.map +1 -0
- package/cjs/testUtil.js +28 -0
- package/cjs/testUtil.js.map +1 -0
- package/{lib → cjs}/types.d.ts +33 -24
- package/cjs/types.d.ts.map +1 -0
- package/{lib/console → cjs}/types.js +0 -0
- package/cjs/types.js.map +1 -0
- package/cjs/types.spec.d.ts +2 -0
- package/cjs/types.spec.d.ts.map +1 -0
- package/cjs/types.spec.js +7 -0
- package/cjs/types.spec.js.map +1 -0
- package/dist/standard-log.es5.js +1971 -0
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -0
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +1887 -0
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -0
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/{lib/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
- package/esm/console.d.ts.map +1 -0
- package/{libm/console/polyfilledConsole.js → esm/console.js} +36 -4
- package/esm/console.js.map +1 -0
- package/esm/console.spec.d.ts +2 -0
- package/esm/console.spec.d.ts.map +1 -0
- package/esm/console.spec.js +151 -0
- package/esm/console.spec.js.map +1 -0
- package/esm/errors.d.ts +9 -0
- package/esm/errors.d.ts.map +1 -0
- package/esm/errors.js +18 -0
- package/esm/errors.js.map +1 -0
- package/esm/formatter.d.ts +6 -0
- package/esm/formatter.d.ts.map +1 -0
- package/{libm/formatter/createTimestampFormatter.js → esm/formatter.js} +10 -2
- package/esm/formatter.js.map +1 -0
- package/esm/formatter.spec.d.ts +2 -0
- package/esm/formatter.spec.d.ts.map +1 -0
- package/esm/formatter.spec.js +30 -0
- package/esm/formatter.spec.js.map +1 -0
- package/esm/index.d.ts +8 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +8 -0
- package/esm/index.js.map +1 -0
- package/esm/logLevels.d.ts +60 -0
- package/esm/logLevels.d.ts.map +1 -0
- package/{libm/logLevel.js → esm/logLevels.js} +29 -3
- package/esm/logLevels.js.map +1 -0
- package/esm/logStore.d.ts +20 -0
- package/esm/logStore.d.ts.map +1 -0
- package/esm/logStore.js +37 -0
- package/esm/logStore.js.map +1 -0
- package/esm/logStore.spec.d.ts +2 -0
- package/esm/logStore.spec.d.ts.map +1 -0
- package/esm/logStore.spec.js +93 -0
- package/esm/logStore.spec.js.map +1 -0
- package/esm/logger.d.ts +6 -0
- package/esm/logger.d.ts.map +1 -0
- package/esm/logger.js +74 -0
- package/esm/logger.js.map +1 -0
- package/{libm/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
- package/esm/memory.d.ts.map +1 -0
- package/esm/memory.js +34 -0
- package/esm/memory.js.map +1 -0
- package/esm/memory.spec.d.ts +2 -0
- package/esm/memory.spec.d.ts.map +1 -0
- package/esm/memory.spec.js +110 -0
- package/esm/memory.spec.js.map +1 -0
- package/esm/platform.browser.d.ts +7 -0
- package/esm/platform.browser.d.ts.map +1 -0
- package/esm/platform.browser.js +6 -0
- package/esm/platform.browser.js.map +1 -0
- package/esm/platform.d.ts +8 -0
- package/esm/platform.d.ts.map +1 -0
- package/esm/platform.js +20 -0
- package/esm/platform.js.map +1 -0
- package/esm/platform.spec.d.ts +2 -0
- package/esm/platform.spec.d.ts.map +1 -0
- package/esm/platform.spec.js +20 -0
- package/esm/platform.spec.js.map +1 -0
- package/esm/standardLog.d.ts +21 -0
- package/esm/standardLog.d.ts.map +1 -0
- package/esm/standardLog.js +36 -0
- package/esm/standardLog.js.map +1 -0
- package/esm/standardLog.spec.d.ts +2 -0
- package/esm/standardLog.spec.d.ts.map +1 -0
- package/esm/standardLog.spec.js +434 -0
- package/esm/standardLog.spec.js.map +1 -0
- package/esm/testUtil.d.ts +10 -0
- package/esm/testUtil.d.ts.map +1 -0
- package/esm/testUtil.js +17 -0
- package/esm/testUtil.js.map +1 -0
- package/{libm → esm}/types.d.ts +33 -24
- package/esm/types.d.ts.map +1 -0
- package/{libm/console → esm}/types.js +0 -0
- package/esm/types.js.map +1 -0
- package/esm/types.spec.d.ts +2 -0
- package/esm/types.spec.d.ts.map +1 -0
- package/esm/types.spec.js +5 -0
- package/esm/types.spec.js.map +1 -0
- package/package.json +72 -31
- package/ts/console.ts +72 -0
- package/ts/errors.ts +12 -0
- package/{src/formatter/createTimestampFormatter.ts → ts/formatter.ts} +13 -2
- package/ts/index.ts +7 -0
- package/{src/logLevel.ts → ts/logLevels.ts} +20 -3
- package/ts/logStore.ts +52 -0
- package/ts/logger.ts +85 -0
- package/ts/memory.ts +47 -0
- package/ts/platform.browser.ts +8 -0
- package/ts/platform.ts +25 -0
- package/ts/standardLog.ts +54 -0
- package/{src → ts}/types.ts +39 -30
- package/dist/standard-log.js +0 -5472
- package/dist/standard-log.js.gz +0 -0
- package/dist/standard-log.js.map +0 -1
- package/dist/standard-log.js.map.gz +0 -0
- package/lib/LogEntry.d.ts +0 -7
- package/lib/LogEntry.d.ts.map +0 -1
- package/lib/LogEntry.js +0 -3
- package/lib/LogEntry.js.map +0 -1
- package/lib/captureLogs.d.ts +0 -4
- package/lib/captureLogs.d.ts.map +0 -1
- package/lib/captureLogs.js +0 -33
- package/lib/captureLogs.js.map +0 -1
- package/lib/config.d.ts +0 -12
- package/lib/config.d.ts.map +0 -1
- package/lib/config.js +0 -49
- package/lib/config.js.map +0 -1
- package/lib/configForTest.d.ts +0 -5
- package/lib/configForTest.d.ts.map +0 -1
- package/lib/configForTest.js +0 -18
- package/lib/configForTest.js.map +0 -1
- package/lib/console/createConsoleLogReporter.d.ts.map +0 -1
- package/lib/console/createConsoleLogReporter.js +0 -42
- package/lib/console/createConsoleLogReporter.js.map +0 -1
- package/lib/console/index.d.ts +0 -4
- package/lib/console/index.d.ts.map +0 -1
- package/lib/console/index.js +0 -7
- package/lib/console/index.js.map +0 -1
- package/lib/console/isConsoleDebugAvailable.d.ts +0 -2
- package/lib/console/isConsoleDebugAvailable.d.ts.map +0 -1
- package/lib/console/isConsoleDebugAvailable.js +0 -18
- package/lib/console/isConsoleDebugAvailable.js.map +0 -1
- package/lib/console/polyfilledConsole.d.ts +0 -7
- package/lib/console/polyfilledConsole.d.ts.map +0 -1
- package/lib/console/polyfilledConsole.js +0 -41
- package/lib/console/polyfilledConsole.js.map +0 -1
- package/lib/console/semverGt.d.ts +0 -2
- package/lib/console/semverGt.d.ts.map +0 -1
- package/lib/console/semverGt.js +0 -13
- package/lib/console/semverGt.js.map +0 -1
- package/lib/console/toConsoleMethod.d.ts +0 -2
- package/lib/console/toConsoleMethod.d.ts.map +0 -1
- package/lib/console/toConsoleMethod.js +0 -22
- package/lib/console/toConsoleMethod.js.map +0 -1
- package/lib/console/types.d.ts +0 -3
- package/lib/console/types.d.ts.map +0 -1
- package/lib/console/types.js.map +0 -1
- package/lib/customLogLevel.d.ts +0 -11
- package/lib/customLogLevel.d.ts.map +0 -1
- package/lib/customLogLevel.js +0 -38
- package/lib/customLogLevel.js.map +0 -1
- package/lib/errors.d.ts +0 -19
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js +0 -46
- package/lib/errors.js.map +0 -1
- package/lib/formatter/createTimestampFormatter.d.ts +0 -3
- package/lib/formatter/createTimestampFormatter.d.ts.map +0 -1
- package/lib/formatter/createTimestampFormatter.js +0 -24
- package/lib/formatter/createTimestampFormatter.js.map +0 -1
- package/lib/formatter/formatLogLevel.d.ts +0 -2
- package/lib/formatter/formatLogLevel.d.ts.map +0 -1
- package/lib/formatter/formatLogLevel.js +0 -10
- package/lib/formatter/formatLogLevel.js.map +0 -1
- package/lib/formatter/index.d.ts +0 -4
- package/lib/formatter/index.d.ts.map +0 -1
- package/lib/formatter/index.js +0 -7
- package/lib/formatter/index.js.map +0 -1
- package/lib/formatter/plainLogFormatter.d.ts +0 -3
- package/lib/formatter/plainLogFormatter.d.ts.map +0 -1
- package/lib/formatter/plainLogFormatter.js +0 -11
- package/lib/formatter/plainLogFormatter.js.map +0 -1
- package/lib/getDefaultReporter.browser.d.ts +0 -2
- package/lib/getDefaultReporter.browser.d.ts.map +0 -1
- package/lib/getDefaultReporter.browser.js +0 -15
- package/lib/getDefaultReporter.browser.js.map +0 -1
- package/lib/getDefaultReporter.d.ts +0 -2
- package/lib/getDefaultReporter.d.ts.map +0 -1
- package/lib/getDefaultReporter.js +0 -19
- package/lib/getDefaultReporter.js.map +0 -1
- package/lib/getLogModeFromEnvironment.browser.d.ts +0 -3
- package/lib/getLogModeFromEnvironment.browser.d.ts.map +0 -1
- package/lib/getLogModeFromEnvironment.browser.js +0 -9
- package/lib/getLogModeFromEnvironment.browser.js.map +0 -1
- package/lib/getLogModeFromEnvironment.d.ts +0 -3
- package/lib/getLogModeFromEnvironment.d.ts.map +0 -1
- package/lib/getLogModeFromEnvironment.js +0 -17
- package/lib/getLogModeFromEnvironment.js.map +0 -1
- package/lib/getLogger.d.ts +0 -9
- package/lib/getLogger.d.ts.map +0 -1
- package/lib/getLogger.js +0 -95
- package/lib/getLogger.js.map +0 -1
- package/lib/getLoggers.d.ts +0 -7
- package/lib/getLoggers.d.ts.map +0 -1
- package/lib/getLoggers.js +0 -15
- package/lib/getLoggers.js.map +0 -1
- package/lib/index.d.ts +0 -17
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -20
- package/lib/index.js.map +0 -1
- package/lib/logLevel.d.ts +0 -106
- package/lib/logLevel.d.ts.map +0 -1
- package/lib/logLevel.js +0 -59
- package/lib/logLevel.js.map +0 -1
- package/lib/logLevelFn.d.ts +0 -20
- package/lib/logLevelFn.d.ts.map +0 -1
- package/lib/logLevelFn.js +0 -76
- package/lib/logLevelFn.js.map +0 -1
- package/lib/logReporter.d.ts +0 -7
- package/lib/logReporter.d.ts.map +0 -1
- package/lib/logReporter.js +0 -29
- package/lib/logReporter.js.map +0 -1
- package/lib/logReporterInternal.d.ts +0 -3
- package/lib/logReporterInternal.d.ts.map +0 -1
- package/lib/logReporterInternal.js +0 -23
- package/lib/logReporterInternal.js.map +0 -1
- package/lib/memory/MemoryLogReporter.d.ts.map +0 -1
- package/lib/memory/MemoryLogReporter.js +0 -56
- package/lib/memory/MemoryLogReporter.js.map +0 -1
- package/lib/memory/index.d.ts +0 -3
- package/lib/memory/index.d.ts.map +0 -1
- package/lib/memory/index.js +0 -6
- package/lib/memory/index.js.map +0 -1
- package/lib/memory/logEntriesToString.d.ts +0 -3
- package/lib/memory/logEntriesToString.d.ts.map +0 -1
- package/lib/memory/logEntriesToString.js +0 -10
- package/lib/memory/logEntriesToString.js.map +0 -1
- package/lib/memory/toInspectStringForObject.d.ts +0 -3
- package/lib/memory/toInspectStringForObject.d.ts.map +0 -1
- package/lib/memory/toInspectStringForObject.js +0 -15
- package/lib/memory/toInspectStringForObject.js.map +0 -1
- package/lib/shouldLog.d.ts +0 -8
- package/lib/shouldLog.d.ts.map +0 -1
- package/lib/shouldLog.js +0 -14
- package/lib/shouldLog.js.map +0 -1
- package/lib/store.d.ts +0 -3
- package/lib/store.d.ts.map +0 -1
- package/lib/store.js +0 -17
- package/lib/store.js.map +0 -1
- package/lib/suppressLogs.d.ts +0 -6
- package/lib/suppressLogs.d.ts.map +0 -1
- package/lib/suppressLogs.js +0 -17
- package/lib/suppressLogs.js.map +0 -1
- package/lib/testUtil.d.ts +0 -7
- package/lib/testUtil.d.ts.map +0 -1
- package/lib/testUtil.js +0 -23
- package/lib/testUtil.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/typesInternal.d.ts +0 -20
- package/lib/typesInternal.d.ts.map +0 -1
- package/lib/typesInternal.js +0 -3
- package/lib/typesInternal.js.map +0 -1
- package/lib/utils.d.ts +0 -5
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -14
- package/lib/utils.js.map +0 -1
- package/lib/writeToReporters.d.ts +0 -6
- package/lib/writeToReporters.d.ts.map +0 -1
- package/lib/writeToReporters.js +0 -22
- package/lib/writeToReporters.js.map +0 -1
- package/libm/LogEntry.d.ts +0 -7
- package/libm/LogEntry.d.ts.map +0 -1
- package/libm/LogEntry.js +0 -2
- package/libm/LogEntry.js.map +0 -1
- package/libm/captureLogs.d.ts +0 -4
- package/libm/captureLogs.d.ts.map +0 -1
- package/libm/captureLogs.js +0 -29
- package/libm/captureLogs.js.map +0 -1
- package/libm/config.d.ts +0 -12
- package/libm/config.d.ts.map +0 -1
- package/libm/config.js +0 -44
- package/libm/config.js.map +0 -1
- package/libm/configForTest.d.ts +0 -5
- package/libm/configForTest.d.ts.map +0 -1
- package/libm/configForTest.js +0 -14
- package/libm/configForTest.js.map +0 -1
- package/libm/console/createConsoleLogReporter.d.ts.map +0 -1
- package/libm/console/createConsoleLogReporter.js +0 -37
- package/libm/console/createConsoleLogReporter.js.map +0 -1
- package/libm/console/index.d.ts +0 -4
- package/libm/console/index.d.ts.map +0 -1
- package/libm/console/index.js +0 -4
- package/libm/console/index.js.map +0 -1
- package/libm/console/isConsoleDebugAvailable.d.ts +0 -2
- package/libm/console/isConsoleDebugAvailable.d.ts.map +0 -1
- package/libm/console/isConsoleDebugAvailable.js +0 -13
- package/libm/console/isConsoleDebugAvailable.js.map +0 -1
- package/libm/console/polyfilledConsole.d.ts +0 -7
- package/libm/console/polyfilledConsole.d.ts.map +0 -1
- package/libm/console/polyfilledConsole.js.map +0 -1
- package/libm/console/semverGt.d.ts +0 -2
- package/libm/console/semverGt.d.ts.map +0 -1
- package/libm/console/semverGt.js +0 -9
- package/libm/console/semverGt.js.map +0 -1
- package/libm/console/toConsoleMethod.d.ts +0 -2
- package/libm/console/toConsoleMethod.d.ts.map +0 -1
- package/libm/console/toConsoleMethod.js +0 -18
- package/libm/console/toConsoleMethod.js.map +0 -1
- package/libm/console/types.d.ts +0 -3
- package/libm/console/types.d.ts.map +0 -1
- package/libm/console/types.js.map +0 -1
- package/libm/customLogLevel.d.ts +0 -11
- package/libm/customLogLevel.d.ts.map +0 -1
- package/libm/customLogLevel.js +0 -30
- package/libm/customLogLevel.js.map +0 -1
- package/libm/errors.d.ts +0 -19
- package/libm/errors.d.ts.map +0 -1
- package/libm/errors.js +0 -32
- package/libm/errors.js.map +0 -1
- package/libm/formatter/createTimestampFormatter.d.ts +0 -3
- package/libm/formatter/createTimestampFormatter.d.ts.map +0 -1
- package/libm/formatter/createTimestampFormatter.js.map +0 -1
- package/libm/formatter/formatLogLevel.d.ts +0 -2
- package/libm/formatter/formatLogLevel.d.ts.map +0 -1
- package/libm/formatter/formatLogLevel.js +0 -6
- package/libm/formatter/formatLogLevel.js.map +0 -1
- package/libm/formatter/index.d.ts +0 -4
- package/libm/formatter/index.d.ts.map +0 -1
- package/libm/formatter/index.js +0 -4
- package/libm/formatter/index.js.map +0 -1
- package/libm/formatter/plainLogFormatter.d.ts +0 -3
- package/libm/formatter/plainLogFormatter.d.ts.map +0 -1
- package/libm/formatter/plainLogFormatter.js +0 -5
- package/libm/formatter/plainLogFormatter.js.map +0 -1
- package/libm/getDefaultReporter.browser.d.ts +0 -2
- package/libm/getDefaultReporter.browser.d.ts.map +0 -1
- package/libm/getDefaultReporter.browser.js +0 -11
- package/libm/getDefaultReporter.browser.js.map +0 -1
- package/libm/getDefaultReporter.d.ts +0 -2
- package/libm/getDefaultReporter.d.ts.map +0 -1
- package/libm/getDefaultReporter.js +0 -15
- package/libm/getDefaultReporter.js.map +0 -1
- package/libm/getLogModeFromEnvironment.browser.d.ts +0 -3
- package/libm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
- package/libm/getLogModeFromEnvironment.browser.js +0 -5
- package/libm/getLogModeFromEnvironment.browser.js.map +0 -1
- package/libm/getLogModeFromEnvironment.d.ts +0 -3
- package/libm/getLogModeFromEnvironment.d.ts.map +0 -1
- package/libm/getLogModeFromEnvironment.js +0 -13
- package/libm/getLogModeFromEnvironment.js.map +0 -1
- package/libm/getLogger.d.ts +0 -9
- package/libm/getLogger.d.ts.map +0 -1
- package/libm/getLogger.js +0 -78
- package/libm/getLogger.js.map +0 -1
- package/libm/getLoggers.d.ts +0 -7
- package/libm/getLoggers.d.ts.map +0 -1
- package/libm/getLoggers.js +0 -11
- package/libm/getLoggers.js.map +0 -1
- package/libm/index.d.ts +0 -17
- package/libm/index.d.ts.map +0 -1
- package/libm/index.js +0 -17
- package/libm/index.js.map +0 -1
- package/libm/logLevel.d.ts +0 -106
- package/libm/logLevel.d.ts.map +0 -1
- package/libm/logLevel.js.map +0 -1
- package/libm/logLevelFn.d.ts +0 -20
- package/libm/logLevelFn.d.ts.map +0 -1
- package/libm/logLevelFn.js +0 -67
- package/libm/logLevelFn.js.map +0 -1
- package/libm/logReporter.d.ts +0 -7
- package/libm/logReporter.d.ts.map +0 -1
- package/libm/logReporter.js +0 -21
- package/libm/logReporter.js.map +0 -1
- package/libm/logReporterInternal.d.ts +0 -3
- package/libm/logReporterInternal.d.ts.map +0 -1
- package/libm/logReporterInternal.js +0 -19
- package/libm/logReporterInternal.js.map +0 -1
- package/libm/memory/MemoryLogReporter.d.ts.map +0 -1
- package/libm/memory/MemoryLogReporter.js +0 -51
- package/libm/memory/MemoryLogReporter.js.map +0 -1
- package/libm/memory/index.d.ts +0 -3
- package/libm/memory/index.d.ts.map +0 -1
- package/libm/memory/index.js +0 -3
- package/libm/memory/index.js.map +0 -1
- package/libm/memory/logEntriesToString.d.ts +0 -3
- package/libm/memory/logEntriesToString.d.ts.map +0 -1
- package/libm/memory/logEntriesToString.js +0 -6
- package/libm/memory/logEntriesToString.js.map +0 -1
- package/libm/memory/toInspectStringForObject.d.ts +0 -3
- package/libm/memory/toInspectStringForObject.d.ts.map +0 -1
- package/libm/memory/toInspectStringForObject.js +0 -11
- package/libm/memory/toInspectStringForObject.js.map +0 -1
- package/libm/shouldLog.d.ts +0 -8
- package/libm/shouldLog.d.ts.map +0 -1
- package/libm/shouldLog.js +0 -10
- package/libm/shouldLog.js.map +0 -1
- package/libm/store.d.ts +0 -3
- package/libm/store.d.ts.map +0 -1
- package/libm/store.js +0 -24
- package/libm/store.js.map +0 -1
- package/libm/suppressLogs.d.ts +0 -6
- package/libm/suppressLogs.d.ts.map +0 -1
- package/libm/suppressLogs.js +0 -9
- package/libm/suppressLogs.js.map +0 -1
- package/libm/testUtil.d.ts +0 -7
- package/libm/testUtil.d.ts.map +0 -1
- package/libm/testUtil.js +0 -17
- package/libm/testUtil.js.map +0 -1
- package/libm/types.d.ts.map +0 -1
- package/libm/types.js +0 -2
- package/libm/types.js.map +0 -1
- package/libm/typesInternal.d.ts +0 -20
- package/libm/typesInternal.d.ts.map +0 -1
- package/libm/typesInternal.js +0 -2
- package/libm/typesInternal.js.map +0 -1
- package/libm/utils.d.ts +0 -5
- package/libm/utils.d.ts.map +0 -1
- package/libm/utils.js +0 -10
- package/libm/utils.js.map +0 -1
- package/libm/writeToReporters.d.ts +0 -6
- package/libm/writeToReporters.d.ts.map +0 -1
- package/libm/writeToReporters.js +0 -18
- package/libm/writeToReporters.js.map +0 -1
- package/src/LogEntry.ts +0 -7
- package/src/captureLogs.spec.ts +0 -52
- package/src/captureLogs.ts +0 -35
- package/src/config.spec.ts +0 -80
- package/src/config.ts +0 -57
- package/src/configForTest.spec.ts +0 -16
- package/src/configForTest.ts +0 -16
- package/src/console/createConsoleLogReporter.spec.ts +0 -198
- package/src/console/createConsoleLogReporter.ts +0 -42
- package/src/console/index.ts +0 -3
- package/src/console/isConsoleDebugAvailable.ts +0 -11
- package/src/console/polyfilledConsole.ts +0 -34
- package/src/console/semverGt.spec.ts +0 -25
- package/src/console/semverGt.ts +0 -9
- package/src/console/toConsoleMethod.ts +0 -18
- package/src/console/types.ts +0 -3
- package/src/customLogLevel.spec.ts +0 -39
- package/src/customLogLevel.ts +0 -35
- package/src/errors.ts +0 -24
- package/src/formatter/createTimestampFormatter.spec.ts +0 -24
- package/src/formatter/formatLogLevel.ts +0 -6
- package/src/formatter/index.ts +0 -3
- package/src/formatter/plainLogFormatter.spec.ts +0 -8
- package/src/formatter/plainLogFormatter.ts +0 -6
- package/src/getDefaultReporter.browser.ts +0 -13
- package/src/getDefaultReporter.ts +0 -15
- package/src/getLogModeFromEnvironment.browser.ts +0 -6
- package/src/getLogModeFromEnvironment.spec.ts +0 -16
- package/src/getLogModeFromEnvironment.ts +0 -16
- package/src/getLogger.spec.ts +0 -460
- package/src/getLogger.ts +0 -92
- package/src/getLoggers.ts +0 -12
- package/src/index.ts +0 -16
- package/src/logLevel.spec.ts +0 -161
- package/src/logLevelFn.ts +0 -72
- package/src/logReporter.spec.ts +0 -99
- package/src/logReporter.ts +0 -26
- package/src/logReporterInternal.ts +0 -18
- package/src/memory/MemoryLogReporter.spec.ts +0 -114
- package/src/memory/MemoryLogReporter.ts +0 -66
- package/src/memory/index.ts +0 -2
- package/src/memory/logEntriesToString.spec.ts +0 -47
- package/src/memory/logEntriesToString.ts +0 -7
- package/src/memory/toInspectStringForObject.ts +0 -13
- package/src/shouldLog.ts +0 -11
- package/src/store.ts +0 -25
- package/src/suppressLogs.spec.ts +0 -34
- package/src/suppressLogs.ts +0 -14
- package/src/testUtil.ts +0 -19
- package/src/types.spec.ts +0 -7
- package/src/typesInternal.ts +0 -21
- package/src/utils.ts +0 -9
- package/src/writeToReporters.spec.ts +0 -9
- package/src/writeToReporters.ts +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.browser.js","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAA;AACnD,MAAM,UAAU,uBAAuB;IACrC,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => e\nexport function isConsoleDebugAvailable() {\n return true\n}\n\nexport const polyfill: { console?: ConsoleLike } = {}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConsoleLike, LogEntry } from './types.js';
|
|
2
|
+
export declare function semverGt(versionString: string, version: [number, number, number]): boolean;
|
|
3
|
+
export declare function isConsoleDebugAvailable(): boolean;
|
|
4
|
+
export declare const toInspectLogEntry: (e: LogEntry) => LogEntry;
|
|
5
|
+
export declare const polyfill: {
|
|
6
|
+
console?: ConsoleLike;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,WAOhF;AAGD,wBAAgB,uBAAuB,YAKtC;AAED,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAEzC,CAAA;AAEJ,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAO,CAAA"}
|
package/esm/platform.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { inspect } from 'util';
|
|
2
|
+
export function semverGt(versionString, version) {
|
|
3
|
+
const actual = versionString.split('.').reverse().reduce((p, v, i) => {
|
|
4
|
+
p += Number.parseInt(v, 10) * Math.pow(100, i);
|
|
5
|
+
return p;
|
|
6
|
+
}, 0);
|
|
7
|
+
return actual > (version[0] * 10000 + version[1] * 100 + version[2]);
|
|
8
|
+
}
|
|
9
|
+
// istanbul ignore next
|
|
10
|
+
export function isConsoleDebugAvailable() {
|
|
11
|
+
// without this, systemJs will complain `process is not defined`
|
|
12
|
+
if (!global.process)
|
|
13
|
+
return true;
|
|
14
|
+
const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version;
|
|
15
|
+
return semverGt(versionString, [9, 3, 0]);
|
|
16
|
+
}
|
|
17
|
+
export const toInspectLogEntry = (e) => (e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
|
|
18
|
+
e);
|
|
19
|
+
export const polyfill = {};
|
|
20
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9B,MAAM,UAAU,QAAQ,CAAC,aAAqB,EAAE,OAAiC;IAC/E,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;QACnE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,CAAC,CAAC,CAAA;IAEL,OAAO,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AACtE,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,uBAAuB;IACrC,gEAAgE;IAChE,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAChC,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA;IAClG,OAAO,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClG,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport function semverGt(versionString: string, version: [number, number, number]) {\n const actual = versionString.split('.').reverse().reduce((p, v, i) => {\n p += Number.parseInt(v, 10) * Math.pow(100, i)\n return p\n }, 0)\n\n return actual > (version[0] * 10000 + version[1] * 100 + version[2])\n}\n\n// istanbul ignore next\nexport function isConsoleDebugAvailable() {\n // without this, systemJs will complain `process is not defined`\n if (!global.process) return true\n const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version\n return semverGt(versionString, [9, 3, 0])\n}\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),\n e)\n\nexport const polyfill: { console?: ConsoleLike } = {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.spec.d.ts","sourceRoot":"","sources":["../ts/platform.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { semverGt } from './platform.js';
|
|
2
|
+
test('9.3.0 returns false', () => {
|
|
3
|
+
expect(semverGt('9.3.0', [9, 3, 0])).toBe(false);
|
|
4
|
+
});
|
|
5
|
+
test('9.3.1 returns true', () => {
|
|
6
|
+
expect(semverGt('9.3.1', [9, 3, 0])).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
test('9.3.1 returns true', () => {
|
|
9
|
+
expect(semverGt('9.3.1', [9, 3, 0])).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
test('9.4.0 returns true', () => {
|
|
12
|
+
expect(semverGt('9.4.0', [9, 3, 0])).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
test('9.10.0 returns true', () => {
|
|
15
|
+
expect(semverGt('9.10.0', [9, 3, 0])).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
test('10.0.0 returns true', () => {
|
|
18
|
+
expect(semverGt('10.0.0', [9, 3, 0])).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=platform.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.spec.js","sourceRoot":"","sources":["../ts/platform.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA","sourcesContent":["import { semverGt } from './platform.js'\n\ntest('9.3.0 returns false', () => {\n expect(semverGt('9.3.0', [9, 3, 0])).toBe(false)\n})\n\ntest('9.3.1 returns true', () => {\n expect(semverGt('9.3.1', [9, 3, 0])).toBe(true)\n})\n\ntest('9.3.1 returns true', () => {\n expect(semverGt('9.3.1', [9, 3, 0])).toBe(true)\n})\n\ntest('9.4.0 returns true', () => {\n expect(semverGt('9.4.0', [9, 3, 0])).toBe(true)\n})\n\ntest('9.10.0 returns true', () => {\n expect(semverGt('9.10.0', [9, 3, 0])).toBe(true)\n})\n\ntest('10.0.0 returns true', () => {\n expect(semverGt('10.0.0', [9, 3, 0])).toBe(true)\n})\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StackTraceMeta } from '@just-func/types';
|
|
2
|
+
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js';
|
|
3
|
+
export interface StandardLog<N extends string = LogMethodNames> {
|
|
4
|
+
readonly logLevel: number;
|
|
5
|
+
toLogLevelName(level: number): string;
|
|
6
|
+
toLogLevel(name: N): number;
|
|
7
|
+
getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createStandardLog<N extends string = LogMethodNames>(options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta): Readonly<StandardLog<N>>;
|
|
10
|
+
export declare function createStandardLogForTest(logLevel?: LogLevel): {
|
|
11
|
+
reporter: import("./memory.js").MemoryLogReporter;
|
|
12
|
+
logLevel: number;
|
|
13
|
+
toLogLevelName: (level: number) => string;
|
|
14
|
+
toLogLevel: (name: LogMethodNames) => number;
|
|
15
|
+
getLogger: (params: [id: string, options?: LoggerOptions | undefined], meta?: StackTraceMeta | undefined) => Logger<LogMethodNames>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Suppress logging within the code block.
|
|
19
|
+
*/
|
|
20
|
+
export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R;
|
|
21
|
+
//# sourceMappingURL=standardLog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAMjD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAErG,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IAC5B,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;CAC3F;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACjE,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,cAAc,GAC/D,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAkB1B;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,QAA0B;;;;;;EAI5E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { required } from 'type-plus';
|
|
2
|
+
import { createLogger } from './logger.js';
|
|
3
|
+
import { logLevels } from './logLevels.js';
|
|
4
|
+
import { createLogStore } from './logStore.js';
|
|
5
|
+
import { createMemoryLogReporter } from './memory.js';
|
|
6
|
+
export function createStandardLog(options, _meta) {
|
|
7
|
+
const store = createLogStore(required({ logLevel: logLevels.info }, options));
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
get logLevel() { return store.logLevel; },
|
|
10
|
+
toLogLevelName(level) {
|
|
11
|
+
return store.logLevelStore.getName(level);
|
|
12
|
+
},
|
|
13
|
+
toLogLevel(name) {
|
|
14
|
+
return store.logLevelStore.getLevel(name);
|
|
15
|
+
},
|
|
16
|
+
getLogger([id, options], meta) {
|
|
17
|
+
if (store.loggers[id])
|
|
18
|
+
return store.loggers[id];
|
|
19
|
+
const opt = required({ level: store.logLevel }, options);
|
|
20
|
+
return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function createStandardLogForTest(logLevel = logLevels.debug) {
|
|
25
|
+
const reporter = createMemoryLogReporter();
|
|
26
|
+
const standardLog = createStandardLog({ reporters: [reporter], logLevel });
|
|
27
|
+
return { ...standardLog, reporter };
|
|
28
|
+
}
|
|
29
|
+
export function suppressLogs(block, ...logs) {
|
|
30
|
+
const origLevels = logs.map(l => l.level);
|
|
31
|
+
logs.forEach(l => l.level = logLevels.none);
|
|
32
|
+
const result = block();
|
|
33
|
+
logs.forEach((l, i) => l.level = origLevels[i]);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=standardLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAUrD,MAAM,UAAU,iBAAiB,CAC/B,OAAwC,EAAE,KAAsB;IAEhE,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7E,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,CAAA,CAAC,CAAC;QAExC,cAAc,CAAC,KAAa;YAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3C,CAAC;QACD,UAAU,CAAC,IAAY;YACrB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC3C,CAAC;QACD,SAAS,CAAC,CAAC,EAAE,EAAE,OAAO,CAAwC,EAAE,IAAqB;YACnF,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBAAE,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAQ,CAAA;YACtD,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAA;YACxD,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,EAAE,CAAQ,CAAA;QACpG,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,WAAqB,SAAS,CAAC,KAAK;IAC3E,MAAM,QAAQ,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1E,OAAO,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,CAAA;AACrC,CAAC;AAMD,MAAM,UAAU,YAAY,CAAI,KAAc,EAAE,GAAG,IAAc;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,MAAM,GAAG,KAAK,EAAE,CAAA;IACtB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { StackTraceMeta } from '@just-func/types'\nimport { required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { logLevels } from './logLevels.js'\nimport { createLogStore } from './logStore.js'\nimport { createMemoryLogReporter } from './memory.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> {\n readonly logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N>\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta\n): Readonly<StandardLog<N>> {\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n\n return Object.freeze({\n get logLevel() { return store.logLevel },\n\n toLogLevelName(level: number) {\n return store.logLevelStore.getName(level)\n },\n toLogLevel(name: string) {\n return store.logLevelStore.getLevel(name)\n },\n getLogger([id, options]: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N> {\n if (store.loggers[id]) return store.loggers[id] as any\n const opt = required({ level: store.logLevel }, options)\n return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta }) as any\n }\n })\n}\n\nexport function createStandardLogForTest(logLevel: LogLevel = logLevels.debug) {\n const reporter = createMemoryLogReporter()\n const standardLog = createStandardLog({ reporters: [reporter], logLevel })\n return { ...standardLog, reporter }\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n const origLevels = logs.map(l => l.level)\n logs.forEach(l => l.level = logLevels.none)\n const result = block()\n logs.forEach((l, i) => l.level = origLevels[i])\n return result\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardLog.spec.d.ts","sourceRoot":"","sources":["../ts/standardLog.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { assertron as a } from 'assertron';
|
|
2
|
+
import { InvalidId } from './errors.js';
|
|
3
|
+
import { logLevels, toLogLevelName } from './logLevels.js';
|
|
4
|
+
import { createMemoryLogReporter } from './memory.js';
|
|
5
|
+
import { createStandardLog, createStandardLogForTest, suppressLogs } from './standardLog.js';
|
|
6
|
+
import { assertSSF, wrapTest } from './testUtil.js';
|
|
7
|
+
describe('createStandardLog()', () => {
|
|
8
|
+
describe('logLevel', () => {
|
|
9
|
+
it('is default to info', () => {
|
|
10
|
+
const actual = createStandardLog();
|
|
11
|
+
expect(actual.logLevel).toBe(logLevels.info);
|
|
12
|
+
});
|
|
13
|
+
it('is readonly', () => {
|
|
14
|
+
const actual = createStandardLog();
|
|
15
|
+
a.throws(() => actual.logLevel = logLevels.planck, err => /only a getter/.test(err));
|
|
16
|
+
});
|
|
17
|
+
it('set logLevel from options', () => {
|
|
18
|
+
const actual = createStandardLog({ logLevel: logLevels.planck });
|
|
19
|
+
expect(actual.logLevel).toBe(logLevels.planck);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('custom levels', () => {
|
|
23
|
+
it('can define custom levels', () => {
|
|
24
|
+
const actual = createStandardLog({ customLevels: { urgent: 80 } });
|
|
25
|
+
expect(actual.toLogLevelName(80)).toBe('urgent');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe('reporters', () => {
|
|
29
|
+
it('can specify reporter', () => {
|
|
30
|
+
const mem = createMemoryLogReporter();
|
|
31
|
+
const sl = createStandardLog({ reporters: [mem] });
|
|
32
|
+
const log = sl.getLogger(['x']);
|
|
33
|
+
log.info('abc');
|
|
34
|
+
expect(mem.logs.length).toBe(1);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('createStandardLogForTest()', () => {
|
|
39
|
+
it('returns with memory reporter', () => {
|
|
40
|
+
const { reporter } = createStandardLogForTest();
|
|
41
|
+
expect(reporter.getLogMessageWithLevel()).toBe('');
|
|
42
|
+
});
|
|
43
|
+
it('defaults to debug', () => {
|
|
44
|
+
const store = createStandardLogForTest();
|
|
45
|
+
expect(store.logLevel).toBe(logLevels.debug);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe('getLogger()', () => {
|
|
49
|
+
it('supports id with alphanumeric and :_-.', () => {
|
|
50
|
+
const sl = createStandardLog();
|
|
51
|
+
sl.getLogger(['abcdefghijklmnopqrstuvwxyz:-_.1234567890']);
|
|
52
|
+
});
|
|
53
|
+
it('supports id with unicode', () => {
|
|
54
|
+
const sl = createStandardLog();
|
|
55
|
+
sl.getLogger(['ミク香港']);
|
|
56
|
+
});
|
|
57
|
+
it('supports id with @, \\ and /', () => {
|
|
58
|
+
const sl = createStandardLog();
|
|
59
|
+
sl.getLogger(['@unional/fixture']);
|
|
60
|
+
sl.getLogger([`a\\b\\c`]);
|
|
61
|
+
});
|
|
62
|
+
it.each('`~!#$%^&*()=+|[]{}<>,?'.split(''))('throws if id has unsupported character %s', (char) => {
|
|
63
|
+
const sl = createStandardLog();
|
|
64
|
+
a.throws(() => sl.getLogger([char]), InvalidId);
|
|
65
|
+
});
|
|
66
|
+
it('throw InvalidId with ssf to the call site', () => {
|
|
67
|
+
const sl = createStandardLog();
|
|
68
|
+
const err = a.throws(() => sl.getLogger(['!']), InvalidId);
|
|
69
|
+
assertSSF(err, __filename);
|
|
70
|
+
});
|
|
71
|
+
test('id is readonly', () => {
|
|
72
|
+
const sl = createStandardLog();
|
|
73
|
+
const log = sl.getLogger(['id is readonly']);
|
|
74
|
+
a.throws(() => log.id = 'b');
|
|
75
|
+
});
|
|
76
|
+
test('get logger with same name gets the same instance', () => {
|
|
77
|
+
const sl = createStandardLog();
|
|
78
|
+
const expected = sl.getLogger(['same-inst']);
|
|
79
|
+
const actual = sl.getLogger(['same-inst']);
|
|
80
|
+
expect(actual).toBe(expected);
|
|
81
|
+
});
|
|
82
|
+
it('can specify local log level', () => {
|
|
83
|
+
const sl = createStandardLog();
|
|
84
|
+
const log = sl.getLogger(['local', { level: logLevels.trace }]);
|
|
85
|
+
expect(log.level).toBe(logLevels.trace);
|
|
86
|
+
});
|
|
87
|
+
test('new logger will get custom level', () => {
|
|
88
|
+
const sl = createStandardLog({ customLevels: { 'to_logger': 1234 } });
|
|
89
|
+
const actual = sl.getLogger(['to_logger_logger']);
|
|
90
|
+
expect(typeof actual.to_logger).toBe('function');
|
|
91
|
+
});
|
|
92
|
+
describe('log levels', () => {
|
|
93
|
+
async function assertLoggedAtLevel(sl, method, level) {
|
|
94
|
+
const log = sl.getLogger([method]);
|
|
95
|
+
const msg = `should log on level: ${level}`;
|
|
96
|
+
log[method](msg);
|
|
97
|
+
a.satisfies(sl.reporter.logs, [{ id: method, level: sl.toLogLevel(method), args: [msg] }]);
|
|
98
|
+
}
|
|
99
|
+
async function assertNotLoggedAtLevel(sl, method, level) {
|
|
100
|
+
const log = sl.getLogger([method]);
|
|
101
|
+
log[method](`should not log on level: ${level}`);
|
|
102
|
+
expect(sl.reporter.logs.length).toBe(0);
|
|
103
|
+
}
|
|
104
|
+
async function assertLoggedAtLocalLevel(sl, method, localLevel) {
|
|
105
|
+
const log = sl.getLogger([method, { level: localLevel }]);
|
|
106
|
+
const msg = `should log on level: ${localLevel}`;
|
|
107
|
+
log[method](msg);
|
|
108
|
+
a.satisfies(sl.reporter.logs, [{ id: log.id, level: sl.toLogLevel(method), args: [msg] }]);
|
|
109
|
+
}
|
|
110
|
+
async function assertNotLoggedAtLocalLevel(sl, method, localLevel) {
|
|
111
|
+
const log = sl.getLogger([method, { level: localLevel }]);
|
|
112
|
+
log[method](`should not log on level: ${localLevel}`);
|
|
113
|
+
expect(sl.reporter.logs.length).toBe(0);
|
|
114
|
+
}
|
|
115
|
+
async function assertLoggedAtCallLevel(sl, method, callLevel) {
|
|
116
|
+
const log = sl.getLogger([method]);
|
|
117
|
+
let actual = false;
|
|
118
|
+
log.on(callLevel, () => actual = true);
|
|
119
|
+
expect(actual).toBe(true);
|
|
120
|
+
}
|
|
121
|
+
async function assertNotLoggedAtCallLevel(sl, method, callLevel, actualLevel) {
|
|
122
|
+
const log = sl.getLogger([method]);
|
|
123
|
+
log.on(callLevel, () => { throw new Error(`should not log at level ${actualLevel}`); });
|
|
124
|
+
}
|
|
125
|
+
async function assertLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel) {
|
|
126
|
+
const log = sl.getLogger([method, { level: localLevel }]);
|
|
127
|
+
let actual = false;
|
|
128
|
+
log.on(callLevel, () => actual = true);
|
|
129
|
+
expect(actual).toBe(true);
|
|
130
|
+
}
|
|
131
|
+
async function assertNotLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel) {
|
|
132
|
+
const log = sl.getLogger([method, { level: localLevel }]);
|
|
133
|
+
log.on(callLevel, () => { throw new Error(`should not log at level ${localLevel}`); });
|
|
134
|
+
}
|
|
135
|
+
const shouldLog = wrapTest((test) => (method, level) => {
|
|
136
|
+
const sl = createStandardLogForTest(level);
|
|
137
|
+
const name = sl.toLogLevelName(level);
|
|
138
|
+
test(`${method}() should log on level: ${name} (${level})`, () => {
|
|
139
|
+
return assertLoggedAtLevel(sl, method, level);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
const shouldNotLog = wrapTest((test) => (method, level) => {
|
|
143
|
+
const sl = createStandardLogForTest(level);
|
|
144
|
+
const name = sl.toLogLevelName(level);
|
|
145
|
+
test(`${method}() should not log on level: ${name} (${level})`, () => {
|
|
146
|
+
return assertNotLoggedAtLevel(sl, method, level);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
const shouldLogWithLocalLevelOverride = wrapTest((test) => (method, localLevel) => {
|
|
150
|
+
const localName = toLogLevelName(localLevel);
|
|
151
|
+
[logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
|
|
152
|
+
const globalName = toLogLevelName(globalLevel) || 'none';
|
|
153
|
+
test(`${method}() should log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
|
|
154
|
+
const sl = createStandardLogForTest(globalLevel);
|
|
155
|
+
return assertLoggedAtLocalLevel(sl, method, localLevel);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
const shouldNotLogWithLocalLevelOverride = wrapTest((test) => (method, localLevel) => {
|
|
160
|
+
const localName = toLogLevelName(localLevel);
|
|
161
|
+
[logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
|
|
162
|
+
const globalName = toLogLevelName(globalLevel) || 'none';
|
|
163
|
+
test(`${method}() should not log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
|
|
164
|
+
const sl = createStandardLogForTest(globalLevel);
|
|
165
|
+
return assertNotLoggedAtLocalLevel(sl, method, localLevel);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
const shouldCallLogFunction = wrapTest((test) => (callLevel, actualLevel) => {
|
|
170
|
+
const method = toLogLevelName(callLevel);
|
|
171
|
+
const name = toLogLevelName(actualLevel);
|
|
172
|
+
test(`${method}() should call log function on level: ${name} (${actualLevel})`, () => {
|
|
173
|
+
const sl = createStandardLogForTest(actualLevel);
|
|
174
|
+
return assertLoggedAtCallLevel(sl, method, callLevel);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
const shouldNotCallLogFunction = wrapTest((test) => (callLevel, actualLevel) => {
|
|
178
|
+
const method = toLogLevelName(callLevel);
|
|
179
|
+
const name = toLogLevelName(actualLevel);
|
|
180
|
+
test(`${method}() should not call log function on level: ${name} (${actualLevel})`, () => {
|
|
181
|
+
const sl = createStandardLogForTest(actualLevel);
|
|
182
|
+
return assertNotLoggedAtCallLevel(sl, method, callLevel, actualLevel);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
const shouldCallLogFunctionWithLocalLevelOverride = wrapTest((test) => (callLevel, localLevel) => {
|
|
186
|
+
const method = toLogLevelName(callLevel);
|
|
187
|
+
const localName = toLogLevelName(localLevel);
|
|
188
|
+
[logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
|
|
189
|
+
const globalName = toLogLevelName(globalLevel) || 'none';
|
|
190
|
+
test(`${method}() should log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
|
|
191
|
+
const sl = createStandardLogForTest(globalLevel);
|
|
192
|
+
return assertLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
const shouldNotCallLogFunctionWithLocalLevelOverride = wrapTest((test) => (callLevel, localLevel) => {
|
|
197
|
+
const method = toLogLevelName(callLevel);
|
|
198
|
+
const localName = toLogLevelName(localLevel);
|
|
199
|
+
[logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
|
|
200
|
+
const globalName = toLogLevelName(globalLevel) || 'none';
|
|
201
|
+
test(`${method}() should not log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
|
|
202
|
+
const sl = createStandardLogForTest(globalLevel);
|
|
203
|
+
return assertNotLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
shouldNotLog('error', logLevels.none);
|
|
208
|
+
shouldLog('error', logLevels.error);
|
|
209
|
+
shouldLog('error', logLevels.warn);
|
|
210
|
+
shouldLog('error', logLevels.info);
|
|
211
|
+
shouldLog('error', logLevels.debug);
|
|
212
|
+
shouldNotLogWithLocalLevelOverride('error', logLevels.none);
|
|
213
|
+
shouldLogWithLocalLevelOverride('error', logLevels.error);
|
|
214
|
+
shouldLogWithLocalLevelOverride('error', logLevels.warn);
|
|
215
|
+
shouldLogWithLocalLevelOverride('error', logLevels.info);
|
|
216
|
+
shouldLogWithLocalLevelOverride('error', logLevels.debug);
|
|
217
|
+
shouldNotLog('warn', logLevels.none);
|
|
218
|
+
shouldNotLog('warn', logLevels.error);
|
|
219
|
+
shouldLog('warn', logLevels.warn);
|
|
220
|
+
shouldLog('warn', logLevels.info);
|
|
221
|
+
shouldLog('warn', logLevels.debug);
|
|
222
|
+
shouldNotLogWithLocalLevelOverride('warn', logLevels.none);
|
|
223
|
+
shouldNotLogWithLocalLevelOverride('warn', logLevels.error);
|
|
224
|
+
shouldLogWithLocalLevelOverride('warn', logLevels.warn);
|
|
225
|
+
shouldLogWithLocalLevelOverride('warn', logLevels.info);
|
|
226
|
+
shouldLogWithLocalLevelOverride('warn', logLevels.debug);
|
|
227
|
+
shouldNotLog('info', logLevels.none);
|
|
228
|
+
shouldNotLog('info', logLevels.error);
|
|
229
|
+
shouldNotLog('info', logLevels.warn);
|
|
230
|
+
shouldLog('info', logLevels.info);
|
|
231
|
+
shouldLog('info', logLevels.debug);
|
|
232
|
+
shouldNotLogWithLocalLevelOverride('info', logLevels.none);
|
|
233
|
+
shouldNotLogWithLocalLevelOverride('info', logLevels.error);
|
|
234
|
+
shouldNotLogWithLocalLevelOverride('info', logLevels.warn);
|
|
235
|
+
shouldLogWithLocalLevelOverride('info', logLevels.info);
|
|
236
|
+
shouldLogWithLocalLevelOverride('info', logLevels.debug);
|
|
237
|
+
shouldNotLog('debug', logLevels.none);
|
|
238
|
+
shouldNotLog('debug', logLevels.error);
|
|
239
|
+
shouldNotLog('debug', logLevels.warn);
|
|
240
|
+
shouldNotLog('debug', logLevels.info);
|
|
241
|
+
shouldLog('debug', logLevels.debug);
|
|
242
|
+
shouldNotLogWithLocalLevelOverride('debug', logLevels.none);
|
|
243
|
+
shouldNotLogWithLocalLevelOverride('debug', logLevels.error);
|
|
244
|
+
shouldNotLogWithLocalLevelOverride('debug', logLevels.warn);
|
|
245
|
+
shouldNotLogWithLocalLevelOverride('debug', logLevels.info);
|
|
246
|
+
shouldLogWithLocalLevelOverride('debug', logLevels.debug);
|
|
247
|
+
shouldNotCallLogFunction(logLevels.error, logLevels.none);
|
|
248
|
+
shouldCallLogFunction(logLevels.error, logLevels.error);
|
|
249
|
+
shouldCallLogFunction(logLevels.error, logLevels.warn);
|
|
250
|
+
shouldCallLogFunction(logLevels.error, logLevels.info);
|
|
251
|
+
shouldCallLogFunction(logLevels.error, logLevels.debug);
|
|
252
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.none);
|
|
253
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.error);
|
|
254
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.warn);
|
|
255
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.info);
|
|
256
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.debug);
|
|
257
|
+
shouldNotCallLogFunction(logLevels.warn, logLevels.none);
|
|
258
|
+
shouldNotCallLogFunction(logLevels.warn, logLevels.error);
|
|
259
|
+
shouldCallLogFunction(logLevels.warn, logLevels.warn);
|
|
260
|
+
shouldCallLogFunction(logLevels.warn, logLevels.info);
|
|
261
|
+
shouldCallLogFunction(logLevels.warn, logLevels.debug);
|
|
262
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.none);
|
|
263
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.error);
|
|
264
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.warn);
|
|
265
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.info);
|
|
266
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.debug);
|
|
267
|
+
shouldNotCallLogFunction(logLevels.info, logLevels.none);
|
|
268
|
+
shouldNotCallLogFunction(logLevels.info, logLevels.error);
|
|
269
|
+
shouldNotCallLogFunction(logLevels.info, logLevels.warn);
|
|
270
|
+
shouldCallLogFunction(logLevels.info, logLevels.info);
|
|
271
|
+
shouldCallLogFunction(logLevels.info, logLevels.debug);
|
|
272
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.none);
|
|
273
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.error);
|
|
274
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.warn);
|
|
275
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.info);
|
|
276
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.debug);
|
|
277
|
+
shouldNotCallLogFunction(logLevels.debug, logLevels.none);
|
|
278
|
+
shouldNotCallLogFunction(logLevels.debug, logLevels.error);
|
|
279
|
+
shouldNotCallLogFunction(logLevels.debug, logLevels.warn);
|
|
280
|
+
shouldNotCallLogFunction(logLevels.debug, logLevels.info);
|
|
281
|
+
shouldCallLogFunction(logLevels.debug, logLevels.debug);
|
|
282
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.none);
|
|
283
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.error);
|
|
284
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.warn);
|
|
285
|
+
shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.info);
|
|
286
|
+
shouldCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.debug);
|
|
287
|
+
});
|
|
288
|
+
it('writes entry directly', () => {
|
|
289
|
+
const sl = createStandardLogForTest();
|
|
290
|
+
const log = sl.getLogger(['write-entry']);
|
|
291
|
+
const entry = { id: 'write-entry', level: logLevels.info, args: ['abc'], timestamp: new Date() };
|
|
292
|
+
log.write(entry);
|
|
293
|
+
a.satisfies(sl.reporter.logs, [entry]);
|
|
294
|
+
});
|
|
295
|
+
test.each(['on', 'count', 'error', 'warn', 'info', 'debug'])('method %s is readonly', name => {
|
|
296
|
+
const sl = createStandardLog();
|
|
297
|
+
const log = sl.getLogger([`${name} is readonly`]);
|
|
298
|
+
a.throws(() => log[name] = true);
|
|
299
|
+
});
|
|
300
|
+
describe('on()', () => {
|
|
301
|
+
it('log using log argument', () => {
|
|
302
|
+
const sl = createStandardLogForTest();
|
|
303
|
+
const logger = sl.getLogger(['log on fn']);
|
|
304
|
+
logger.on('error', log => { log('value'); });
|
|
305
|
+
a.satisfies(sl.reporter.logs, [
|
|
306
|
+
{ id: 'log on fn', level: logLevels.error, args: ['value'] }
|
|
307
|
+
]);
|
|
308
|
+
});
|
|
309
|
+
it('can take log level name in first argument', () => {
|
|
310
|
+
const sl = createStandardLogForTest();
|
|
311
|
+
const log = sl.getLogger(['string-on']);
|
|
312
|
+
log.on('debug', () => { return; });
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
describe('count()', () => {
|
|
316
|
+
test('will increment the counter', async () => {
|
|
317
|
+
const sl = createStandardLogForTest();
|
|
318
|
+
const logger = sl.getLogger(['inc counter']);
|
|
319
|
+
logger.count();
|
|
320
|
+
logger.count();
|
|
321
|
+
a.satisfies(sl.reporter.logs, [
|
|
322
|
+
{ id: 'inc counter', level: logLevels.debug, args: [1] },
|
|
323
|
+
{ id: 'inc counter', level: logLevels.debug, args: [2] }
|
|
324
|
+
]);
|
|
325
|
+
});
|
|
326
|
+
test('append args after the counter', async () => {
|
|
327
|
+
const sl = createStandardLogForTest(logLevels.debug);
|
|
328
|
+
const id = 'inc with args';
|
|
329
|
+
const logger = sl.getLogger([id]);
|
|
330
|
+
logger.count('msg1', 'msg2');
|
|
331
|
+
a.satisfies(sl.reporter.logs, [
|
|
332
|
+
{ id, level: logLevels.debug, args: [1, 'msg1', 'msg2'] }
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
test('not log if log level is less than debug', async () => {
|
|
336
|
+
const sl = createStandardLogForTest(logLevels.debug - 1);
|
|
337
|
+
const id = 'inc with args';
|
|
338
|
+
const logger = sl.getLogger([id]);
|
|
339
|
+
logger.count('msg1', 'msg2');
|
|
340
|
+
expect(sl.reporter.logs.length).toBe(0);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
test('logger with custom level', async () => {
|
|
344
|
+
const mem = createMemoryLogReporter();
|
|
345
|
+
const sl = createStandardLog({ customLevels: { 'cust_lvl': 100 }, reporters: [mem] });
|
|
346
|
+
const logger = sl.getLogger(['cust']);
|
|
347
|
+
logger.cust_lvl('a', 'b');
|
|
348
|
+
a.satisfies(mem.logs, [{ id: 'cust', level: 100, args: ['a', 'b'] }]);
|
|
349
|
+
});
|
|
350
|
+
describe('getLogger([,{ writeTo }])', () => {
|
|
351
|
+
function testWriteTo(loggerParams, handler) {
|
|
352
|
+
const memReporter = createMemoryLogReporter();
|
|
353
|
+
const specialReporter = createMemoryLogReporter({ id: 'special' });
|
|
354
|
+
const sl = createStandardLog({ reporters: [memReporter, specialReporter] });
|
|
355
|
+
const log = sl.getLogger(loggerParams);
|
|
356
|
+
handler(log, memReporter.logs, specialReporter.logs, sl);
|
|
357
|
+
}
|
|
358
|
+
it('can specify which reporter to use by name', () => {
|
|
359
|
+
testWriteTo(['writeTo-string', { writeTo: 'special' }], (log, memLogs, specialLogs) => {
|
|
360
|
+
log.error('error message');
|
|
361
|
+
expect(memLogs.length).toEqual(0);
|
|
362
|
+
expect(specialLogs.length).toEqual(1);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
it('can specify which reporter to use by regex', () => {
|
|
366
|
+
testWriteTo(['writeTo-regex', { writeTo: /^spec/ }], (log, memLogs, specialLogs) => {
|
|
367
|
+
log.error('error message');
|
|
368
|
+
expect(memLogs.length).toEqual(0);
|
|
369
|
+
expect(specialLogs.length).toEqual(1);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
it('can specify which reporter to use by RegExp', () => {
|
|
373
|
+
testWriteTo(['writeTo-RegExp', { writeTo: new RegExp('^spec') }], (log, memLogs, specialLogs) => {
|
|
374
|
+
log.error('error message');
|
|
375
|
+
expect(memLogs.length).toEqual(0);
|
|
376
|
+
expect(specialLogs.length).toEqual(1);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
it('can specify which reporter to use by function', () => {
|
|
380
|
+
testWriteTo(['writeTo-fn', { writeTo: id => id === 'special' }], (log, memLogs, specialLogs) => {
|
|
381
|
+
log.error('error message');
|
|
382
|
+
expect(memLogs.length).toEqual(0);
|
|
383
|
+
expect(specialLogs.length).toEqual(1);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
it('can specify custom reporter', () => {
|
|
387
|
+
const reporter = createMemoryLogReporter({ id: 'custom mem' });
|
|
388
|
+
testWriteTo(['writeTo-reporter', { writeTo: reporter }], (log, memLogs, specialLogs) => {
|
|
389
|
+
log.error('error message');
|
|
390
|
+
expect(memLogs.length).toEqual(0);
|
|
391
|
+
expect(specialLogs.length).toEqual(0);
|
|
392
|
+
expect(reporter.logs.length).toEqual(1);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
test('the custom console reporter cannot pick up logs from other loggers', () => {
|
|
396
|
+
// if not, it would be a security issue as the new reporter
|
|
397
|
+
// can capture the logs from other logger and send it elsewhere
|
|
398
|
+
const reporter = createMemoryLogReporter({ id: 'custom mem' });
|
|
399
|
+
testWriteTo(['writeTo-reporter-no-override', { writeTo: reporter }], (_, memLogs, specialLogs, sl) => {
|
|
400
|
+
const log = sl.getLogger(['writeTo-reporter-no-override-2']);
|
|
401
|
+
log.error('error message');
|
|
402
|
+
expect(reporter.logs.length).toEqual(0);
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
describe('suppressLogs()', () => {
|
|
408
|
+
test('suppress log', () => {
|
|
409
|
+
const sl = createStandardLogForTest();
|
|
410
|
+
const log = sl.getLogger(['l']);
|
|
411
|
+
suppressLogs(() => {
|
|
412
|
+
log.alert('should not see me');
|
|
413
|
+
}, log);
|
|
414
|
+
expect(sl.reporter.getLogMessageWithLevel()).toBe('');
|
|
415
|
+
});
|
|
416
|
+
test('suppress multiple logs', () => {
|
|
417
|
+
const sl = createStandardLogForTest();
|
|
418
|
+
const log1 = sl.getLogger(['l1']);
|
|
419
|
+
const log2 = sl.getLogger(['l2']);
|
|
420
|
+
suppressLogs(() => {
|
|
421
|
+
log1.alert('should not see me');
|
|
422
|
+
log2.alert('should not see me too');
|
|
423
|
+
}, log1, log2);
|
|
424
|
+
expect(sl.reporter.getLogMessageWithLevel()).toBe('');
|
|
425
|
+
});
|
|
426
|
+
test('return block result', () => {
|
|
427
|
+
const sl = createStandardLogForTest();
|
|
428
|
+
const log1 = sl.getLogger(['l']);
|
|
429
|
+
const log2 = sl.getLogger(['l2']);
|
|
430
|
+
const a = suppressLogs(() => 1, log1, log2);
|
|
431
|
+
expect(a).toBe(1);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
//# sourceMappingURL=standardLog.spec.js.map
|