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/README.md
CHANGED
|
@@ -3,50 +3,61 @@
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![NPM downloads][downloads-image]][downloads-url]
|
|
5
5
|
|
|
6
|
-
[![
|
|
6
|
+
[![GitHub NodeJS][github-nodejs]][github-action-url]
|
|
7
7
|
[![Codecov][codecov-image]][codecov-url]
|
|
8
|
-
[![Codacy Grade Badge][codacy-grade]][codacy-grade-url]
|
|
9
|
-
[![Codacy Coverage Badge][codacy-coverage]][codacy-coverage-url]
|
|
10
|
-
|
|
11
|
-
[![Greenkeeper][greenkeeper-image]][greenkeeper-url]
|
|
12
8
|
|
|
13
9
|
[![Visual Studio Code][vscode-image]][vscode-url]
|
|
14
|
-
[![Wallaby.js][wallaby-image]][wallaby-url]
|
|
15
10
|
|
|
16
|
-
`standard-log` is a powerful and extensible logging library.
|
|
11
|
+
[`standard-log`] is a powerful and extensible logging library.
|
|
12
|
+
|
|
13
|
+
## New in 9.0
|
|
14
|
+
|
|
15
|
+
[`standard-log`] 9.0 is a trimmed down version that focus more on security and support the micro-app paradigm.
|
|
16
|
+
|
|
17
|
+
The key changes are:
|
|
18
|
+
|
|
19
|
+
- No side effects: application calling `createStandardLog()` gets a completely enclosed log system.
|
|
20
|
+
- Immutable: after the log system can be configured when calling `createStandardLog()`.\
|
|
21
|
+
But after that, the system is immutable and cannot be changed.\
|
|
22
|
+
|
|
23
|
+
For the full list of changes, please check the [change log](./CHANGELOG.md).
|
|
17
24
|
|
|
18
25
|
## Key features
|
|
19
26
|
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
+
- Support micro-app with isolated log system.
|
|
28
|
+
- Create multiple loggers for different part of your application.
|
|
29
|
+
- Provide multiple log levels out of the box.
|
|
30
|
+
- Support custom log levels.
|
|
31
|
+
- Three levels of log level controls: log system, logger, and log method.
|
|
32
|
+
- Send logs to multiple reporters, e.g. console, file, memory, or remote service.
|
|
33
|
+
- Custom formatting and filtering for each reporter.
|
|
34
|
+
- Security focus. After the system is created, it cannot be changed.
|
|
35
|
+
- Compliant with the [`just-func`] paradigm.
|
|
27
36
|
|
|
28
37
|
## Usage
|
|
29
38
|
|
|
30
|
-
To use `standard-log
|
|
39
|
+
To use [`standard-log`], you first create a new log system.
|
|
31
40
|
|
|
32
41
|
```ts
|
|
33
|
-
import {
|
|
42
|
+
import { createStandardLog } from 'standard-log'
|
|
43
|
+
|
|
44
|
+
const standardLog = createStandarLog(/* options */)
|
|
34
45
|
|
|
35
|
-
const log = getLogger('my-app')
|
|
46
|
+
const log = standardLog.getLogger(['my-app'])
|
|
36
47
|
|
|
37
|
-
log.error('error')
|
|
38
|
-
log.warn('warn')
|
|
39
|
-
log.info('info')
|
|
48
|
+
log.error('error message')
|
|
49
|
+
log.warn('warn message')
|
|
50
|
+
log.info('info message')
|
|
40
51
|
// by default debug() will not be printed
|
|
41
52
|
// because production mode defaults log level to `info`
|
|
42
|
-
log.debug('debug')
|
|
53
|
+
log.debug('debug message')
|
|
43
54
|
```
|
|
44
55
|
|
|
45
|
-

|
|
46
57
|
|
|
47
|
-
(above is logged with `standard-log-color`
|
|
58
|
+
(above is logged with `standard-log-color`)
|
|
48
59
|
|
|
49
|
-
You can configure a logger by doing `getLogger(id, options)`:
|
|
60
|
+
You can configure a logger by doing `getLogger([id, options])`:
|
|
50
61
|
|
|
51
62
|
`options.level: number`:
|
|
52
63
|
|
|
@@ -56,41 +67,12 @@ Log level of this logger.
|
|
|
56
67
|
|
|
57
68
|
Only log to specific reporter(s).
|
|
58
69
|
|
|
59
|
-
### Mode
|
|
60
|
-
|
|
61
|
-
By default, `standard-log` runs in production mode.
|
|
62
|
-
You can change it programmatically:
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
import { config } from 'standard-log'
|
|
66
|
-
|
|
67
|
-
config({ mode: 'production' }) // or 'development', 'test'
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
or by setting the environment variable `STANDARD_LOG`.
|
|
71
|
-
|
|
72
|
-
`production` mode:
|
|
73
|
-
|
|
74
|
-
- `config()` can only be called once.
|
|
75
|
-
- configuration is protected from tempering.
|
|
76
|
-
|
|
77
|
-
`development` mode:
|
|
78
|
-
|
|
79
|
-
- a warning is emitted when calling `config()` or log for the first time.
|
|
80
|
-
|
|
81
|
-
`test` mode:
|
|
82
|
-
|
|
83
|
-
- no warning is emitted
|
|
84
|
-
|
|
85
70
|
### Log Level
|
|
86
71
|
|
|
87
72
|
`standard-log` log level defaults to `logLevels.info`.
|
|
88
73
|
It comes with many log levels out of the box:
|
|
89
74
|
|
|
90
75
|
```ts
|
|
91
|
-
import { getLogger } from 'standard-log'
|
|
92
|
-
|
|
93
|
-
const log = getLogger('x')
|
|
94
76
|
log.emergency('msg')
|
|
95
77
|
log.alert('msg')
|
|
96
78
|
log.critical('msg')
|
|
@@ -108,16 +90,16 @@ When sending logs to console, they are mapped to `info`, `warn`, `error`, and `d
|
|
|
108
90
|
You can also add your own custom levels:
|
|
109
91
|
|
|
110
92
|
```ts
|
|
111
|
-
import {
|
|
93
|
+
import { createStandardLog } from 'standard-log'
|
|
112
94
|
|
|
113
|
-
|
|
95
|
+
const standardLog = createStandardLog({
|
|
114
96
|
customLevels: {
|
|
115
97
|
'important': logLevel.warn + 1,
|
|
116
98
|
'silly': logLevel.debug + 1
|
|
117
99
|
}
|
|
118
100
|
})
|
|
119
101
|
|
|
120
|
-
const log = getLogger
|
|
102
|
+
const log = standardLog.getLogger('custom')
|
|
121
103
|
log.important('this is an important message')
|
|
122
104
|
log.silly('oh silly')
|
|
123
105
|
```
|
|
@@ -128,14 +110,14 @@ Besides printing the logs to console,
|
|
|
128
110
|
you can use different reporters to save the logs in memory, file, service, or others.
|
|
129
111
|
|
|
130
112
|
```ts
|
|
131
|
-
import {
|
|
113
|
+
import { createStandardLog, createConsoleLogReporter, createMemoryLogReporter } from 'standard-log'
|
|
132
114
|
|
|
133
|
-
|
|
115
|
+
createStandardLog({
|
|
134
116
|
reporters: [createConsoleLogReporter(), createMemoryLogReporter()]
|
|
135
117
|
})
|
|
136
118
|
```
|
|
137
119
|
|
|
138
|
-
Some reporters
|
|
120
|
+
Some reporters allow you to format the logs and/or filter them.
|
|
139
121
|
Using the console log reporter as an example:
|
|
140
122
|
|
|
141
123
|
```ts
|
|
@@ -149,37 +131,10 @@ createConsoleLogReporter({
|
|
|
149
131
|
|
|
150
132
|
Here are some additional reporters:
|
|
151
133
|
|
|
152
|
-
- [`standard-log-color`]
|
|
134
|
+
- [`standard-log-color`]
|
|
153
135
|
- `standard-log-file` (TODO)
|
|
154
136
|
- `standard-log-syslog` (TODO)
|
|
155
137
|
|
|
156
|
-
### Capture Logs
|
|
157
|
-
|
|
158
|
-
You can temporarily capture logs by `captureLogs()`.
|
|
159
|
-
This is useful when you are writing tests.
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
import { getLogger, captureLogs } from 'standard-log'
|
|
163
|
-
import a from 'assertron'
|
|
164
|
-
|
|
165
|
-
test('your test', () => {
|
|
166
|
-
function foo() {
|
|
167
|
-
const log = getLogger('foo logger')
|
|
168
|
-
// this log will not be sent to normal reporters
|
|
169
|
-
log.info('some messages')
|
|
170
|
-
return 'miku'
|
|
171
|
-
}
|
|
172
|
-
const log = getLogger('foo logger')
|
|
173
|
-
const [result, logs] = captureLogs(log, foo)
|
|
174
|
-
|
|
175
|
-
a.satisfies(logs, [{ args: ['some messages']}])
|
|
176
|
-
a.equals('miku', result)
|
|
177
|
-
|
|
178
|
-
// rewriting the logs
|
|
179
|
-
logs.forEach(entry => log.write(entry))
|
|
180
|
-
})
|
|
181
|
-
```
|
|
182
|
-
|
|
183
138
|
### Suppress log
|
|
184
139
|
|
|
185
140
|
You can temporarily suppress logs by `suppressLogs()`.
|
|
@@ -193,66 +148,35 @@ const log = getLogger('some logger')
|
|
|
193
148
|
suppressLogs(() => log.info('not logged'), log)
|
|
194
149
|
```
|
|
195
150
|
|
|
196
|
-
##
|
|
197
|
-
|
|
198
|
-
The package comes with a pre-bundled file under `dist`.
|
|
199
|
-
To use it, you also need to load [`global-store`](https://github.com/unional/global-store)
|
|
200
|
-
|
|
201
|
-
If you are building a library and bundle it, make sure you mark `global-store` as externals.
|
|
202
|
-
You can check out [`global-store`](https://github.com/unional/global-store) for more information.
|
|
203
|
-
|
|
204
|
-
## testing
|
|
151
|
+
## Testing
|
|
205
152
|
|
|
206
153
|
During test,
|
|
207
|
-
you should
|
|
154
|
+
you should use `createStandardLogForTest` which includes a `MemoryReporter` to capture the logs.
|
|
208
155
|
|
|
209
156
|
```ts
|
|
210
|
-
import {
|
|
157
|
+
import { createStandardLogForTest, createMemoryReporter } from 'standard-log'
|
|
211
158
|
|
|
212
159
|
test('your test', () => {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
reporters: [reporter],
|
|
216
|
-
mode: 'test'
|
|
217
|
-
})
|
|
160
|
+
const standardLog = createStandardLogForTest()
|
|
161
|
+
yourApp.standardLog = standardLog
|
|
218
162
|
|
|
219
|
-
|
|
163
|
+
// do your thing...
|
|
220
164
|
|
|
221
|
-
const messages = reporter.getLogMessage() // or getLogMessageWithLevel()
|
|
165
|
+
const messages = standardLog.reporter.getLogMessage() // or getLogMessageWithLevel()
|
|
222
166
|
// validate the message if you want to
|
|
223
167
|
})
|
|
224
168
|
```
|
|
225
169
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
test('your test', () => {
|
|
232
|
-
const { reporter } = configForTest()
|
|
233
|
-
|
|
234
|
-
// do your thing...
|
|
235
|
-
})
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
[npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
|
|
239
|
-
[npm-url]: https://www.npmjs.com/package/standard-log
|
|
170
|
+
[`just-func`]: https://github.com/justland/just-func-typescript
|
|
171
|
+
[`standard-log`]: https://github.com/unional/standard-log
|
|
172
|
+
[`standard-log-color`]: https://github.com/unional/standard-log/tree/master/packages/color
|
|
173
|
+
[codecov-image]: https://codecov.io/gh/unional/standard-log/branch/master/graph/badge.svg
|
|
174
|
+
[codecov-url]: https://codecov.io/gh/unional/standard-log
|
|
240
175
|
[downloads-image]: https://img.shields.io/npm/dm/standard-log.svg?style=flat
|
|
241
176
|
[downloads-url]: https://npmjs.org/package/standard-log
|
|
242
|
-
|
|
243
|
-
[github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
|
|
244
177
|
[github-action-url]: https://github.com/unional/standard-log/actions
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
[
|
|
248
|
-
[codacy-grade-url]: https://www.codacy.com/app/homawong/standard-log?utm_source=github.com&utm_medium=referral&utm_content=unional/standard-log&utm_campaign=Badge_Grade
|
|
249
|
-
[codacy-coverage]: https://api.codacy.com/project/badge/Coverage/707f89609508442486050d207ec5bd78
|
|
250
|
-
[codacy-coverage-url]: https://www.codacy.com/manual/homawong/standard-log?utm_source=github.com&utm_medium=referral&utm_content=unional/standard-log&utm_campaign=Badge_Coverage
|
|
251
|
-
|
|
252
|
-
[greenkeeper-image]: https://badges.greenkeeper.io/unional/standard-log.svg
|
|
253
|
-
[greenkeeper-url]: https://greenkeeper.io/
|
|
254
|
-
|
|
178
|
+
[github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
|
|
179
|
+
[npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
|
|
180
|
+
[npm-url]: https://www.npmjs.com/package/standard-log
|
|
255
181
|
[vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
|
|
256
182
|
[vscode-url]: https://code.visualstudio.com/
|
|
257
|
-
[wallaby-image]: https://img.shields.io/badge/wallaby.js-configured-green.svg
|
|
258
|
-
[wallaby-url]: https://wallabyjs.com
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LogFormatter, LogReporter, LogReporterOptions } from '
|
|
2
|
-
|
|
1
|
+
import type { ConsoleLike, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
|
|
2
|
+
export declare function toConsoleMethod(level: number): "error" | "warn" | "info" | "debug";
|
|
3
|
+
export declare type ConsoleLogFormatter = LogFormatter<any[]>;
|
|
3
4
|
export declare type ConsoleLogReporter = LogReporter<any[]> & {
|
|
4
|
-
console:
|
|
5
|
+
console: ConsoleLike;
|
|
5
6
|
};
|
|
6
|
-
export declare type ConsoleLogFormatter = LogFormatter<any[]>;
|
|
7
7
|
export declare type ConsoleLogReporterOptions = LogReporterOptions<any[]>;
|
|
8
8
|
export declare function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter;
|
|
9
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAY,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,uCAS5C;AAmCD,oBAAY,mBAAmB,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;AACrD,oBAAY,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;AAC9E,oBAAY,yBAAyB,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAA;AAEjE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAiBhG"}
|
package/cjs/console.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConsoleLogReporter = exports.toConsoleMethod = void 0;
|
|
4
|
+
var type_plus_1 = require("type-plus");
|
|
5
|
+
var logLevels_js_1 = require("./logLevels.js");
|
|
6
|
+
var platform_js_1 = require("./platform.js");
|
|
7
|
+
var formatter_js_1 = require("./formatter.js");
|
|
8
|
+
function toConsoleMethod(level) {
|
|
9
|
+
switch (true) {
|
|
10
|
+
// edge case in case none is somehow written
|
|
11
|
+
case (level <= 0): return 'debug';
|
|
12
|
+
case (level <= logLevels_js_1.logLevels.error): return 'error';
|
|
13
|
+
case (level <= logLevels_js_1.logLevels.warn): return 'warn';
|
|
14
|
+
case (level <= logLevels_js_1.logLevels.info): return 'info';
|
|
15
|
+
default: return 'debug';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.toConsoleMethod = toConsoleMethod;
|
|
19
|
+
// istanbul ignore next
|
|
20
|
+
/* eslint-disable no-console */
|
|
21
|
+
function buildPolyfillConsole() {
|
|
22
|
+
// old phantomjs does not have bind function
|
|
23
|
+
var hasBind = !!console.log.bind;
|
|
24
|
+
if (hasBind) {
|
|
25
|
+
return {
|
|
26
|
+
// Node@9.3 or below has `console.debug = undefined` or it doesn't log
|
|
27
|
+
// Should use `console.log()` in those case.
|
|
28
|
+
debug: ((0, platform_js_1.isConsoleDebugAvailable)() ? console.debug : console.log).bind(console),
|
|
29
|
+
// the `typeof` guards against IE where `console.log.apply()`
|
|
30
|
+
// results in error `Object doesn't support property or method 'apply'`
|
|
31
|
+
info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
|
|
32
|
+
warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
|
|
33
|
+
error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return {
|
|
38
|
+
debug: buildFn((0, platform_js_1.isConsoleDebugAvailable)() ? 'debug' : 'log'),
|
|
39
|
+
info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
|
|
40
|
+
warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
|
|
41
|
+
error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// istanbul ignore next
|
|
46
|
+
function buildFn(name) {
|
|
47
|
+
return function () {
|
|
48
|
+
var args = [];
|
|
49
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
50
|
+
args[_i] = arguments[_i];
|
|
51
|
+
}
|
|
52
|
+
console[name].apply(console, args);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createConsoleLogReporter(options) {
|
|
56
|
+
var _a = (0, type_plus_1.required)({ id: 'console', formatter: formatter_js_1.plainLogFormatter }, options), id = _a.id, formatter = _a.formatter, filter = _a.filter;
|
|
57
|
+
if (!platform_js_1.polyfill.console)
|
|
58
|
+
platform_js_1.polyfill.console = buildPolyfillConsole();
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
id: id,
|
|
61
|
+
isConsoleReporter: true,
|
|
62
|
+
get formatter() { return formatter; },
|
|
63
|
+
get filter() { return filter; },
|
|
64
|
+
console: platform_js_1.polyfill.console,
|
|
65
|
+
write: function (entry) {
|
|
66
|
+
var _a;
|
|
67
|
+
if (filter && !filter(entry))
|
|
68
|
+
return;
|
|
69
|
+
var values = formatter(entry);
|
|
70
|
+
var method = toConsoleMethod(entry.level);
|
|
71
|
+
(_a = this.console)[method].apply(_a, values);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.createConsoleLogReporter = createConsoleLogReporter;
|
|
76
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,+CAA0C;AAC1C,6CAAiE;AACjE,+CAAkD;AAGlD,SAAgB,eAAe,CAAC,KAAa;IAC3C,QAAQ,IAAI,EAAE;QACZ,4CAA4C;QAC5C,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QACjC,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QAC/C,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,MAAM,CAAA;QAC7C,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,MAAM,CAAA;QAC7C,OAAO,CAAC,CAAC,OAAO,OAAO,CAAA;KACxB;AACH,CAAC;AATD,0CASC;AAED,uBAAuB;AACvB,+BAA+B;AAC/B,SAAS,oBAAoB;IAC3B,4CAA4C;IAC5C,IAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAe,CAAA;IAC7C,IAAI,OAAO,EAAE;QACX,OAAO;YACL,sEAAsE;YACtE,4CAA4C;YAC5C,KAAK,EAAE,CAAC,IAAA,qCAAuB,GAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC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OAAO,CAAC,IAAI,CAAC,OAAb,OAAO,EAAU,IAAI,EAAC;IAAC,CAAC,CAAA;AAC7D,CAAC;AAOD,SAAgB,wBAAwB,CAAC,OAAmC;IACpE,IAAA,KAA4B,IAAA,oBAAQ,EAAC,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,gCAAiB,EAAE,EAAE,OAAO,CAAC,EAA5F,EAAE,QAAA,EAAE,SAAS,eAAA,EAAE,MAAM,YAAuE,CAAA;IACpG,IAAI,CAAC,sBAAQ,CAAC,OAAO;QAAE,sBAAQ,CAAC,OAAO,GAAG,oBAAoB,EAAE,CAAA;IAEhE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,IAAA;QACF,iBAAiB,EAAE,IAAI;QACvB,IAAI,SAAS,KAAK,OAAO,SAAS,CAAA,CAAC,CAAC;QACpC,IAAI,MAAM,KAAK,OAAO,MAAM,CAAA,CAAC,CAAC;QAC9B,OAAO,EAAE,sBAAQ,CAAC,OAAO;QACzB,KAAK,EAAL,UAAM,KAAe;;YACnB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,IAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,MAAM,CAAC,WAAI,MAAM,EAAC;QACjC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAjBD,4DAiBC","sourcesContent":["import { required } from 'type-plus'\nimport { logLevels } from './logLevels.js'\nimport { isConsoleDebugAvailable, polyfill } from './platform.js'\nimport { plainLogFormatter } from './formatter.js'\nimport type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport function toConsoleMethod(level: number) {\n switch (true) {\n // edge case in case none is somehow written\n case (level <= 0): return 'debug'\n case (level <= logLevels.error): return 'error'\n case (level <= logLevels.warn): return 'warn'\n case (level <= logLevels.info): return 'info'\n default: return 'debug'\n }\n}\n\n// istanbul ignore next\n/* eslint-disable no-console */\nfunction buildPolyfillConsole() {\n // old phantomjs does not have bind function\n const hasBind = !!console.log.bind as boolean\n if (hasBind) {\n return {\n // Node@9.3 or below has `console.debug = undefined` or it doesn't log\n // Should use `console.log()` in those case.\n debug: (isConsoleDebugAvailable() ? console.debug : console.log).bind(console),\n // the `typeof` guards against IE where `console.log.apply()`\n // results in error `Object doesn't support property or method 'apply'`\n info: (typeof console.info === 'function' ? console.info : console.log).bind(console),\n warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),\n error: (typeof console.error === 'function' ? console.error : console.log).bind(console)\n }\n }\n else {\n return {\n debug: buildFn(isConsoleDebugAvailable() ? 'debug' : 'log'),\n info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),\n warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),\n error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),\n }\n }\n}\n\n// istanbul ignore next\nfunction buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {\n return function (...args: any[]) { console[name](...args) }\n}\n\n\nexport type ConsoleLogFormatter = LogFormatter<any[]>\nexport type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }\nexport type ConsoleLogReporterOptions = LogReporterOptions<any[]>\n\nexport function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {\n const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)\n if (!polyfill.console) polyfill.console = buildPolyfillConsole()\n\n return Object.freeze({\n id,\n isConsoleReporter: true,\n get formatter() { return formatter },\n get filter() { return filter },\n console: polyfill.console,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n const values = formatter(entry)\n const method = toConsoleMethod(entry.level)\n this.console[method](...values)\n }\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.spec.d.ts","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var
|
|
7
|
-
var index_js_1 = require("
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, index_js_1.
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
var standardLog_js_1 = require("./standardLog.js");
|
|
4
|
+
var index_js_1 = require("./index.js");
|
|
5
|
+
var platform_js_1 = require("./platform.js");
|
|
6
|
+
describe('toConsoleMethod()', function () {
|
|
7
|
+
it('converts any level to standard console method names: debug, info, warn, error', function () {
|
|
8
|
+
expect((0, index_js_1.toConsoleMethod)(1)).toEqual('error');
|
|
9
|
+
expect((0, index_js_1.toConsoleMethod)(399)).toEqual('error');
|
|
10
|
+
expect((0, index_js_1.toConsoleMethod)(400)).toEqual('error');
|
|
11
|
+
expect((0, index_js_1.toConsoleMethod)(401)).toEqual('warn');
|
|
12
|
+
expect((0, index_js_1.toConsoleMethod)(499)).toEqual('warn');
|
|
13
|
+
expect((0, index_js_1.toConsoleMethod)(500)).toEqual('warn');
|
|
14
|
+
expect((0, index_js_1.toConsoleMethod)(501)).toEqual('info');
|
|
15
|
+
expect((0, index_js_1.toConsoleMethod)(700)).toEqual('info');
|
|
16
|
+
expect((0, index_js_1.toConsoleMethod)(701)).toEqual('debug');
|
|
17
|
+
expect((0, index_js_1.toConsoleMethod)(800)).toEqual('debug');
|
|
18
|
+
expect((0, index_js_1.toConsoleMethod)(801)).toEqual('debug');
|
|
19
|
+
expect((0, index_js_1.toConsoleMethod)(Infinity)).toEqual('debug');
|
|
16
20
|
});
|
|
17
|
-
it('
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(0,
|
|
22
|
-
|
|
23
|
-
var idFormatter = function (entry) { return [entry.id]; };
|
|
24
|
-
test('set formatter during production mode throws', function () {
|
|
25
|
-
(0, index_js_1.config)({ mode: 'production' });
|
|
26
|
-
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
27
|
-
assertron_1.default.throws(function () { return reporter.formatter = idFormatter; }, index_js_1.ProhibitedDuringProduction);
|
|
28
|
-
});
|
|
29
|
-
it('set formatter throws with ssf at call site', function () {
|
|
30
|
-
(0, index_js_1.config)({ mode: 'production' });
|
|
31
|
-
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
32
|
-
var err = assertron_1.default.throws(function () { return reporter.formatter = idFormatter; }, index_js_1.ProhibitedDuringProduction);
|
|
33
|
-
(0, testUtil_js_1.assertSSF)(err, __filename);
|
|
21
|
+
it('converts to debug for 0 (none) or negative (not valid) level', function () {
|
|
22
|
+
// these are invalid input.
|
|
23
|
+
// so instead of hiding them and not logged,
|
|
24
|
+
// log them so that it is easier to discover.
|
|
25
|
+
expect((0, index_js_1.toConsoleMethod)(-1)).toEqual('debug');
|
|
26
|
+
expect((0, index_js_1.toConsoleMethod)(0)).toEqual('debug');
|
|
34
27
|
});
|
|
35
28
|
});
|
|
36
|
-
describe('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
['emergency', 'info', 'warn', 'debug'].forEach(function (level) {
|
|
42
|
-
reporter.write({ id: 'plain', level: index_js_1.logLevels[level], args: ['hello', 'world'], timestamp: new Date() });
|
|
43
|
-
});
|
|
29
|
+
describe('rendering tests', function () {
|
|
30
|
+
test('plain rendering', function () {
|
|
31
|
+
var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
|
|
32
|
+
['emergency', 'info', 'warn', 'debug'].forEach(function (level) {
|
|
33
|
+
reporter.write({ id: 'plain', level: index_js_1.logLevels[level], args: ['hello', 'world'], timestamp: new Date() });
|
|
44
34
|
});
|
|
45
35
|
});
|
|
36
|
+
});
|
|
37
|
+
describe('createConsoleLogReporter', function () {
|
|
38
|
+
var fakeConsole = createFakeConsole();
|
|
39
|
+
beforeEach(function () { return platform_js_1.polyfill.console = fakeConsole = createFakeConsole(); });
|
|
46
40
|
describe('id', function () {
|
|
47
41
|
test('default is "console"', function () {
|
|
48
42
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
@@ -57,7 +51,6 @@ describe('unit tests', function () {
|
|
|
57
51
|
test('error, alert, critical and emergency logs are written to console.error', function () {
|
|
58
52
|
var id = 'log';
|
|
59
53
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
60
|
-
var fakeConsole = reporter.console = createFakeConsole();
|
|
61
54
|
reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
|
|
62
55
|
reporter.write({ id: id, level: index_js_1.logLevels.critical, args: ['critical'], timestamp: new Date() });
|
|
63
56
|
reporter.write({ id: id, level: index_js_1.logLevels.alert, args: ['alert'], timestamp: new Date() });
|
|
@@ -67,14 +60,12 @@ describe('unit tests', function () {
|
|
|
67
60
|
test('warn logs are written to console.warn', function () {
|
|
68
61
|
var id = 'log';
|
|
69
62
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
70
|
-
var fakeConsole = reporter.console = createFakeConsole();
|
|
71
63
|
reporter.write({ id: id, level: index_js_1.logLevels.warn, args: ['warn'], timestamp: new Date() });
|
|
72
64
|
expect(fakeConsole.warns.length).toBe(1);
|
|
73
65
|
});
|
|
74
66
|
test('notice and info logs are written to console.info', function () {
|
|
75
67
|
var id = 'log';
|
|
76
68
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
77
|
-
var fakeConsole = reporter.console = createFakeConsole();
|
|
78
69
|
reporter.write({ id: id, level: index_js_1.logLevels.notice, args: ['notice'], timestamp: new Date() });
|
|
79
70
|
reporter.write({ id: id, level: index_js_1.logLevels.info, args: ['info'], timestamp: new Date() });
|
|
80
71
|
expect(fakeConsole.infos.length).toBe(2);
|
|
@@ -82,7 +73,6 @@ describe('unit tests', function () {
|
|
|
82
73
|
test('debug, trace, and planck logs are written to console.debug', function () {
|
|
83
74
|
var id = 'log';
|
|
84
75
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
85
|
-
var fakeConsole = reporter.console = createFakeConsole();
|
|
86
76
|
reporter.write({ id: id, level: index_js_1.logLevels.debug, args: ['debug'], timestamp: new Date() });
|
|
87
77
|
reporter.write({ id: id, level: index_js_1.logLevels.trace, args: ['trace'], timestamp: new Date() });
|
|
88
78
|
reporter.write({ id: id, level: index_js_1.logLevels.planck, args: ['planck'], timestamp: new Date() });
|
|
@@ -90,19 +80,24 @@ describe('unit tests', function () {
|
|
|
90
80
|
});
|
|
91
81
|
});
|
|
92
82
|
describe('custom logs', function () {
|
|
93
|
-
afterEach(function () { return (0, index_js_1.clearCustomLogLevel)(); });
|
|
94
83
|
test('are written according to their log level value', function () {
|
|
95
|
-
(0, index_js_1.addCustomLogLevel)('high', 50);
|
|
96
|
-
(0, index_js_1.addCustomLogLevel)('important', 450);
|
|
97
|
-
(0, index_js_1.addCustomLogLevel)('interest', 650);
|
|
98
|
-
(0, index_js_1.addCustomLogLevel)('silly', 1000);
|
|
99
84
|
var id = 'log';
|
|
100
85
|
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
var sl = (0, standardLog_js_1.createStandardLog)({
|
|
87
|
+
logLevel: index_js_1.logLevels.all,
|
|
88
|
+
customLevels: {
|
|
89
|
+
'high': 50,
|
|
90
|
+
'important': 450,
|
|
91
|
+
'interest': 650,
|
|
92
|
+
'silly': 1000
|
|
93
|
+
},
|
|
94
|
+
reporters: [reporter]
|
|
95
|
+
});
|
|
96
|
+
var log = sl.getLogger([id]);
|
|
97
|
+
log.high('a');
|
|
98
|
+
log.important('b');
|
|
99
|
+
log.interest('c');
|
|
100
|
+
log.silly('d');
|
|
106
101
|
expect(fakeConsole.errors.length).toBe(1);
|
|
107
102
|
expect(fakeConsole.warns.length).toBe(1);
|
|
108
103
|
expect(fakeConsole.infos.length).toBe(1);
|
|
@@ -114,37 +109,24 @@ describe('unit tests', function () {
|
|
|
114
109
|
test('use specific formatter', function () {
|
|
115
110
|
var id = 'id-only';
|
|
116
111
|
var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter });
|
|
117
|
-
|
|
112
|
+
expect(reporter.formatter).toBe(idFormatter);
|
|
118
113
|
reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
|
|
119
114
|
expect(fakeConsole.errors).toEqual([['id-only']]);
|
|
120
115
|
});
|
|
121
|
-
test('formatter can be changed afterward', function () {
|
|
122
|
-
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
123
|
-
var formatter = reporter.formatter;
|
|
124
|
-
reporter.formatter = idFormatter;
|
|
125
|
-
expect(reporter.formatter).not.toEqual(formatter);
|
|
126
|
-
});
|
|
127
116
|
});
|
|
128
117
|
describe('filter', function () {
|
|
129
118
|
var filter = function (entry) { return entry.id !== 'secret'; };
|
|
130
119
|
test('use specific filter', function () {
|
|
131
120
|
var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter, filter: filter });
|
|
132
|
-
|
|
121
|
+
expect(reporter.filter).toBe(filter);
|
|
133
122
|
reporter.write({ id: 'normal', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
|
|
134
123
|
reporter.write({ id: 'secret', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
|
|
135
124
|
expect(fakeConsole.errors).toEqual([['normal']]);
|
|
136
125
|
});
|
|
137
|
-
test('can change filter', function () {
|
|
138
|
-
var reporter = (0, index_js_1.createConsoleLogReporter)();
|
|
139
|
-
var filter = reporter.filter;
|
|
140
|
-
reporter.filter = function (entry) { return entry.id !== 'secret'; };
|
|
141
|
-
expect(reporter.filter).not.toEqual(filter);
|
|
142
|
-
});
|
|
143
126
|
});
|
|
144
127
|
test('write log entry with multiple arguments', function () {
|
|
145
128
|
var id = 'log';
|
|
146
129
|
var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
|
|
147
|
-
var fakeConsole = reporter.console = createFakeConsole();
|
|
148
130
|
var entry = { id: id, level: index_js_1.logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() };
|
|
149
131
|
reporter.write(entry);
|
|
150
132
|
expect(fakeConsole.infos).toEqual([
|
|
@@ -192,4 +174,4 @@ function createFakeConsole() {
|
|
|
192
174
|
}
|
|
193
175
|
};
|
|
194
176
|
}
|
|
195
|
-
//# sourceMappingURL=
|
|
177
|
+
//# sourceMappingURL=console.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.spec.js","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AACpD,uCAGmB;AACnB,6CAAwC;AAExC,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,+EAA+E,EAAE;QAClF,MAAM,CAAC,IAAA,0BAAe,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG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;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;KAC5C,CAAA;AACH,CAAC","sourcesContent":["import { createStandardLog } from './standardLog.js'\nimport {\n ConsoleLogFormatter, createConsoleLogReporter,\n LogFilter, logLevels, plainLogFormatter, toConsoleMethod\n} from './index.js'\nimport { polyfill } from './platform.js'\n\ndescribe('toConsoleMethod()', () => {\n it('converts any level to standard console method names: debug, info, warn, error', () => {\n expect(toConsoleMethod(1)).toEqual('error')\n expect(toConsoleMethod(399)).toEqual('error')\n expect(toConsoleMethod(400)).toEqual('error')\n\n expect(toConsoleMethod(401)).toEqual('warn')\n expect(toConsoleMethod(499)).toEqual('warn')\n expect(toConsoleMethod(500)).toEqual('warn')\n\n expect(toConsoleMethod(501)).toEqual('info')\n expect(toConsoleMethod(700)).toEqual('info')\n\n expect(toConsoleMethod(701)).toEqual('debug')\n expect(toConsoleMethod(800)).toEqual('debug')\n expect(toConsoleMethod(801)).toEqual('debug')\n expect(toConsoleMethod(Infinity)).toEqual('debug')\n })\n it('converts to debug for 0 (none) or negative (not valid) level', () => {\n // these are invalid input.\n // so instead of hiding them and not logged,\n // log them so that it is easier to discover.\n expect(toConsoleMethod(-1)).toEqual('debug')\n expect(toConsoleMethod(0)).toEqual('debug')\n })\n})\ndescribe('rendering tests', () => {\n test('plain rendering', () => {\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });\n ['emergency', 'info', 'warn', 'debug'].forEach(level => {\n reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })\n })\n })\n})\n\n\ndescribe('createConsoleLogReporter', () => {\n let fakeConsole = createFakeConsole()\n beforeEach(() => polyfill.console = fakeConsole = createFakeConsole())\n\n describe('id', () => {\n test('default is \"console\"', () => {\n const reporter = createConsoleLogReporter()\n expect(reporter.id).toBe('console')\n })\n test('can be overridden', () => {\n const reporter = createConsoleLogReporter({ id: 'neo-console' })\n expect(reporter.id).toBe('neo-console')\n })\n })\n\n describe('log level', () => {\n test('error, alert, critical and emergency logs are written to console.error', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })\n\n expect(fakeConsole.errors.length).toBe(4)\n })\n\n test('warn logs are written to console.warn', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })\n\n expect(fakeConsole.warns.length).toBe(1)\n })\n\n test('notice and info logs are written to console.info', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })\n\n expect(fakeConsole.infos.length).toBe(2)\n })\n\n\n test('debug, trace, and planck logs are written to console.debug', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })\n\n expect(fakeConsole.debugs.length).toBe(3)\n })\n })\n\n describe('custom logs', () => {\n test('are written according to their log level value', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n const sl = createStandardLog({\n logLevel: logLevels.all,\n customLevels: {\n 'high': 50,\n 'important': 450,\n 'interest': 650,\n 'silly': 1000\n },\n reporters: [reporter]\n })\n const log = sl.getLogger([id])\n log.high('a')\n log.important('b')\n log.interest('c')\n log.silly('d')\n\n expect(fakeConsole.errors.length).toBe(1)\n expect(fakeConsole.warns.length).toBe(1)\n expect(fakeConsole.infos.length).toBe(1)\n expect(fakeConsole.debugs.length).toBe(1)\n })\n })\n\n const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]\n\n describe('formatter', () => {\n test('use specific formatter', () => {\n const id = 'id-only'\n const reporter = createConsoleLogReporter({ formatter: idFormatter })\n expect(reporter.formatter).toBe(idFormatter)\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['id-only']])\n })\n })\n\n describe('filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n test('use specific filter', () => {\n const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })\n expect(reporter.filter).toBe(filter)\n\n reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['normal']])\n })\n })\n\n test('write log entry with multiple arguments', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })\n\n const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }\n\n reporter.write(entry)\n\n expect(fakeConsole.infos).toEqual([\n [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']\n ])\n })\n})\n\nfunction createFakeConsole() {\n const errors: any[] = []\n const infos: any[] = []\n const warns: any[] = []\n const debugs: any[] = []\n return {\n errors,\n infos,\n warns,\n debugs,\n error(...args: any[]) { errors.push(args) },\n info(...args: any[]) { infos.push(args) },\n warn(...args: any[]) { warns.push(args) },\n debug(...args: any[]) { debugs.push(args) }\n }\n}\n"]}
|