standard-log 8.0.1 → 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/README.md +57 -133
- package/{esm/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/createConsoleLogReporter.spec.js → console.spec.js} +50 -68
- package/cjs/console.spec.js.map +1 -0
- package/cjs/errors.d.ts +0 -10
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +1 -43
- package/cjs/errors.js.map +1 -1
- 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 +5 -14
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +5 -14
- package/cjs/index.js.map +1 -1
- 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/{esm/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 -3
- 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 +7 -5
- package/cjs/testUtil.d.ts.map +1 -1
- package/cjs/testUtil.js +11 -14
- package/cjs/testUtil.js.map +1 -1
- package/cjs/types.d.ts +33 -24
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +324 -1078
- 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 +307 -1145
- 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/{cjs/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
- package/esm/console.d.ts.map +1 -0
- package/esm/{console/polyfilledConsole.js → 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/createConsoleLogReporter.spec.js → console.spec.js} +50 -65
- package/esm/console.spec.js.map +1 -0
- package/esm/errors.d.ts +0 -10
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +0 -34
- package/esm/errors.js.map +1 -1
- package/esm/formatter.d.ts +6 -0
- package/esm/formatter.d.ts.map +1 -0
- package/esm/{formatter/createTimestampFormatter.js → 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 +5 -14
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +5 -14
- package/esm/index.js.map +1 -1
- package/esm/logLevels.d.ts +60 -0
- package/esm/logLevels.d.ts.map +1 -0
- package/esm/{logLevel.js → 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/{cjs/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/{console/semverGt.spec.js → platform.spec.js} +2 -2
- 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 +7 -5
- package/esm/testUtil.d.ts.map +1 -1
- package/esm/testUtil.js +8 -12
- package/esm/testUtil.js.map +1 -1
- package/esm/types.d.ts +33 -24
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +10 -19
- package/ts/console.ts +72 -0
- package/ts/errors.ts +0 -12
- package/ts/{formatter/createTimestampFormatter.ts → formatter.ts} +12 -1
- package/ts/index.ts +5 -14
- package/ts/{logLevel.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/ts/types.ts +39 -30
- package/cjs/LogEntry.d.ts +0 -7
- package/cjs/LogEntry.d.ts.map +0 -1
- package/cjs/LogEntry.js +0 -3
- package/cjs/LogEntry.js.map +0 -1
- package/cjs/captureLogs.d.ts +0 -4
- package/cjs/captureLogs.d.ts.map +0 -1
- package/cjs/captureLogs.js +0 -33
- package/cjs/captureLogs.js.map +0 -1
- package/cjs/captureLogs.spec.d.ts +0 -2
- package/cjs/captureLogs.spec.d.ts.map +0 -1
- package/cjs/captureLogs.spec.js +0 -117
- package/cjs/captureLogs.spec.js.map +0 -1
- package/cjs/config.d.ts +0 -12
- package/cjs/config.d.ts.map +0 -1
- package/cjs/config.js +0 -59
- package/cjs/config.js.map +0 -1
- package/cjs/config.spec.d.ts +0 -2
- package/cjs/config.spec.d.ts.map +0 -1
- package/cjs/config.spec.js +0 -72
- package/cjs/config.spec.js.map +0 -1
- package/cjs/configForTest.d.ts +0 -5
- package/cjs/configForTest.d.ts.map +0 -1
- package/cjs/configForTest.js +0 -18
- package/cjs/configForTest.js.map +0 -1
- package/cjs/configForTest.spec.d.ts +0 -2
- package/cjs/configForTest.spec.d.ts.map +0 -1
- package/cjs/configForTest.spec.js +0 -17
- package/cjs/configForTest.spec.js.map +0 -1
- package/cjs/console/createConsoleLogReporter.d.ts.map +0 -1
- package/cjs/console/createConsoleLogReporter.js +0 -42
- package/cjs/console/createConsoleLogReporter.js.map +0 -1
- package/cjs/console/createConsoleLogReporter.spec.d.ts +0 -2
- package/cjs/console/createConsoleLogReporter.spec.d.ts.map +0 -1
- package/cjs/console/createConsoleLogReporter.spec.js.map +0 -1
- package/cjs/console/index.d.ts +0 -4
- package/cjs/console/index.d.ts.map +0 -1
- package/cjs/console/index.js +0 -20
- package/cjs/console/index.js.map +0 -1
- package/cjs/console/isConsoleDebugAvailable.d.ts +0 -2
- package/cjs/console/isConsoleDebugAvailable.d.ts.map +0 -1
- package/cjs/console/isConsoleDebugAvailable.js +0 -20
- package/cjs/console/isConsoleDebugAvailable.js.map +0 -1
- package/cjs/console/polyfilledConsole.d.ts +0 -7
- package/cjs/console/polyfilledConsole.d.ts.map +0 -1
- package/cjs/console/polyfilledConsole.js +0 -41
- package/cjs/console/polyfilledConsole.js.map +0 -1
- package/cjs/console/semverGt.d.ts +0 -2
- package/cjs/console/semverGt.d.ts.map +0 -1
- package/cjs/console/semverGt.js +0 -13
- package/cjs/console/semverGt.js.map +0 -1
- package/cjs/console/semverGt.spec.d.ts +0 -2
- package/cjs/console/semverGt.spec.d.ts.map +0 -1
- package/cjs/console/semverGt.spec.js +0 -22
- package/cjs/console/semverGt.spec.js.map +0 -1
- package/cjs/console/toConsoleMethod.d.ts +0 -2
- package/cjs/console/toConsoleMethod.d.ts.map +0 -1
- package/cjs/console/toConsoleMethod.js +0 -22
- package/cjs/console/toConsoleMethod.js.map +0 -1
- package/cjs/console/types.d.ts +0 -3
- package/cjs/console/types.d.ts.map +0 -1
- package/cjs/console/types.js +0 -3
- package/cjs/console/types.js.map +0 -1
- package/cjs/customLogLevel.d.ts +0 -11
- package/cjs/customLogLevel.d.ts.map +0 -1
- package/cjs/customLogLevel.js +0 -38
- package/cjs/customLogLevel.js.map +0 -1
- package/cjs/customLogLevel.spec.d.ts +0 -2
- package/cjs/customLogLevel.spec.d.ts.map +0 -1
- package/cjs/customLogLevel.spec.js +0 -37
- package/cjs/customLogLevel.spec.js.map +0 -1
- package/cjs/formatter/createTimestampFormatter.d.ts +0 -3
- package/cjs/formatter/createTimestampFormatter.d.ts.map +0 -1
- package/cjs/formatter/createTimestampFormatter.js +0 -26
- package/cjs/formatter/createTimestampFormatter.js.map +0 -1
- package/cjs/formatter/createTimestampFormatter.spec.d.ts +0 -2
- package/cjs/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
- package/cjs/formatter/createTimestampFormatter.spec.js +0 -23
- package/cjs/formatter/createTimestampFormatter.spec.js.map +0 -1
- package/cjs/formatter/formatLogLevel.d.ts +0 -2
- package/cjs/formatter/formatLogLevel.d.ts.map +0 -1
- package/cjs/formatter/formatLogLevel.js +0 -10
- package/cjs/formatter/formatLogLevel.js.map +0 -1
- package/cjs/formatter/index.d.ts +0 -4
- package/cjs/formatter/index.d.ts.map +0 -1
- package/cjs/formatter/index.js +0 -20
- package/cjs/formatter/index.js.map +0 -1
- package/cjs/formatter/plainLogFormatter.d.ts +0 -3
- package/cjs/formatter/plainLogFormatter.d.ts.map +0 -1
- package/cjs/formatter/plainLogFormatter.js +0 -19
- package/cjs/formatter/plainLogFormatter.js.map +0 -1
- package/cjs/formatter/plainLogFormatter.spec.d.ts +0 -2
- package/cjs/formatter/plainLogFormatter.spec.d.ts.map +0 -1
- package/cjs/formatter/plainLogFormatter.spec.js +0 -9
- package/cjs/formatter/plainLogFormatter.spec.js.map +0 -1
- package/cjs/getDefaultReporter.browser.d.ts +0 -2
- package/cjs/getDefaultReporter.browser.d.ts.map +0 -1
- package/cjs/getDefaultReporter.browser.js +0 -15
- package/cjs/getDefaultReporter.browser.js.map +0 -1
- package/cjs/getDefaultReporter.d.ts +0 -2
- package/cjs/getDefaultReporter.d.ts.map +0 -1
- package/cjs/getDefaultReporter.js +0 -19
- package/cjs/getDefaultReporter.js.map +0 -1
- package/cjs/getLogModeFromEnvironment.browser.d.ts +0 -3
- package/cjs/getLogModeFromEnvironment.browser.d.ts.map +0 -1
- package/cjs/getLogModeFromEnvironment.browser.js +0 -9
- package/cjs/getLogModeFromEnvironment.browser.js.map +0 -1
- package/cjs/getLogModeFromEnvironment.d.ts +0 -3
- package/cjs/getLogModeFromEnvironment.d.ts.map +0 -1
- package/cjs/getLogModeFromEnvironment.js +0 -17
- package/cjs/getLogModeFromEnvironment.js.map +0 -1
- package/cjs/getLogModeFromEnvironment.spec.d.ts +0 -2
- package/cjs/getLogModeFromEnvironment.spec.d.ts.map +0 -1
- package/cjs/getLogModeFromEnvironment.spec.js +0 -25
- package/cjs/getLogModeFromEnvironment.spec.js.map +0 -1
- package/cjs/getLogger.d.ts +0 -9
- package/cjs/getLogger.d.ts.map +0 -1
- package/cjs/getLogger.js +0 -103
- package/cjs/getLogger.js.map +0 -1
- package/cjs/getLogger.spec.d.ts +0 -2
- package/cjs/getLogger.spec.d.ts.map +0 -1
- package/cjs/getLogger.spec.js +0 -485
- package/cjs/getLogger.spec.js.map +0 -1
- package/cjs/getLoggers.d.ts +0 -7
- package/cjs/getLoggers.d.ts.map +0 -1
- package/cjs/getLoggers.js +0 -15
- package/cjs/getLoggers.js.map +0 -1
- package/cjs/logLevel.d.ts +0 -106
- package/cjs/logLevel.d.ts.map +0 -1
- package/cjs/logLevel.js +0 -59
- package/cjs/logLevel.js.map +0 -1
- package/cjs/logLevel.spec.d.ts +0 -2
- package/cjs/logLevel.spec.d.ts.map +0 -1
- package/cjs/logLevel.spec.js +0 -195
- package/cjs/logLevel.spec.js.map +0 -1
- package/cjs/logLevelFn.d.ts +0 -20
- package/cjs/logLevelFn.d.ts.map +0 -1
- package/cjs/logLevelFn.js +0 -76
- package/cjs/logLevelFn.js.map +0 -1
- package/cjs/logReporter.d.ts +0 -7
- package/cjs/logReporter.d.ts.map +0 -1
- package/cjs/logReporter.js +0 -29
- package/cjs/logReporter.js.map +0 -1
- package/cjs/logReporter.spec.d.ts +0 -2
- package/cjs/logReporter.spec.d.ts.map +0 -1
- package/cjs/logReporter.spec.js +0 -98
- package/cjs/logReporter.spec.js.map +0 -1
- package/cjs/logReporterInternal.d.ts +0 -3
- package/cjs/logReporterInternal.d.ts.map +0 -1
- package/cjs/logReporterInternal.js +0 -23
- package/cjs/logReporterInternal.js.map +0 -1
- package/cjs/memory/MemoryLogReporter.d.ts.map +0 -1
- package/cjs/memory/MemoryLogReporter.js +0 -56
- package/cjs/memory/MemoryLogReporter.js.map +0 -1
- package/cjs/memory/MemoryLogReporter.spec.d.ts +0 -2
- package/cjs/memory/MemoryLogReporter.spec.d.ts.map +0 -1
- package/cjs/memory/MemoryLogReporter.spec.js +0 -124
- package/cjs/memory/MemoryLogReporter.spec.js.map +0 -1
- package/cjs/memory/index.d.ts +0 -3
- package/cjs/memory/index.d.ts.map +0 -1
- package/cjs/memory/index.js +0 -19
- package/cjs/memory/index.js.map +0 -1
- package/cjs/memory/logEntriesToString.d.ts +0 -3
- package/cjs/memory/logEntriesToString.d.ts.map +0 -1
- package/cjs/memory/logEntriesToString.js +0 -10
- package/cjs/memory/logEntriesToString.js.map +0 -1
- package/cjs/memory/logEntriesToString.spec.d.ts +0 -2
- package/cjs/memory/logEntriesToString.spec.d.ts.map +0 -1
- package/cjs/memory/logEntriesToString.spec.js +0 -36
- package/cjs/memory/logEntriesToString.spec.js.map +0 -1
- package/cjs/memory/toInspectStringForObject.d.ts +0 -3
- package/cjs/memory/toInspectStringForObject.d.ts.map +0 -1
- package/cjs/memory/toInspectStringForObject.js +0 -17
- package/cjs/memory/toInspectStringForObject.js.map +0 -1
- package/cjs/shouldLog.d.ts +0 -8
- package/cjs/shouldLog.d.ts.map +0 -1
- package/cjs/shouldLog.js +0 -14
- package/cjs/shouldLog.js.map +0 -1
- package/cjs/store.d.ts +0 -3
- package/cjs/store.d.ts.map +0 -1
- package/cjs/store.js +0 -27
- package/cjs/store.js.map +0 -1
- package/cjs/suppressLogs.d.ts +0 -6
- package/cjs/suppressLogs.d.ts.map +0 -1
- package/cjs/suppressLogs.js +0 -17
- package/cjs/suppressLogs.js.map +0 -1
- package/cjs/suppressLogs.spec.d.ts +0 -2
- package/cjs/suppressLogs.spec.d.ts.map +0 -1
- package/cjs/suppressLogs.spec.js +0 -31
- package/cjs/suppressLogs.spec.js.map +0 -1
- package/cjs/typesInternal.d.ts +0 -20
- package/cjs/typesInternal.d.ts.map +0 -1
- package/cjs/typesInternal.js +0 -3
- package/cjs/typesInternal.js.map +0 -1
- package/cjs/utils.d.ts +0 -6
- package/cjs/utils.d.ts.map +0 -1
- package/cjs/utils.js +0 -15
- package/cjs/utils.js.map +0 -1
- package/cjs/writeToReporters.d.ts +0 -6
- package/cjs/writeToReporters.d.ts.map +0 -1
- package/cjs/writeToReporters.js +0 -22
- package/cjs/writeToReporters.js.map +0 -1
- package/cjs/writeToReporters.spec.d.ts +0 -2
- package/cjs/writeToReporters.spec.d.ts.map +0 -1
- package/cjs/writeToReporters.spec.js +0 -59
- package/cjs/writeToReporters.spec.js.map +0 -1
- package/esm/LogEntry.d.ts +0 -7
- package/esm/LogEntry.d.ts.map +0 -1
- package/esm/LogEntry.js +0 -2
- package/esm/LogEntry.js.map +0 -1
- package/esm/captureLogs.d.ts +0 -4
- package/esm/captureLogs.d.ts.map +0 -1
- package/esm/captureLogs.js +0 -29
- package/esm/captureLogs.js.map +0 -1
- package/esm/captureLogs.spec.d.ts +0 -2
- package/esm/captureLogs.spec.d.ts.map +0 -1
- package/esm/captureLogs.spec.js +0 -45
- package/esm/captureLogs.spec.js.map +0 -1
- package/esm/config.d.ts +0 -12
- package/esm/config.d.ts.map +0 -1
- package/esm/config.js +0 -44
- package/esm/config.js.map +0 -1
- package/esm/config.spec.d.ts +0 -2
- package/esm/config.spec.d.ts.map +0 -1
- package/esm/config.spec.js +0 -67
- package/esm/config.spec.js.map +0 -1
- package/esm/configForTest.d.ts +0 -5
- package/esm/configForTest.d.ts.map +0 -1
- package/esm/configForTest.js +0 -14
- package/esm/configForTest.js.map +0 -1
- package/esm/configForTest.spec.d.ts +0 -2
- package/esm/configForTest.spec.d.ts.map +0 -1
- package/esm/configForTest.spec.js +0 -15
- package/esm/configForTest.spec.js.map +0 -1
- package/esm/console/createConsoleLogReporter.d.ts.map +0 -1
- package/esm/console/createConsoleLogReporter.js +0 -37
- package/esm/console/createConsoleLogReporter.js.map +0 -1
- package/esm/console/createConsoleLogReporter.spec.d.ts +0 -2
- package/esm/console/createConsoleLogReporter.spec.d.ts.map +0 -1
- package/esm/console/createConsoleLogReporter.spec.js.map +0 -1
- package/esm/console/index.d.ts +0 -4
- package/esm/console/index.d.ts.map +0 -1
- package/esm/console/index.js +0 -4
- package/esm/console/index.js.map +0 -1
- package/esm/console/isConsoleDebugAvailable.d.ts +0 -2
- package/esm/console/isConsoleDebugAvailable.d.ts.map +0 -1
- package/esm/console/isConsoleDebugAvailable.js +0 -13
- package/esm/console/isConsoleDebugAvailable.js.map +0 -1
- package/esm/console/polyfilledConsole.d.ts +0 -7
- package/esm/console/polyfilledConsole.d.ts.map +0 -1
- package/esm/console/polyfilledConsole.js.map +0 -1
- package/esm/console/semverGt.d.ts +0 -2
- package/esm/console/semverGt.d.ts.map +0 -1
- package/esm/console/semverGt.js +0 -9
- package/esm/console/semverGt.js.map +0 -1
- package/esm/console/semverGt.spec.d.ts +0 -2
- package/esm/console/semverGt.spec.d.ts.map +0 -1
- package/esm/console/semverGt.spec.js.map +0 -1
- package/esm/console/toConsoleMethod.d.ts +0 -2
- package/esm/console/toConsoleMethod.d.ts.map +0 -1
- package/esm/console/toConsoleMethod.js +0 -18
- package/esm/console/toConsoleMethod.js.map +0 -1
- package/esm/console/types.d.ts +0 -3
- package/esm/console/types.d.ts.map +0 -1
- package/esm/console/types.js +0 -2
- package/esm/console/types.js.map +0 -1
- package/esm/customLogLevel.d.ts +0 -11
- package/esm/customLogLevel.d.ts.map +0 -1
- package/esm/customLogLevel.js +0 -30
- package/esm/customLogLevel.js.map +0 -1
- package/esm/customLogLevel.spec.d.ts +0 -2
- package/esm/customLogLevel.spec.d.ts.map +0 -1
- package/esm/customLogLevel.spec.js +0 -32
- package/esm/customLogLevel.spec.js.map +0 -1
- package/esm/formatter/createTimestampFormatter.d.ts +0 -3
- package/esm/formatter/createTimestampFormatter.d.ts.map +0 -1
- package/esm/formatter/createTimestampFormatter.js.map +0 -1
- package/esm/formatter/createTimestampFormatter.spec.d.ts +0 -2
- package/esm/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
- package/esm/formatter/createTimestampFormatter.spec.js +0 -21
- package/esm/formatter/createTimestampFormatter.spec.js.map +0 -1
- package/esm/formatter/formatLogLevel.d.ts +0 -2
- package/esm/formatter/formatLogLevel.d.ts.map +0 -1
- package/esm/formatter/formatLogLevel.js +0 -6
- package/esm/formatter/formatLogLevel.js.map +0 -1
- package/esm/formatter/index.d.ts +0 -4
- package/esm/formatter/index.d.ts.map +0 -1
- package/esm/formatter/index.js +0 -4
- package/esm/formatter/index.js.map +0 -1
- package/esm/formatter/plainLogFormatter.d.ts +0 -3
- package/esm/formatter/plainLogFormatter.d.ts.map +0 -1
- package/esm/formatter/plainLogFormatter.js +0 -5
- package/esm/formatter/plainLogFormatter.js.map +0 -1
- package/esm/formatter/plainLogFormatter.spec.d.ts +0 -2
- package/esm/formatter/plainLogFormatter.spec.d.ts.map +0 -1
- package/esm/formatter/plainLogFormatter.spec.js +0 -7
- package/esm/formatter/plainLogFormatter.spec.js.map +0 -1
- package/esm/getDefaultReporter.browser.d.ts +0 -2
- package/esm/getDefaultReporter.browser.d.ts.map +0 -1
- package/esm/getDefaultReporter.browser.js +0 -11
- package/esm/getDefaultReporter.browser.js.map +0 -1
- package/esm/getDefaultReporter.d.ts +0 -2
- package/esm/getDefaultReporter.d.ts.map +0 -1
- package/esm/getDefaultReporter.js +0 -15
- package/esm/getDefaultReporter.js.map +0 -1
- package/esm/getLogModeFromEnvironment.browser.d.ts +0 -3
- package/esm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
- package/esm/getLogModeFromEnvironment.browser.js +0 -5
- package/esm/getLogModeFromEnvironment.browser.js.map +0 -1
- package/esm/getLogModeFromEnvironment.d.ts +0 -3
- package/esm/getLogModeFromEnvironment.d.ts.map +0 -1
- package/esm/getLogModeFromEnvironment.js +0 -13
- package/esm/getLogModeFromEnvironment.js.map +0 -1
- package/esm/getLogModeFromEnvironment.spec.d.ts +0 -2
- package/esm/getLogModeFromEnvironment.spec.d.ts.map +0 -1
- package/esm/getLogModeFromEnvironment.spec.js +0 -20
- package/esm/getLogModeFromEnvironment.spec.js.map +0 -1
- package/esm/getLogger.d.ts +0 -9
- package/esm/getLogger.d.ts.map +0 -1
- package/esm/getLogger.js +0 -78
- package/esm/getLogger.js.map +0 -1
- package/esm/getLogger.spec.d.ts +0 -2
- package/esm/getLogger.spec.d.ts.map +0 -1
- package/esm/getLogger.spec.js +0 -385
- package/esm/getLogger.spec.js.map +0 -1
- package/esm/getLoggers.d.ts +0 -7
- package/esm/getLoggers.d.ts.map +0 -1
- package/esm/getLoggers.js +0 -11
- package/esm/getLoggers.js.map +0 -1
- package/esm/logLevel.d.ts +0 -106
- package/esm/logLevel.d.ts.map +0 -1
- package/esm/logLevel.js.map +0 -1
- package/esm/logLevel.spec.d.ts +0 -2
- package/esm/logLevel.spec.d.ts.map +0 -1
- package/esm/logLevel.spec.js +0 -148
- package/esm/logLevel.spec.js.map +0 -1
- package/esm/logLevelFn.d.ts +0 -20
- package/esm/logLevelFn.d.ts.map +0 -1
- package/esm/logLevelFn.js +0 -67
- package/esm/logLevelFn.js.map +0 -1
- package/esm/logReporter.d.ts +0 -7
- package/esm/logReporter.d.ts.map +0 -1
- package/esm/logReporter.js +0 -21
- package/esm/logReporter.js.map +0 -1
- package/esm/logReporter.spec.d.ts +0 -2
- package/esm/logReporter.spec.d.ts.map +0 -1
- package/esm/logReporter.spec.js +0 -93
- package/esm/logReporter.spec.js.map +0 -1
- package/esm/logReporterInternal.d.ts +0 -3
- package/esm/logReporterInternal.d.ts.map +0 -1
- package/esm/logReporterInternal.js +0 -19
- package/esm/logReporterInternal.js.map +0 -1
- package/esm/memory/MemoryLogReporter.d.ts.map +0 -1
- package/esm/memory/MemoryLogReporter.js +0 -51
- package/esm/memory/MemoryLogReporter.js.map +0 -1
- package/esm/memory/MemoryLogReporter.spec.d.ts +0 -2
- package/esm/memory/MemoryLogReporter.spec.d.ts.map +0 -1
- package/esm/memory/MemoryLogReporter.spec.js +0 -111
- package/esm/memory/MemoryLogReporter.spec.js.map +0 -1
- package/esm/memory/index.d.ts +0 -3
- package/esm/memory/index.d.ts.map +0 -1
- package/esm/memory/index.js +0 -3
- package/esm/memory/index.js.map +0 -1
- package/esm/memory/logEntriesToString.d.ts +0 -3
- package/esm/memory/logEntriesToString.d.ts.map +0 -1
- package/esm/memory/logEntriesToString.js +0 -6
- package/esm/memory/logEntriesToString.js.map +0 -1
- package/esm/memory/logEntriesToString.spec.d.ts +0 -2
- package/esm/memory/logEntriesToString.spec.d.ts.map +0 -1
- package/esm/memory/logEntriesToString.spec.js +0 -42
- package/esm/memory/logEntriesToString.spec.js.map +0 -1
- package/esm/memory/toInspectStringForObject.d.ts +0 -3
- package/esm/memory/toInspectStringForObject.d.ts.map +0 -1
- package/esm/memory/toInspectStringForObject.js +0 -11
- package/esm/memory/toInspectStringForObject.js.map +0 -1
- package/esm/shouldLog.d.ts +0 -8
- package/esm/shouldLog.d.ts.map +0 -1
- package/esm/shouldLog.js +0 -10
- package/esm/shouldLog.js.map +0 -1
- package/esm/store.d.ts +0 -3
- package/esm/store.d.ts.map +0 -1
- package/esm/store.js +0 -24
- package/esm/store.js.map +0 -1
- package/esm/suppressLogs.d.ts +0 -6
- package/esm/suppressLogs.d.ts.map +0 -1
- package/esm/suppressLogs.js +0 -9
- package/esm/suppressLogs.js.map +0 -1
- package/esm/suppressLogs.spec.d.ts +0 -2
- package/esm/suppressLogs.spec.d.ts.map +0 -1
- package/esm/suppressLogs.spec.js +0 -29
- package/esm/suppressLogs.spec.js.map +0 -1
- package/esm/typesInternal.d.ts +0 -20
- package/esm/typesInternal.d.ts.map +0 -1
- package/esm/typesInternal.js +0 -2
- package/esm/typesInternal.js.map +0 -1
- package/esm/utils.d.ts +0 -6
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -11
- package/esm/utils.js.map +0 -1
- package/esm/writeToReporters.d.ts +0 -6
- package/esm/writeToReporters.d.ts.map +0 -1
- package/esm/writeToReporters.js +0 -18
- package/esm/writeToReporters.js.map +0 -1
- package/esm/writeToReporters.spec.d.ts +0 -2
- package/esm/writeToReporters.spec.d.ts.map +0 -1
- package/esm/writeToReporters.spec.js +0 -9
- package/esm/writeToReporters.spec.js.map +0 -1
- package/ts/LogEntry.ts +0 -7
- package/ts/captureLogs.ts +0 -35
- package/ts/config.ts +0 -57
- package/ts/configForTest.ts +0 -16
- package/ts/console/createConsoleLogReporter.ts +0 -48
- package/ts/console/index.ts +0 -3
- package/ts/console/isConsoleDebugAvailable.ts +0 -11
- package/ts/console/polyfilledConsole.ts +0 -34
- package/ts/console/semverGt.ts +0 -9
- package/ts/console/toConsoleMethod.ts +0 -18
- package/ts/console/types.ts +0 -3
- package/ts/customLogLevel.ts +0 -35
- package/ts/formatter/formatLogLevel.ts +0 -6
- package/ts/formatter/index.ts +0 -3
- package/ts/formatter/plainLogFormatter.ts +0 -6
- package/ts/getDefaultReporter.browser.ts +0 -13
- package/ts/getDefaultReporter.ts +0 -15
- package/ts/getLogModeFromEnvironment.browser.ts +0 -6
- package/ts/getLogModeFromEnvironment.ts +0 -16
- package/ts/getLogger.ts +0 -92
- package/ts/getLoggers.ts +0 -12
- package/ts/logLevelFn.ts +0 -72
- package/ts/logReporter.ts +0 -26
- package/ts/logReporterInternal.ts +0 -18
- package/ts/memory/MemoryLogReporter.ts +0 -72
- package/ts/memory/index.ts +0 -2
- package/ts/memory/logEntriesToString.ts +0 -7
- package/ts/memory/toInspectStringForObject.ts +0 -13
- package/ts/shouldLog.ts +0 -11
- package/ts/store.ts +0 -25
- package/ts/suppressLogs.ts +0 -14
- package/ts/typesInternal.ts +0 -21
- package/ts/utils.ts +0 -11
- package/ts/writeToReporters.ts +0 -20
package/esm/types.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
export declare type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare type LogEntry = {
|
|
6
|
-
id: string;
|
|
7
|
-
level: number;
|
|
8
|
-
args: any[];
|
|
9
|
-
timestamp: Date;
|
|
1
|
+
export declare type StandardLogOptions<CustomLevelNames extends string = string> = {
|
|
2
|
+
customLevels: Record<CustomLevelNames, number>;
|
|
3
|
+
logLevel: number;
|
|
4
|
+
reporters: LogReporter[];
|
|
10
5
|
};
|
|
6
|
+
export interface LoggerOptions {
|
|
7
|
+
level?: number;
|
|
8
|
+
writeTo?: LogReporter | ReporterFilter;
|
|
9
|
+
}
|
|
11
10
|
export declare type Logger<T extends string = LogMethodNames> = {
|
|
12
11
|
readonly id: string;
|
|
13
12
|
/**
|
|
@@ -22,17 +21,28 @@ export declare type Logger<T extends string = LogMethodNames> = {
|
|
|
22
21
|
on(level: number | T, logFunction: LogFunction): void;
|
|
23
22
|
/**
|
|
24
23
|
* Write custom log entries.
|
|
25
|
-
* This can be used along with `captureLogs()` to rewrite the logs at a later time.
|
|
26
24
|
*/
|
|
27
25
|
write(entry: LogEntry): void;
|
|
28
26
|
} & {
|
|
29
27
|
[k in T]: LogMethod;
|
|
30
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Names of the standard log methods.
|
|
31
|
+
*/
|
|
32
|
+
export declare type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
|
|
33
|
+
export declare type LogEntry = {
|
|
34
|
+
id: string;
|
|
35
|
+
level: number;
|
|
36
|
+
args: any[];
|
|
37
|
+
timestamp: Date;
|
|
38
|
+
};
|
|
39
|
+
export declare type LogMethod = (...args: any[]) => void;
|
|
40
|
+
export declare type LogFunction = ((log: LogMethod) => void) | (() => string);
|
|
31
41
|
export declare type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
|
|
32
42
|
/**
|
|
33
43
|
* Formats a log entry.
|
|
34
44
|
* Depends on the reporter, it can expect a different return type.
|
|
35
|
-
* By default the return type is `any[]` which `console` accepts.
|
|
45
|
+
* By default the return type is `any[]` which the `console` accepts.
|
|
36
46
|
*/
|
|
37
47
|
export declare type LogFormatter<T = any[]> = (entry: LogEntry) => T;
|
|
38
48
|
/**
|
|
@@ -43,31 +53,24 @@ export declare type LogLevelEntry = {
|
|
|
43
53
|
name: string;
|
|
44
54
|
level: number;
|
|
45
55
|
};
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
id: string;
|
|
56
|
+
export interface LogReporter<T = any> {
|
|
57
|
+
readonly id: string;
|
|
49
58
|
/**
|
|
50
59
|
* Specifies the formatter to be used by the reporter.
|
|
51
60
|
* Using this you can customize how the reporter writes the log entry.
|
|
52
|
-
* This is readonly in production mode.
|
|
53
61
|
*/
|
|
54
|
-
formatter: LogFormatter<T>;
|
|
62
|
+
readonly formatter: LogFormatter<T>;
|
|
55
63
|
/**
|
|
56
64
|
* Specifies a filter to determine should the log be written.
|
|
57
|
-
* This is readonly in production mode.
|
|
58
65
|
*/
|
|
59
|
-
filter?: LogFilter;
|
|
66
|
+
readonly filter?: LogFilter;
|
|
60
67
|
/**
|
|
61
68
|
* Indicate if this is a console reporter.
|
|
62
69
|
* There is only one console reporter can be present in the system.
|
|
63
|
-
* If a new console reporter is added,
|
|
64
|
-
* it will be used in place of the existing one.
|
|
65
|
-
* However, existing filter will be carried over to ensure logs should not be shown remain not shown.
|
|
66
|
-
* If the new reporter also contains a filter, they will be combined.
|
|
67
70
|
*/
|
|
68
|
-
isConsoleReporter?: boolean;
|
|
71
|
+
readonly isConsoleReporter?: boolean;
|
|
69
72
|
write(entry: LogEntry): void;
|
|
70
|
-
}
|
|
73
|
+
}
|
|
71
74
|
export declare type LogReporterOptions<T = any> = {
|
|
72
75
|
id?: string;
|
|
73
76
|
/**
|
|
@@ -81,4 +84,10 @@ export declare type LogReporterOptions<T = any> = {
|
|
|
81
84
|
filter?: LogFilter;
|
|
82
85
|
};
|
|
83
86
|
export declare type LogLevel = number;
|
|
87
|
+
export interface ConsoleLike {
|
|
88
|
+
debug(...args: any[]): void;
|
|
89
|
+
info(...args: any[]): void;
|
|
90
|
+
warn(...args: any[]): void;
|
|
91
|
+
error(...args: any[]): void;
|
|
92
|
+
}
|
|
84
93
|
//# sourceMappingURL=types.d.ts.map
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,MAAM,IAAI;IACzE,YAAY,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,GAAG,cAAc,CAAA;CACvC;AAED,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IACtD;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,SAAS;CAAE,CAAA;AAE3B;;GAEG;AACH,oBAAY,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AAErI,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,oBAAY,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAEhD,oBAAY,WAAW,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,CAAA;AAErE,oBAAY,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;AAEhF;;;;GAIG;AACH,oBAAY,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAA;AAE5D;;GAEG;AACH,oBAAY,SAAS,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;AAEpD,oBAAY,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3D,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B;AAED,oBAAY,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED,oBAAY,QAAQ,GAAG,MAAM,CAAA;AAE7B,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7B"}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["export type StandardLogOptions<CustomLevelNames extends string = string> = {\n customLevels: Record<CustomLevelNames, number>,\n logLevel: number,\n reporters: LogReporter[]\n}\n\nexport interface LoggerOptions {\n level?: number,\n writeTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<T extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | T, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in T]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = ((log: LogMethod) => void) | (() => string)\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string, level: number }\n\nexport interface LogReporter<T = any> {\n readonly id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n readonly formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n readonly filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n */\n readonly isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n debug(...args: any[]): void,\n info(...args: any[]): void,\n warn(...args: any[]): void,\n error(...args: any[]): void,\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "standard-log",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "The standard log library",
|
|
5
5
|
"homepage": "https://github.com/unional/standard-log/tree/master/packages/log",
|
|
6
6
|
"bugs": {
|
|
@@ -23,12 +23,9 @@
|
|
|
23
23
|
},
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"browser": {
|
|
26
|
-
"./cjs/
|
|
27
|
-
"./
|
|
28
|
-
"./
|
|
29
|
-
"./esm/getLogModeFromEnvironment.js": "./esm/getLogModeFromEnvironment.browser.js",
|
|
30
|
-
"./ts/getDefaultReporter.ts": "./ts/getDefaultReporter.browser.ts",
|
|
31
|
-
"./ts/getLogModeFromEnvironment.ts": "./ts/getLogModeFromEnvironment.browser.ts"
|
|
26
|
+
"./cjs/platform.js": "./cjs/platform.browser.js",
|
|
27
|
+
"./esm/platform.js": "./esm/platform.browser.js",
|
|
28
|
+
"./ts/platform.js": "./ts/platform.browser.js"
|
|
32
29
|
},
|
|
33
30
|
"typings": "./cjs/index.d.ts",
|
|
34
31
|
"files": [
|
|
@@ -48,7 +45,7 @@
|
|
|
48
45
|
"bundle": "run-p bundle:es5 bundle:esm",
|
|
49
46
|
"bundle:es5": "webpack -c ./webpack.es5.cjs",
|
|
50
47
|
"bundle:esm": "webpack -c ./webpack.esm.cjs",
|
|
51
|
-
"clean": "rimraf dist lib libm cjs
|
|
48
|
+
"clean": "rimraf cjs coverage dist esm lib libm tslib .tsbuildinfo && mkdir cjs && echo '{\"type\":\"commonjs\"}' > cjs/package.json || true",
|
|
52
49
|
"coverage": "jest --coverage",
|
|
53
50
|
"depcheck": "depcheck",
|
|
54
51
|
"lint": "cross-env TIMING=1 eslint --ext=ts,js,cjs,mjs .",
|
|
@@ -58,42 +55,36 @@
|
|
|
58
55
|
"watch": "jest --watch"
|
|
59
56
|
},
|
|
60
57
|
"dependencies": {
|
|
61
|
-
"
|
|
62
|
-
"iso-error": "^4.3.
|
|
58
|
+
"@just-func/types": "^0.2.0",
|
|
59
|
+
"iso-error": "^4.3.5",
|
|
63
60
|
"ms": "^2.1.3",
|
|
64
|
-
"tslib": "^2.4.0",
|
|
65
61
|
"type-plus": "^4.10.0",
|
|
66
62
|
"upper-case": "^2.0.2"
|
|
67
63
|
},
|
|
68
64
|
"devDependencies": {
|
|
69
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
70
66
|
"@types/ms": "^0.7.31",
|
|
67
|
+
"@types/ramda": "^0.28.13",
|
|
71
68
|
"assertron": "^9.2.3",
|
|
72
69
|
"compression-webpack-plugin": "^10.0.0",
|
|
73
70
|
"cross-env": "^7.0.3",
|
|
74
|
-
"delay": "^5.0.0",
|
|
75
71
|
"depcheck": "^1.4.3",
|
|
76
72
|
"eslint": "^8.17.0",
|
|
77
|
-
"global-store": "1.0.0-beta.21",
|
|
78
73
|
"jest": "^28.1.0",
|
|
79
74
|
"npm-run-all": "^4.1.5",
|
|
80
75
|
"param-case": "^3.0.4",
|
|
81
76
|
"pascal-case": "^3.1.2",
|
|
77
|
+
"ramda": "^0.28.0",
|
|
82
78
|
"rimraf": "^3.0.2",
|
|
83
79
|
"size-limit": "^7.0.8",
|
|
84
80
|
"ts-jest": "^28.0.4",
|
|
85
81
|
"ts-loader": "^9.3.0",
|
|
82
|
+
"tslib": "^2.4.0",
|
|
86
83
|
"typescript": "^4.7.3",
|
|
87
84
|
"webpack": "^5.73.0",
|
|
88
85
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
89
86
|
"webpack-cli": "^4.9.2"
|
|
90
87
|
},
|
|
91
|
-
"peerDependencies": {
|
|
92
|
-
"global-store": "*"
|
|
93
|
-
},
|
|
94
|
-
"optionalDependencies": {
|
|
95
|
-
"ramda": "^0.28.0"
|
|
96
|
-
},
|
|
97
88
|
"size-limit": [
|
|
98
89
|
{
|
|
99
90
|
"path": "./cjs/index.js",
|
package/ts/console.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { required } from 'type-plus'
|
|
2
|
+
import { logLevels } from './logLevels.js'
|
|
3
|
+
import { isConsoleDebugAvailable, polyfill } from './platform.js'
|
|
4
|
+
import { plainLogFormatter } from './formatter.js'
|
|
5
|
+
import type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
|
|
6
|
+
|
|
7
|
+
export function toConsoleMethod(level: number) {
|
|
8
|
+
switch (true) {
|
|
9
|
+
// edge case in case none is somehow written
|
|
10
|
+
case (level <= 0): return 'debug'
|
|
11
|
+
case (level <= logLevels.error): return 'error'
|
|
12
|
+
case (level <= logLevels.warn): return 'warn'
|
|
13
|
+
case (level <= logLevels.info): return 'info'
|
|
14
|
+
default: return 'debug'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// istanbul ignore next
|
|
19
|
+
/* eslint-disable no-console */
|
|
20
|
+
function buildPolyfillConsole() {
|
|
21
|
+
// old phantomjs does not have bind function
|
|
22
|
+
const hasBind = !!console.log.bind as boolean
|
|
23
|
+
if (hasBind) {
|
|
24
|
+
return {
|
|
25
|
+
// Node@9.3 or below has `console.debug = undefined` or it doesn't log
|
|
26
|
+
// Should use `console.log()` in those case.
|
|
27
|
+
debug: (isConsoleDebugAvailable() ? console.debug : console.log).bind(console),
|
|
28
|
+
// the `typeof` guards against IE where `console.log.apply()`
|
|
29
|
+
// results in error `Object doesn't support property or method 'apply'`
|
|
30
|
+
info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
|
|
31
|
+
warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
|
|
32
|
+
error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return {
|
|
37
|
+
debug: buildFn(isConsoleDebugAvailable() ? 'debug' : 'log'),
|
|
38
|
+
info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
|
|
39
|
+
warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
|
|
40
|
+
error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// istanbul ignore next
|
|
46
|
+
function buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {
|
|
47
|
+
return function (...args: any[]) { console[name](...args) }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export type ConsoleLogFormatter = LogFormatter<any[]>
|
|
52
|
+
export type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }
|
|
53
|
+
export type ConsoleLogReporterOptions = LogReporterOptions<any[]>
|
|
54
|
+
|
|
55
|
+
export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {
|
|
56
|
+
const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)
|
|
57
|
+
if (!polyfill.console) polyfill.console = buildPolyfillConsole()
|
|
58
|
+
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
id,
|
|
61
|
+
isConsoleReporter: true,
|
|
62
|
+
get formatter() { return formatter },
|
|
63
|
+
get filter() { return filter },
|
|
64
|
+
console: polyfill.console,
|
|
65
|
+
write(entry: LogEntry) {
|
|
66
|
+
if (filter && !filter(entry)) return
|
|
67
|
+
const values = formatter(entry)
|
|
68
|
+
const method = toConsoleMethod(entry.level)
|
|
69
|
+
this.console[method](...values)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
package/ts/errors.ts
CHANGED
|
@@ -10,15 +10,3 @@ export class InvalidId extends StandardLogError {
|
|
|
10
10
|
super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
export class ProhibitedDuringProduction extends StandardLogError {
|
|
15
|
-
constructor(public action: string, options?: IsoError.Options) {
|
|
16
|
-
super(`Cannot perform ${action} during production`, options)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class InvalidEnvVar extends StandardLogError {
|
|
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
|
-
}
|
|
24
|
-
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import ms from 'ms'
|
|
2
|
+
import { upperCase } from 'upper-case'
|
|
3
|
+
import { toLogLevelName } from './logLevels.js'
|
|
4
|
+
import type { LogEntry } from './types.js'
|
|
2
5
|
|
|
3
6
|
export type TimestampFormat = 'none' | 'iso' | 'elapsed'
|
|
4
7
|
|
|
@@ -9,7 +12,7 @@ export function createTimestampFormatter(format: TimestampFormat) {
|
|
|
9
12
|
case 'iso':
|
|
10
13
|
return (timestamp: Date) => timestamp.toISOString()
|
|
11
14
|
case 'elapsed': {
|
|
12
|
-
let lastTick: number
|
|
15
|
+
let lastTick: number
|
|
13
16
|
return (timestamp: Date) => {
|
|
14
17
|
const newTick = timestamp.getTime()
|
|
15
18
|
const result = ms(lastTick === undefined ? 0 : newTick - lastTick)
|
|
@@ -19,3 +22,11 @@ export function createTimestampFormatter(format: TimestampFormat) {
|
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
|
|
26
|
+
export function formatLogLevel(level: number) {
|
|
27
|
+
return `(${upperCase(toLogLevelName(level))})`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {
|
|
31
|
+
return [timestamp.toISOString(), id, formatLogLevel(level), ...args]
|
|
32
|
+
}
|
package/ts/index.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './config.js'
|
|
3
|
-
export * from './configForTest.js'
|
|
4
|
-
export * from './console/index.js'
|
|
5
|
-
export * from './customLogLevel.js'
|
|
1
|
+
export * from './console.js'
|
|
6
2
|
export * from './errors.js'
|
|
7
|
-
export * from './formatter
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './logReporter.js'
|
|
12
|
-
export * from './memory/index.js'
|
|
13
|
-
export * from './shouldLog.js'
|
|
14
|
-
export * from './suppressLogs.js'
|
|
3
|
+
export * from './formatter.js'
|
|
4
|
+
export * from './logLevels.js'
|
|
5
|
+
export * from './memory.js'
|
|
6
|
+
export * from './standardLog.js'
|
|
15
7
|
export * from './types.js'
|
|
16
|
-
export * from './utils.js'
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
export const logLevels = {
|
|
3
2
|
/**
|
|
4
3
|
* none: 0
|
|
@@ -52,6 +51,24 @@ export const logLevels = {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
|
-
*
|
|
54
|
+
* Convert default log level value to log level name.
|
|
55
|
+
*/
|
|
56
|
+
export function toLogLevelName(level: number) {
|
|
57
|
+
if (level <= 100) return 'emergency'
|
|
58
|
+
if (level <= 200) return 'alert'
|
|
59
|
+
if (level <= 300) return 'critical'
|
|
60
|
+
if (level <= 400) return 'error'
|
|
61
|
+
if (level <= 500) return 'warn'
|
|
62
|
+
if (level <= 600) return 'notice'
|
|
63
|
+
if (level <= 700) return 'info'
|
|
64
|
+
if (level <= 800) return 'debug'
|
|
65
|
+
if (level <= 900) return 'trace'
|
|
66
|
+
return 'planck'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Convert default log level name to log level value.
|
|
56
71
|
*/
|
|
57
|
-
export
|
|
72
|
+
export function toLogLevel(name: string) {
|
|
73
|
+
return (logLevels as any)[name.toLocaleLowerCase()]
|
|
74
|
+
}
|
package/ts/logStore.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import { mapKey, reduceByKey, reduceKey } from 'type-plus'
|
|
3
|
+
import { createConsoleLogReporter } from './console.js'
|
|
4
|
+
import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'
|
|
5
|
+
import type { Logger, LogLevel, LogReporter, StandardLogOptions } from './types.js'
|
|
6
|
+
|
|
7
|
+
export function createLogStore(options: StandardLogOptions): LogStore {
|
|
8
|
+
return {
|
|
9
|
+
loggers: {},
|
|
10
|
+
reporters: options.reporters || [createConsoleLogReporter()],
|
|
11
|
+
logLevel: options.logLevel,
|
|
12
|
+
logLevelStore: logLevelStore(options)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface LogStore {
|
|
17
|
+
loggers: Record<string, Logger>,
|
|
18
|
+
reporters: LogReporter[],
|
|
19
|
+
logLevel: LogLevel,
|
|
20
|
+
logLevelStore: ReturnType<typeof logLevelStore>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LogLevelStoreOptions {
|
|
24
|
+
customLevels?: Record<string, number>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function logLevelStore(options: LogLevelStoreOptions) {
|
|
28
|
+
const customLevels = options.customLevels || {}
|
|
29
|
+
|
|
30
|
+
const store = {
|
|
31
|
+
customLevels,
|
|
32
|
+
customLevelsReverse: reduceByKey(customLevels, (p, k) => {
|
|
33
|
+
p[customLevels[k]] = k
|
|
34
|
+
return p
|
|
35
|
+
}, {} as Record<number, string>)
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
getName(level: number) {
|
|
39
|
+
return store.customLevelsReverse[level] ?? toLogLevelName(level)
|
|
40
|
+
},
|
|
41
|
+
getLevel(name: string) {
|
|
42
|
+
return store.customLevels[name] ?? toLogLevel(name)
|
|
43
|
+
},
|
|
44
|
+
getAllLevels() {
|
|
45
|
+
return reduceKey(logLevels, (result, name) => {
|
|
46
|
+
if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })
|
|
47
|
+
|
|
48
|
+
return result
|
|
49
|
+
}, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/ts/logger.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { StackTraceMeta } from '@just-func/types'
|
|
2
|
+
import { RequiredPick } from 'type-plus'
|
|
3
|
+
import { InvalidId } from './errors.js'
|
|
4
|
+
import { logLevels } from './logLevels.js'
|
|
5
|
+
import { LogStore } from './logStore.js'
|
|
6
|
+
import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'
|
|
7
|
+
import { LogLevel } from './types.js'
|
|
8
|
+
|
|
9
|
+
export function createLogger<T extends string = LogMethodNames>(
|
|
10
|
+
[store, id, { level, writeTo = () => true }]: [LogStore, string, RequiredPick<LoggerOptions, 'level'>],
|
|
11
|
+
meta?: StackTraceMeta
|
|
12
|
+
): Logger {
|
|
13
|
+
validateId(id, meta)
|
|
14
|
+
const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'
|
|
15
|
+
? [id => id === writeTo, store.reporters]
|
|
16
|
+
: writeTo instanceof RegExp
|
|
17
|
+
? [id => writeTo.test(id), store.reporters]
|
|
18
|
+
: typeof writeTo === 'function'
|
|
19
|
+
? [writeTo, store.reporters]
|
|
20
|
+
: [() => true, [writeTo]]
|
|
21
|
+
|
|
22
|
+
function write(entry: LogEntry) {
|
|
23
|
+
writeToReporters(reporters, entry, filter)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const logger = {
|
|
27
|
+
level,
|
|
28
|
+
write
|
|
29
|
+
} as any
|
|
30
|
+
|
|
31
|
+
Object.defineProperties(logger, {
|
|
32
|
+
id: { value: id, writable: false },
|
|
33
|
+
count: {
|
|
34
|
+
writable: false,
|
|
35
|
+
value: ((counter) => (...args: any[]) => {
|
|
36
|
+
const level = logLevels.debug
|
|
37
|
+
if (shouldLog(store, level, logger.level))
|
|
38
|
+
write({
|
|
39
|
+
id,
|
|
40
|
+
level,
|
|
41
|
+
args: [++counter, ...args],
|
|
42
|
+
timestamp: new Date()
|
|
43
|
+
})
|
|
44
|
+
})(0)
|
|
45
|
+
},
|
|
46
|
+
on: {
|
|
47
|
+
writable: false,
|
|
48
|
+
value: (level: number | T, logFn: LogFunction) => {
|
|
49
|
+
const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level
|
|
50
|
+
if (shouldLog(store, logLevel, logger.level)) {
|
|
51
|
+
const methodName = store.logLevelStore.getName(logLevel)
|
|
52
|
+
const bindedMethod = logger[methodName].bind(logger)
|
|
53
|
+
const result = logFn(bindedMethod)
|
|
54
|
+
if (result) bindedMethod(result)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
|
|
60
|
+
Object.defineProperty(logger, name, {
|
|
61
|
+
writable: false,
|
|
62
|
+
value: (...args: any[]) => {
|
|
63
|
+
if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
return logger
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function validateId(id: string, meta?: StackTraceMeta) {
|
|
71
|
+
if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id)) throw new InvalidId(id, meta)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {
|
|
75
|
+
reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Determines should you log.
|
|
80
|
+
* @param loggerLevel Log level of the logger.
|
|
81
|
+
* It can be undefined which the global log level will be used.
|
|
82
|
+
*/
|
|
83
|
+
function shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {
|
|
84
|
+
return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)
|
|
85
|
+
}
|
package/ts/memory.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { required } from 'type-plus'
|
|
2
|
+
import { toInspectLogEntry } from './platform.js'
|
|
3
|
+
import { formatLogLevel } from './formatter.js'
|
|
4
|
+
import type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
|
|
5
|
+
|
|
6
|
+
export type MemoryLogReporter = LogReporter<LogEntry> & {
|
|
7
|
+
logs: LogEntry[],
|
|
8
|
+
/**
|
|
9
|
+
* Gets a simple log message for testing.
|
|
10
|
+
* The message only contains arguments for each log entry.
|
|
11
|
+
*/
|
|
12
|
+
getLogMessage(): string,
|
|
13
|
+
getLogMessageWithLevel(): string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type MemoryLogFormatter = LogFormatter<LogEntry>
|
|
17
|
+
|
|
18
|
+
export function toMessageWithLevel(logs: LogEntry[]) {
|
|
19
|
+
return logs.map(toInspectLogEntry)
|
|
20
|
+
.map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
|
|
21
|
+
.join('\n')
|
|
22
|
+
// if it has more than this log,
|
|
23
|
+
// we assume it is running under tests,
|
|
24
|
+
// and remove this log to simplify testing.
|
|
25
|
+
.replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {
|
|
29
|
+
const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)
|
|
30
|
+
const logs: LogEntry[] = []
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
id,
|
|
33
|
+
get formatter() { return formatter },
|
|
34
|
+
get filter() { return filter },
|
|
35
|
+
logs,
|
|
36
|
+
write(entry: LogEntry) {
|
|
37
|
+
if (filter && !filter(entry)) return
|
|
38
|
+
logs.push(formatter(entry))
|
|
39
|
+
},
|
|
40
|
+
getLogMessage() {
|
|
41
|
+
return logs.map(toInspectLogEntry)
|
|
42
|
+
.map(log => log.args.join(' '))
|
|
43
|
+
.join('\n')
|
|
44
|
+
},
|
|
45
|
+
getLogMessageWithLevel() { return toMessageWithLevel(logs) }
|
|
46
|
+
})
|
|
47
|
+
}
|
package/ts/platform.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { inspect } from 'util'
|
|
2
|
+
import type { ConsoleLike, LogEntry } from './types.js'
|
|
3
|
+
|
|
4
|
+
export function semverGt(versionString: string, version: [number, number, number]) {
|
|
5
|
+
const actual = versionString.split('.').reverse().reduce((p, v, i) => {
|
|
6
|
+
p += Number.parseInt(v, 10) * Math.pow(100, i)
|
|
7
|
+
return p
|
|
8
|
+
}, 0)
|
|
9
|
+
|
|
10
|
+
return actual > (version[0] * 10000 + version[1] * 100 + version[2])
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// istanbul ignore next
|
|
14
|
+
export function isConsoleDebugAvailable() {
|
|
15
|
+
// without this, systemJs will complain `process is not defined`
|
|
16
|
+
if (!global.process) return true
|
|
17
|
+
const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
|
|
18
|
+
return semverGt(versionString, [9, 3, 0])
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const toInspectLogEntry = (e: LogEntry) => (
|
|
22
|
+
e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
|
|
23
|
+
e)
|
|
24
|
+
|
|
25
|
+
export const polyfill: { console?: ConsoleLike } = {}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { StackTraceMeta } from '@just-func/types'
|
|
2
|
+
import { required } from 'type-plus'
|
|
3
|
+
import { createLogger } from './logger.js'
|
|
4
|
+
import { logLevels } from './logLevels.js'
|
|
5
|
+
import { createLogStore } from './logStore.js'
|
|
6
|
+
import { createMemoryLogReporter } from './memory.js'
|
|
7
|
+
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'
|
|
8
|
+
|
|
9
|
+
export interface StandardLog<N extends string = LogMethodNames> {
|
|
10
|
+
readonly logLevel: number,
|
|
11
|
+
toLogLevelName(level: number): string,
|
|
12
|
+
toLogLevel(name: N): number,
|
|
13
|
+
getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createStandardLog<N extends string = LogMethodNames>(
|
|
17
|
+
options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta
|
|
18
|
+
): Readonly<StandardLog<N>> {
|
|
19
|
+
const store = createLogStore(required({ logLevel: logLevels.info }, options))
|
|
20
|
+
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
get logLevel() { return store.logLevel },
|
|
23
|
+
|
|
24
|
+
toLogLevelName(level: number) {
|
|
25
|
+
return store.logLevelStore.getName(level)
|
|
26
|
+
},
|
|
27
|
+
toLogLevel(name: string) {
|
|
28
|
+
return store.logLevelStore.getLevel(name)
|
|
29
|
+
},
|
|
30
|
+
getLogger([id, options]: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N> {
|
|
31
|
+
if (store.loggers[id]) return store.loggers[id] as any
|
|
32
|
+
const opt = required({ level: store.logLevel }, options)
|
|
33
|
+
return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta }) as any
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createStandardLogForTest(logLevel: LogLevel = logLevels.debug) {
|
|
39
|
+
const reporter = createMemoryLogReporter()
|
|
40
|
+
const standardLog = createStandardLog({ reporters: [reporter], logLevel })
|
|
41
|
+
return { ...standardLog, reporter }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Suppress logging within the code block.
|
|
46
|
+
*/
|
|
47
|
+
export function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R
|
|
48
|
+
export function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {
|
|
49
|
+
const origLevels = logs.map(l => l.level)
|
|
50
|
+
logs.forEach(l => l.level = logLevels.none)
|
|
51
|
+
const result = block()
|
|
52
|
+
logs.forEach((l, i) => l.level = origLevels[i])
|
|
53
|
+
return result
|
|
54
|
+
}
|