standard-log 11.5.1 → 12.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.
Files changed (157) hide show
  1. package/README.md +2 -3
  2. package/cjs/console.d.ts +3 -3
  3. package/cjs/console.d.ts.map +1 -1
  4. package/cjs/console.js +18 -9
  5. package/cjs/console.js.map +1 -1
  6. package/cjs/errors.d.ts.map +1 -1
  7. package/cjs/errors.js.map +1 -1
  8. package/cjs/formatter.d.ts +1 -1
  9. package/cjs/formatter.d.ts.map +1 -1
  10. package/cjs/formatter.js +2 -2
  11. package/cjs/formatter.js.map +1 -1
  12. package/cjs/index.d.ts +4 -4
  13. package/cjs/index.d.ts.map +1 -1
  14. package/cjs/index.js +7 -8
  15. package/cjs/index.js.map +1 -1
  16. package/cjs/{logLevels.d.ts → log_levels.d.ts} +1 -1
  17. package/cjs/log_levels.d.ts.map +1 -0
  18. package/cjs/{logLevels.js → log_levels.js} +1 -1
  19. package/cjs/log_levels.js.map +1 -0
  20. package/{esm/logStore.d.ts → cjs/log_store.d.ts} +1 -1
  21. package/cjs/log_store.d.ts.map +1 -0
  22. package/cjs/{logStore.js → log_store.js} +6 -6
  23. package/cjs/log_store.js.map +1 -0
  24. package/cjs/logger.d.ts +1 -1
  25. package/cjs/logger.d.ts.map +1 -1
  26. package/cjs/logger.js +16 -14
  27. package/cjs/logger.js.map +1 -1
  28. package/cjs/memory.d.ts +2 -2
  29. package/cjs/memory.d.ts.map +1 -1
  30. package/cjs/memory.js +15 -8
  31. package/cjs/memory.js.map +1 -1
  32. package/cjs/platform.d.ts.map +1 -1
  33. package/cjs/platform.js +1 -2
  34. package/cjs/platform.js.map +1 -1
  35. package/cjs/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  36. package/cjs/standard_log.ctx.d.ts.map +1 -0
  37. package/cjs/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  38. package/cjs/standard_log.ctx.js.map +1 -0
  39. package/{esm/standardLog.d.ts → cjs/standard_log.d.ts} +4 -9
  40. package/cjs/standard_log.d.ts.map +1 -0
  41. package/cjs/{standardLog.js → standard_log.js} +37 -40
  42. package/cjs/standard_log.js.map +1 -0
  43. package/cjs/standard_log.mocks.d.ts +8 -0
  44. package/cjs/standard_log.mocks.d.ts.map +1 -0
  45. package/cjs/standard_log.mocks.js +32 -0
  46. package/cjs/standard_log.mocks.js.map +1 -0
  47. package/cjs/test_utils.d.ts +10 -0
  48. package/cjs/test_utils.d.ts.map +1 -0
  49. package/cjs/test_utils.js +25 -0
  50. package/cjs/test_utils.js.map +1 -0
  51. package/cjs/testing/index.d.ts +2 -0
  52. package/cjs/testing/index.d.ts.map +1 -0
  53. package/cjs/testing/index.js +6 -0
  54. package/cjs/testing/index.js.map +1 -0
  55. package/cjs/types.d.ts +12 -12
  56. package/cjs/types.d.ts.map +1 -1
  57. package/cjs/types.js.map +1 -1
  58. package/dist/standard-log.es5.js +1139 -758
  59. package/dist/standard-log.es5.js.gz +0 -0
  60. package/dist/standard-log.es5.js.map +1 -1
  61. package/dist/standard-log.es5.js.map.gz +0 -0
  62. package/dist/standard-log.esm.js +220 -175
  63. package/dist/standard-log.esm.js.gz +0 -0
  64. package/dist/standard-log.esm.js.map +1 -1
  65. package/dist/standard-log.esm.js.map.gz +0 -0
  66. package/esm/console.d.ts +3 -3
  67. package/esm/console.d.ts.map +1 -1
  68. package/esm/console.js +21 -10
  69. package/esm/console.js.map +1 -1
  70. package/esm/errors.d.ts.map +1 -1
  71. package/esm/errors.js.map +1 -1
  72. package/esm/formatter.d.ts +1 -1
  73. package/esm/formatter.d.ts.map +1 -1
  74. package/esm/formatter.js +1 -1
  75. package/esm/formatter.js.map +1 -1
  76. package/esm/index.d.ts +4 -4
  77. package/esm/index.d.ts.map +1 -1
  78. package/esm/index.js +2 -2
  79. package/esm/index.js.map +1 -1
  80. package/esm/{logLevels.d.ts → log_levels.d.ts} +1 -1
  81. package/esm/log_levels.d.ts.map +1 -0
  82. package/esm/{logLevels.js → log_levels.js} +1 -1
  83. package/esm/log_levels.js.map +1 -0
  84. package/{cjs/logStore.d.ts → esm/log_store.d.ts} +1 -1
  85. package/esm/log_store.d.ts.map +1 -0
  86. package/esm/{logStore.js → log_store.js} +2 -2
  87. package/esm/log_store.js.map +1 -0
  88. package/esm/logger.d.ts +1 -1
  89. package/esm/logger.d.ts.map +1 -1
  90. package/esm/logger.js +2 -2
  91. package/esm/logger.js.map +1 -1
  92. package/esm/memory.d.ts +2 -2
  93. package/esm/memory.d.ts.map +1 -1
  94. package/esm/memory.js +15 -8
  95. package/esm/memory.js.map +1 -1
  96. package/esm/platform.d.ts.map +1 -1
  97. package/esm/platform.js +1 -2
  98. package/esm/platform.js.map +1 -1
  99. package/esm/{standardLog.ctx.d.ts → standard_log.ctx.d.ts} +2 -2
  100. package/esm/standard_log.ctx.d.ts.map +1 -0
  101. package/esm/{standardLog.ctx.js → standard_log.ctx.js} +1 -1
  102. package/esm/standard_log.ctx.js.map +1 -0
  103. package/{cjs/standardLog.d.ts → esm/standard_log.d.ts} +4 -9
  104. package/esm/standard_log.d.ts.map +1 -0
  105. package/esm/{standardLog.js → standard_log.js} +27 -28
  106. package/esm/standard_log.js.map +1 -0
  107. package/esm/standard_log.mocks.d.ts +8 -0
  108. package/esm/standard_log.mocks.d.ts.map +1 -0
  109. package/esm/standard_log.mocks.js +16 -0
  110. package/esm/standard_log.mocks.js.map +1 -0
  111. package/esm/test_utils.d.ts +10 -0
  112. package/esm/test_utils.d.ts.map +1 -0
  113. package/esm/test_utils.js +18 -0
  114. package/esm/test_utils.js.map +1 -0
  115. package/esm/testing/index.d.ts +2 -0
  116. package/esm/testing/index.d.ts.map +1 -0
  117. package/esm/testing/index.js +2 -0
  118. package/esm/testing/index.js.map +1 -0
  119. package/esm/types.d.ts +12 -12
  120. package/esm/types.d.ts.map +1 -1
  121. package/esm/types.js.map +1 -1
  122. package/package.json +14 -8
  123. package/ts/console.ts +55 -46
  124. package/ts/errors.ts +6 -6
  125. package/ts/formatter.ts +19 -19
  126. package/ts/index.ts +19 -10
  127. package/ts/log_levels.ts +107 -0
  128. package/ts/log_store.ts +63 -0
  129. package/ts/logger.ts +69 -59
  130. package/ts/memory.ts +66 -54
  131. package/ts/platform.ts +2 -2
  132. package/ts/standard_log.ctx.ts +8 -0
  133. package/ts/standard_log.mocks.ts +22 -0
  134. package/ts/standard_log.ts +140 -0
  135. package/ts/test_utils.ts +21 -0
  136. package/ts/testing/index.ts +1 -0
  137. package/ts/types.ts +72 -62
  138. package/cjs/logLevels.d.ts.map +0 -1
  139. package/cjs/logLevels.js.map +0 -1
  140. package/cjs/logStore.d.ts.map +0 -1
  141. package/cjs/logStore.js.map +0 -1
  142. package/cjs/standardLog.ctx.d.ts.map +0 -1
  143. package/cjs/standardLog.ctx.js.map +0 -1
  144. package/cjs/standardLog.d.ts.map +0 -1
  145. package/cjs/standardLog.js.map +0 -1
  146. package/esm/logLevels.d.ts.map +0 -1
  147. package/esm/logLevels.js.map +0 -1
  148. package/esm/logStore.d.ts.map +0 -1
  149. package/esm/logStore.js.map +0 -1
  150. package/esm/standardLog.ctx.d.ts.map +0 -1
  151. package/esm/standardLog.ctx.js.map +0 -1
  152. package/esm/standardLog.d.ts.map +0 -1
  153. package/esm/standardLog.js.map +0 -1
  154. package/ts/logLevels.ts +0 -108
  155. package/ts/logStore.ts +0 -54
  156. package/ts/standardLog.ctx.ts +0 -8
  157. package/ts/standardLog.ts +0 -135
package/ts/memory.ts CHANGED
@@ -5,71 +5,83 @@ import type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './
5
5
  import { createConsoleLogReporter } from './console.js'
6
6
 
7
7
  export type MemoryLogReporter = LogReporter<LogEntry> & {
8
- logs: LogEntry[],
9
- /**
10
- * Gets a simple log message for testing.
11
- * The message only contains arguments for each log entry.
12
- */
13
- getLogMessage(): string,
14
- getLogMessages(): string[],
15
- getLogMessageWithLevel(): string,
16
- getLogMessagesWithIdAndLevel(): string[],
17
- emit(): void
8
+ logs: LogEntry[]
9
+ /**
10
+ * Gets a simple log message for testing.
11
+ * The message only contains arguments for each log entry.
12
+ */
13
+ getLogMessage(): string
14
+ getLogMessages(): string[]
15
+ getLogMessageWithLevel(): string
16
+ getLogMessagesWithIdAndLevel(): string[]
17
+ emit(): void
18
18
  }
19
19
 
20
20
  export type MemoryLogFormatter = LogFormatter<LogEntry>
21
21
 
22
22
  export function toMessageWithLevel(logs: LogEntry[]) {
23
- return logs.map(toInspectLogEntry)
24
- .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
25
- .join('\n')
26
- // if it has more than this log,
27
- // we assume it is running under tests,
28
- // and remove this log to simplify testing.
29
- .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '')
23
+ return (
24
+ logs
25
+ .map(toInspectLogEntry)
26
+ .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
27
+ .join('\n')
28
+ // if it has more than this log,
29
+ // we assume it is running under tests,
30
+ // and remove this log to simplify testing.
31
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '')
32
+ )
30
33
  }
31
34
 
32
35
  export function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {
33
- return Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))
36
+ return Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))
34
37
  }
35
38
 
36
39
  function buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {
37
- const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)
38
- const logs: LogEntry[] = []
39
- return {
40
- id,
41
- get formatter() { return formatter },
42
- get filter() { return filter },
43
- logs,
44
- write(entry: LogEntry) {
45
- if (filter && !filter(entry)) return
46
- logs.push(formatter(entry))
47
- },
48
- getLogMessage() {
49
- return this.getLogMessages().join('\n')
50
- },
51
- getLogMessages() {
52
- return logs.map(toInspectLogEntry)
53
- .map(log => log.args.join(' '))
54
- },
55
- getLogMessagesWithIdAndLevel() {
56
- return logs.map(toInspectLogEntry)
57
- .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)
58
- },
59
- getLogMessageWithLevel() { return toMessageWithLevel(logs) },
60
- /**
61
- * emit the saved log to console for easy debugging
62
- */
63
- emit() {
64
- const reporter = createConsoleLogReporter()
65
- logs.forEach(l => reporter.write(l))
66
- }
67
- }
40
+ const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)
41
+ const logs: LogEntry[] = []
42
+ return {
43
+ id,
44
+ get formatter() {
45
+ return formatter
46
+ },
47
+ get filter() {
48
+ return filter
49
+ },
50
+ logs,
51
+ write(entry: LogEntry) {
52
+ if (filter && !filter(entry)) return
53
+ logs.push(formatter(entry))
54
+ },
55
+ getLogMessage() {
56
+ return this.getLogMessages().join('\n')
57
+ },
58
+ getLogMessages() {
59
+ return logs.map(toInspectLogEntry).map(log => log.args.join(' '))
60
+ },
61
+ getLogMessagesWithIdAndLevel() {
62
+ return logs
63
+ .map(toInspectLogEntry)
64
+ .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)
65
+ },
66
+ getLogMessageWithLevel() {
67
+ return toMessageWithLevel(logs)
68
+ },
69
+ /**
70
+ * emit the saved log to console for easy debugging
71
+ */
72
+ emit() {
73
+ const reporter = createConsoleLogReporter()
74
+ logs.forEach(l => reporter.write(l))
75
+ }
76
+ }
68
77
  }
69
78
 
70
- export function createMemoryWithConsoleLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {
71
- return Object.freeze(
72
- Object.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {
73
- isConsoleReporter: true
74
- }))
79
+ export function createMemoryWithConsoleLogReporter(
80
+ options?: LogReporterOptions<LogEntry>
81
+ ): MemoryLogReporter {
82
+ return Object.freeze(
83
+ Object.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {
84
+ isConsoleReporter: true
85
+ })
86
+ )
75
87
  }
package/ts/platform.ts CHANGED
@@ -3,7 +3,7 @@ import { inspect } from 'util'
3
3
  import type { ConsoleLike, LogEntry } from './types.js'
4
4
 
5
5
  export const toInspectLogEntry = (e: LogEntry) => (
6
- e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
7
- e)
6
+ (e.args = e.args.map(value => (typeof value === 'object' && value !== null ? inspect(value) : value))), e
7
+ )
8
8
 
9
9
  export const polyfill: { console?: ConsoleLike } = record()
@@ -0,0 +1,8 @@
1
+ import { record } from 'type-plus'
2
+ import type { LogStore } from './log_store.js'
3
+ import type { LogMethodNames, StandardLogInstance } from './types.js'
4
+
5
+ export const ctx: {
6
+ configured?: boolean
7
+ gsl?: { store: LogStore; standardLog: StandardLogInstance<LogMethodNames> }
8
+ } = record()
@@ -0,0 +1,22 @@
1
+ import { logLevels } from './log_levels.js'
2
+ import { createMemoryLogReporter, type MemoryLogReporter } from './memory.js'
3
+ import { createStandardLogClosure, type StandardLog } from './standard_log.js'
4
+ import type { LogMethodNames, StandardLogOptions } from './types.js'
5
+
6
+ export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
7
+ reporter: MemoryLogReporter
8
+ }
9
+
10
+ export function createStandardLogForTest<N extends string = LogMethodNames>(
11
+ options: StandardLogOptions<N> = {}
12
+ ): StandardLogForTest<N> {
13
+ options.logLevel = options.logLevel ?? logLevels.debug
14
+ options.reporters = options.reporters ?? []
15
+ const existingReporter = options.reporters.find(r => r.id === 'memory') as MemoryLogReporter
16
+ const reporter = existingReporter ?? createMemoryLogReporter()
17
+ if (!existingReporter) {
18
+ options.reporters.push(reporter)
19
+ }
20
+ const closure = createStandardLogClosure<N>(options)
21
+ return { ...closure.standardLog, reporter }
22
+ }
@@ -0,0 +1,140 @@
1
+ import { record, required } from 'type-plus'
2
+ import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './log_levels.js'
3
+ import { createLogStore, type LogStore } from './log_store.js'
4
+ import { createLogger } from './logger.js'
5
+ import { ctx } from './standard_log.ctx.js'
6
+ import type {
7
+ LogMethodNames,
8
+ Logger,
9
+ LoggerOptions,
10
+ StandardLogInstance,
11
+ StandardLogOptions
12
+ } from './types.js'
13
+
14
+ export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {}
15
+
16
+ export function createStandardLog<N extends string = LogMethodNames>(
17
+ options?: StandardLogOptions<N>
18
+ ): StandardLog<N> {
19
+ const closure = createStandardLogClosure(options)
20
+ if (options?.reporters?.some(r => !r.id)) {
21
+ const log = closure.standardLog.getLogger('standard-log')
22
+ log.critical(
23
+ `Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`
24
+ )
25
+ }
26
+
27
+ if (!ctx.gsl) ctx.gsl = closure as any
28
+ return closure.standardLog
29
+ }
30
+
31
+ function noop() {}
32
+
33
+ export function createStandardLogClosure<N extends string = LogMethodNames>(
34
+ options?: StandardLogOptions<N>
35
+ ): { store: LogStore; standardLog: StandardLog<N> } {
36
+ // TODO reporter.id must not be empty
37
+ const store = createLogStore(required({ logLevel: logLevels.info }, options))
38
+ const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []
39
+ const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([
40
+ 'on',
41
+ 'count',
42
+ 'write'
43
+ ])
44
+ return {
45
+ store,
46
+ standardLog: {
47
+ get logLevel() {
48
+ return store.logLevel
49
+ },
50
+
51
+ toLogLevelName(level: number) {
52
+ return store.logLevelStore.getName(level)
53
+ },
54
+ toLogLevel(name: string) {
55
+ return store.logLevelStore.getLevel(name)
56
+ },
57
+ getLogger(id: string, options?: LoggerOptions) {
58
+ if (store.loggers[id]) return store.loggers[id] as any
59
+ return (store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any)
60
+ },
61
+ getNonConsoleLogger(id, options?) {
62
+ if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any
63
+
64
+ if (store.loggers[id]) {
65
+ const log = this.getLogger('standard-log')
66
+ log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)
67
+ return (store.nonConsoleLoggers[id] = createDummyLogger(logMethods))
68
+ }
69
+
70
+ return (store.nonConsoleLoggers[id] =
71
+ nonConsoleReporters.length === 0
72
+ ? createDummyLogger(logMethods)
73
+ : createLogger(store, id, {
74
+ ssf: this.getNonConsoleLogger,
75
+ ...options,
76
+ writeTo(reporterId) {
77
+ return nonConsoleReporters.indexOf(reporterId) >= 0
78
+ }
79
+ }))
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ function createDummyLogger(logMethods: string[]) {
86
+ return logMethods.reduce((p, m) => {
87
+ p[m] = noop
88
+ return p
89
+ }, record()) as Logger
90
+ }
91
+
92
+ /**
93
+ * Suppress logging within the code block.
94
+ */
95
+ export function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R
96
+ export function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {
97
+ const origLevels = logs.map(l => l.level)
98
+ logs.forEach(l => (l.level = logLevels.none))
99
+ const result = block()
100
+ logs.forEach((l, i) => (l.level = origLevels[i]))
101
+ return result
102
+ }
103
+
104
+ export type GetLogger<N extends string = LogMethodNames> = (
105
+ id: string,
106
+ options?: LoggerOptions
107
+ ) => Logger<LogMethodNames | N>
108
+
109
+ export function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {
110
+ return getGlobalSL<N>().getLogger(id, options)
111
+ }
112
+
113
+ function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
114
+ if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
115
+
116
+ return ctx.gsl!.standardLog as StandardLogInstance<N>
117
+ }
118
+
119
+ export function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {
120
+ if (ctx.configured) {
121
+ const log = ctx.gsl!.standardLog.getLogger('standard-log')
122
+ log.warn(
123
+ 'configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.'
124
+ )
125
+ }
126
+
127
+ if (ctx.gsl) {
128
+ if (options.logLevel) {
129
+ ctx.gsl.store.logLevel = options.logLevel
130
+ }
131
+ if (options.reporters) {
132
+ const reporters = ctx.gsl.store.reporters
133
+ reporters.length = 0
134
+ reporters.push(...options.reporters)
135
+ }
136
+ } else {
137
+ ctx.gsl = createStandardLogClosure(options)
138
+ }
139
+ ctx.configured = true
140
+ }
@@ -0,0 +1,21 @@
1
+ import { range } from 'ramda'
2
+ import { plainLogFormatter } from './formatter.js'
3
+ import { toInspectLogEntry } from './platform.js'
4
+ import type { LogEntry } from './types.js'
5
+
6
+ export function rangeEntries(start: number, end: number, expected: any) {
7
+ return range(start, end).map(value => [value, expected])
8
+ }
9
+
10
+ export function assertSSF(err: Error, filename: string) {
11
+ const firstStackTrace = err.stack?.split('\n')[1]
12
+ expect(firstStackTrace).toMatch(filename)
13
+ }
14
+
15
+ export function logEntriesToString(logs: LogEntry[]) {
16
+ return logs.map(toInspectLogEntry).map(plainLogFormatter).join('\n')
17
+ }
18
+
19
+ export function wrapTest<F extends Record<any, any>>(fn: (test: jest.It) => F) {
20
+ return Object.assign(fn(test), { only: fn(test.only), skip: fn(test.skip) })
21
+ }
@@ -0,0 +1 @@
1
+ export { createStandardLogForTest, type StandardLogForTest } from '../standard_log.mocks.js'
package/ts/types.ts CHANGED
@@ -1,45 +1,55 @@
1
1
  import type { StackTraceMeta } from '@just-func/types'
2
2
 
3
3
  export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
4
- customLevels?: Record<CustomLevelNames, number>,
5
- logLevel?: number,
6
- reporters?: LogReporter[]
4
+ customLevels?: Record<CustomLevelNames, number>
5
+ logLevel?: number
6
+ reporters?: LogReporter[]
7
7
  }
8
8
 
9
9
  export interface LoggerOptions extends StackTraceMeta {
10
- level?: number,
11
- writeTo?: LogReporter | ReporterFilter
10
+ level?: number
11
+ writeTo?: LogReporter | ReporterFilter
12
12
  }
13
13
 
14
14
  export type Logger<N extends string = LogMethodNames> = {
15
- readonly id: string,
16
- /**
17
- * Logger local log level.
18
- */
19
- level?: number,
20
- /**
21
- * Logs with an increment counter.
22
- * This is useful during debugging to check for steps executed.
23
- */
24
- count(...args: any[]): void,
25
- on(level: number | N, logFunction: LogFunction): void,
26
- /**
27
- * Write custom log entries.
28
- */
29
- write(entry: LogEntry): void
15
+ readonly id: string
16
+ /**
17
+ * Logger local log level.
18
+ */
19
+ level?: number
20
+ /**
21
+ * Logs with an increment counter.
22
+ * This is useful during debugging to check for steps executed.
23
+ */
24
+ count(...args: any[]): void
25
+ on(level: number | N, logFunction: LogFunction): void
26
+ /**
27
+ * Write custom log entries.
28
+ */
29
+ write(entry: LogEntry): void
30
30
  } & { [k in N]: LogMethod }
31
31
 
32
32
  /**
33
33
  * Names of the standard log methods.
34
34
  */
35
- export type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'
35
+ export type LogMethodNames =
36
+ | 'emergency'
37
+ | 'alert'
38
+ | 'critical'
39
+ | 'error'
40
+ | 'warn'
41
+ | 'notice'
42
+ | 'info'
43
+ | 'debug'
44
+ | 'trace'
45
+ | 'planck'
36
46
 
37
47
  export type LogEntry = {
38
- id: string,
39
- level: number,
40
- // args instead of messages because it is `any[]` instead of `string[]`
41
- args: any[],
42
- timestamp: Date
48
+ id: string
49
+ level: number
50
+ // args instead of messages because it is `any[]` instead of `string[]`
51
+ args: any[]
52
+ timestamp: Date
43
53
  }
44
54
 
45
55
  export type LogMethod = (...args: any[]) => void
@@ -49,11 +59,11 @@ export type LogFunction = (log: LogMethod, logLevel: number) => string | void
49
59
  export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)
50
60
 
51
61
  export interface StandardLogInstance<N extends string = LogMethodNames> {
52
- logLevel: number,
53
- toLogLevelName(level: number): string,
54
- toLogLevel(name: N): number,
55
- getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,
56
- getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
62
+ logLevel: number
63
+ toLogLevelName(level: number): string
64
+ toLogLevel(name: N): number
65
+ getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
66
+ getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
57
67
  }
58
68
 
59
69
  /**
@@ -68,45 +78,45 @@ export type LogFormatter<T = any[]> = (entry: LogEntry) => T
68
78
  */
69
79
  export type LogFilter = (entry: LogEntry) => boolean
70
80
 
71
- export type LogLevelEntry = { name: string, level: number }
81
+ export type LogLevelEntry = { name: string; level: number }
72
82
 
73
83
  export interface LogReporter<T = any> {
74
- readonly id: string,
75
- /**
76
- * Specifies the formatter to be used by the reporter.
77
- * Using this you can customize how the reporter writes the log entry.
78
- */
79
- readonly formatter: LogFormatter<T>,
80
- /**
81
- * Specifies a filter to determine should the log be written.
82
- */
83
- readonly filter?: LogFilter,
84
- /**
85
- * Indicate if this is a console reporter.
86
- * There is only one console reporter can be present in the system.
87
- */
88
- readonly isConsoleReporter?: boolean,
89
- write(entry: LogEntry): void
84
+ readonly id: string
85
+ /**
86
+ * Specifies the formatter to be used by the reporter.
87
+ * Using this you can customize how the reporter writes the log entry.
88
+ */
89
+ readonly formatter: LogFormatter<T>
90
+ /**
91
+ * Specifies a filter to determine should the log be written.
92
+ */
93
+ readonly filter?: LogFilter
94
+ /**
95
+ * Indicate if this is a console reporter.
96
+ * There is only one console reporter can be present in the system.
97
+ */
98
+ readonly isConsoleReporter?: boolean
99
+ write(entry: LogEntry): void
90
100
  }
91
101
 
92
102
  export type LogReporterOptions<T = any> = {
93
- id?: string,
94
- /**
95
- * Specifies the formatter to be used by the reporter.
96
- * Using this you can customize how the reporter writes the log entry.
97
- */
98
- formatter?: LogFormatter<T>,
99
- /**
100
- * Specifies a filter to determine should the log be written.
101
- */
102
- filter?: LogFilter
103
+ id?: string
104
+ /**
105
+ * Specifies the formatter to be used by the reporter.
106
+ * Using this you can customize how the reporter writes the log entry.
107
+ */
108
+ formatter?: LogFormatter<T>
109
+ /**
110
+ * Specifies a filter to determine should the log be written.
111
+ */
112
+ filter?: LogFilter
103
113
  }
104
114
 
105
115
  export type LogLevel = number
106
116
 
107
117
  export interface ConsoleLike {
108
- debug(...args: any[]): void,
109
- info(...args: any[]): void,
110
- warn(...args: any[]): void,
111
- error(...args: any[]): void,
118
+ debug(...args: any[]): void
119
+ info(...args: any[]): void
120
+ warn(...args: any[]): void
121
+ error(...args: any[]): void
112
122
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS;IACpB;;OAEG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;CAEJ,CAAA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,4GAW3C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAW5C,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"logLevels.js","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":";;;AACa,QAAA,SAAS,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,CAAU;IAChB;;;;OAIG;IACH,SAAS,EAAE,GAAY;IACvB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,QAAQ,EAAE,GAAY;IACtB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,MAAM,EAAE,GAAY;IACpB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;;OAKG;IACH,MAAM,EAAE,QAAQ;IAChB;;OAEG;IACH,GAAG,EAAE,QAAQ;CACd,CAAA;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAa;IAC1C,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,WAAW,CAAA;IACpC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IACnC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,QAAQ,CAAA;IACjC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,OAAO,QAAQ,CAAA;AACjB,CAAC;AAXD,wCAWC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAQ,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;AACrD,CAAC;AAFD,gCAEC;AAEY,QAAA,wBAAwB,GAAa;IAChD,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACT,CAAA","sourcesContent":["\nexport const logLevels = {\n /**\n * none: 0\n */\n none: 0 as const,\n /**\n * emergency: 100\n *\n * emergency -> alert\n */\n emergency: 100 as const,\n /**\n * alert: 200\n *\n * emergency -> alert -> critical\n */\n alert: 200 as const,\n /**\n * critical: 300\n *\n * alert -> critical -> error\n */\n critical: 300 as const,\n /**\n * error: 400\n *\n * critical -> error -> warn\n */\n error: 400 as const,\n /**\n * warn: 500\n *\n * error -> warn -> notice\n */\n warn: 500 as const,\n /**\n * notice: 600\n *\n * warn -> notice -> info\n */\n notice: 600 as const,\n /**\n * info: 700\n *\n * notice -> info -> debug\n */\n info: 700 as const,\n /**\n * debug: 800\n *\n * info -> debug -> trace\n */\n debug: 800 as const,\n /**\n * trace: 900\n *\n * debug -> trace -> planck\n */\n trace: 900 as const,\n /**\n * planck: Infinity\n * `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.\n *\n * trace -> planck\n */\n planck: Infinity,\n /**\n * all: Infinity\n */\n all: Infinity\n}\n\n/**\n * Convert default log level value to log level name.\n */\nexport function toLogLevelName(level: number) {\n if (level <= 100) return 'emergency'\n if (level <= 200) return 'alert'\n if (level <= 300) return 'critical'\n if (level <= 400) return 'error'\n if (level <= 500) return 'warn'\n if (level <= 600) return 'notice'\n if (level <= 700) return 'info'\n if (level <= 800) return 'debug'\n if (level <= 900) return 'trace'\n return 'planck'\n}\n\n/**\n * Convert default log level name to log level value.\n */\nexport function toLogLevel(name: string): number | undefined {\n return (logLevels as any)[name.toLocaleLowerCase()]\n}\n\nexport const DEFAULT_LOG_METHOD_NAMES: string[] = [\n 'emergency',\n 'alert',\n 'critical',\n 'error',\n 'warn',\n 'notice',\n 'info',\n 'debug',\n 'trace',\n 'planck'\n]\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,C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,OAAO,CAAC,CAAA;QACV,CAAC,EAAE,EAA4B,CAAC;KACjC,CAAA;IACD,OAAO;QACL,OAAO,YAAC,KAAa;;YACnB,OAAO,MAAA,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,mCAAI,IAAA,6BAAc,EAAC,KAAK,CAAC,CAAA;QAClE,CAAC;QACD,QAAQ,YAAC,IAAY;;YACnB,OAAO,MAAA,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,IAAA,yBAAU,EAAC,IAAI,CAAC,CAAA;QACrD,CAAC;QACD,YAAY;YACV,OAAO,IAAA,qBAAS,EAAC,wBAAS,EAAE,UAAC,MAAM,EAAE,IAAI;gBACvC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK;oBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,wBAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAEpF,OAAO,MAAM,CAAA;YACf,CAAC,EAAE,IAAA,kBAAM,EAAC,KAAK,CAAC,YAAY,EAAE,UAAA,IAAI,IAAI,OAAA,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAA3C,CAA2C,CAAC,CAAC,CAAA;QACrF,CAAC;KACF,CAAA;AACH,CAAC;AAzBD,sCAyBC","sourcesContent":["\nimport { mapKey, record, reduceByKey, reduceKey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'\nimport type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore {\n return {\n loggers: record(),\n nonConsoleLoggers: record(),\n reporters: options.reporters || [createConsoleLogReporter()],\n logLevel: options.logLevel,\n logLevelStore: logLevelStore(options)\n }\n}\n\nexport interface LogStore {\n loggers: Record<string, Logger>,\n nonConsoleLoggers: Record<string, Logger>,\n reporters: LogReporter[],\n logLevel: LogLevel,\n logLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n customLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n const customLevels = options.customLevels || record()\n\n const store = {\n customLevels,\n customLevelsReverse: reduceByKey(customLevels, (p, k) => {\n p[customLevels[k]] = k\n return p\n }, {} as Record<number, string>)\n }\n return {\n getName(level: number) {\n return store.customLevelsReverse[level] ?? toLogLevelName(level)\n },\n getLevel(name: string) {\n return store.customLevels[name] ?? toLogLevel(name)\n },\n getAllLevels() {\n return reduceKey(logLevels, (result, name) => {\n if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n return result\n }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.ctx.d.ts","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,eAAO,MAAM,GAAG,EAAE;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;KAAE,CAAA;CACjE,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.ctx.js","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAIrB,QAAA,GAAG,GAGZ,IAAA,kBAAM,GAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport type { LogStore } from './logStore.js'\nimport type { LogMethodNames, StandardLogInstance } from './types.js'\n\nexport const ctx: {\n configured?: boolean,\n gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAExE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE1H,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,CAAE,SAAQ,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACvG;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACjE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B,WAAW,CAAC,CAAC,CAAC,CAShB;AAID,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CA2ClD;AASD,oBAAY,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAEpH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,QAAQ,GAAE,QAA0B,GACnC,kBAAkB,CAAC,CAAC,CAAC,CAIvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MA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Ac,CAAC,CAAA;QAC1D,GAAG,CAAC,IAAI,CAAC,kJAAkJ,CAAC,CAAA;KAC7J;IAED,IAAI,wBAAG,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,wBAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SAC1C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,IAAM,SAAS,GAAG,wBAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAA;YACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;YACpB,SAAS,CAAC,IAAI,OAAd,SAAS,EAAS,OAAO,CAAC,SAAS,EAAC;SACrC;KACF;SACI;QACH,wBAAG,CAAC,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,wBAAG,CAAC,UAAU,GAAG,IAAI,CAAA;AACvB,CAAC;AApBD,oCAoBC","sourcesContent":["import { record, required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'\nimport { createLogStore, LogStore } from './logStore.js'\nimport { createMemoryLogReporter, MemoryLogReporter } from './memory.js'\nimport { ctx } from './standardLog.ctx.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): StandardLog<N> {\n const closure = createStandardLogClosure(options)\n if (options?.reporters?.some(r => !r.id)) {\n const log = closure.standardLog.getLogger('standard-log')\n log.critical(`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`)\n }\n\n if (!ctx.gsl) ctx.gsl = closure as any\n return closure.standardLog\n}\n\nfunction noop() { }\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): { store: LogStore, standardLog: StandardLog<N> } {\n // TODO reporter.id must not be empty\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []\n const logMethods = DEFAULT_LOG_METHOD_NAMES\n .concat(Object.keys(options?.customLevels ?? {}))\n .concat(['on', 'count', 'write'])\n return {\n store,\n standardLog: {\n get logLevel() { return store.logLevel },\n\n toLogLevelName(level: number) {\n return store.logLevelStore.getName(level)\n },\n toLogLevel(name: string) {\n return store.logLevelStore.getLevel(name)\n },\n getLogger(id: string, options?: LoggerOptions) {\n if (store.loggers[id]) return store.loggers[id] as any\n return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any\n },\n getNonConsoleLogger(id, options?) {\n if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any\n\n if (store.loggers[id]) {\n const log = this.getLogger('standard-log')\n log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)\n return store.nonConsoleLoggers[id] = createDummyLogger(logMethods)\n }\n\n return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0\n ? createDummyLogger(logMethods)\n : createLogger(store, id, {\n ssf: this.getNonConsoleLogger,\n ...options,\n writeTo(reporterId) {\n return nonConsoleReporters.indexOf(reporterId) >= 0\n }\n })\n },\n }\n }\n}\n\nfunction createDummyLogger(logMethods: string[]) {\n return logMethods.reduce((p, m) => {\n p[m] = noop\n return p\n }, record()) as Logger\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & { reporter: MemoryLogReporter }\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n logLevel: LogLevel = logLevels.debug\n): StandardLogForTest<N> {\n const reporter = createMemoryLogReporter()\n const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })\n return { ...closure.standardLog, reporter }\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n const origLevels = logs.map(l => l.level)\n logs.forEach(l => l.level = logLevels.none)\n const result = block()\n logs.forEach((l, i) => l.level = origLevels[i])\n return result\n}\n\nexport type GetLogger<N extends string = LogMethodNames> = (id: string, options?: LoggerOptions) => Logger<LogMethodNames | N>\n\nexport function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n return getGlobalSL<N>().getLogger(id, options)\n}\n\nfunction getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {\n if (!ctx.gsl) ctx.gsl = createStandardLogClosure()\n\n return ctx.gsl!.standardLog as StandardLogInstance<N>\n}\n\nexport function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {\n if (ctx.configured) {\n const log = ctx.gsl!.standardLog.getLogger('standard-log')\n log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')\n }\n\n if (ctx.gsl) {\n if (options.logLevel) {\n ctx.gsl.store.logLevel = options.logLevel\n }\n if (options.reporters) {\n const reporters = ctx.gsl.store.reporters\n reporters.length = 0\n reporters.push(...options.reporters)\n }\n }\n else {\n ctx.gsl = createStandardLogClosure(options)\n }\n ctx.configured = true\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS;IACpB;;OAEG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;CAEJ,CAAA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,4GAW3C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAA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AChC,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAQ,SAAiB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAa;IAChD,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACT,CAAA","sourcesContent":["\nexport const logLevels = {\n /**\n * none: 0\n */\n none: 0 as const,\n /**\n * emergency: 100\n *\n * emergency -> alert\n */\n emergency: 100 as const,\n /**\n * alert: 200\n *\n * emergency -> alert -> critical\n */\n alert: 200 as const,\n /**\n * critical: 300\n *\n * alert -> critical -> error\n */\n critical: 300 as const,\n /**\n * error: 400\n *\n * critical -> error -> warn\n */\n error: 400 as const,\n /**\n * warn: 500\n *\n * error -> warn -> notice\n */\n warn: 500 as const,\n /**\n * notice: 600\n *\n * warn -> notice -> info\n */\n notice: 600 as const,\n /**\n * info: 700\n *\n * notice -> info -> debug\n */\n info: 700 as const,\n /**\n * debug: 800\n *\n * info -> debug -> trace\n */\n debug: 800 as const,\n /**\n * trace: 900\n *\n * debug -> trace -> planck\n */\n trace: 900 as const,\n /**\n * planck: Infinity\n * `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.\n *\n * trace -> planck\n */\n planck: Infinity,\n /**\n * all: Infinity\n */\n all: Infinity\n}\n\n/**\n * Convert default log level value to log level name.\n */\nexport function toLogLevelName(level: number) {\n if (level <= 100) return 'emergency'\n if (level <= 200) return 'alert'\n if (level <= 300) return 'critical'\n if (level <= 400) return 'error'\n if (level <= 500) return 'warn'\n if (level <= 600) return 'notice'\n if (level <= 700) return 'info'\n if (level <= 800) return 'debug'\n if (level <= 900) return 'trace'\n return 'planck'\n}\n\n/**\n * Convert default log level name to log level value.\n */\nexport function toLogLevel(name: string): number | undefined {\n return (logLevels as any)[name.toLocaleLowerCase()]\n}\n\nexport const DEFAULT_LOG_METHOD_NAMES: string[] = [\n 'emergency',\n 'alert',\n 'critical',\n 'error',\n 'warn',\n 'notice',\n 'info',\n 'debug',\n 'trace',\n 'planck'\n]\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAQpH;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACtC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB;mBAWxC,MAAM;mBAGN,MAAM;;;;;EAWxB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"logStore.js","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EA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KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACrF,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["\nimport { mapKey, record, reduceByKey, reduceKey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'\nimport type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore {\n return {\n loggers: record(),\n nonConsoleLoggers: record(),\n reporters: options.reporters || [createConsoleLogReporter()],\n logLevel: options.logLevel,\n logLevelStore: logLevelStore(options)\n }\n}\n\nexport interface LogStore {\n loggers: Record<string, Logger>,\n nonConsoleLoggers: Record<string, Logger>,\n reporters: LogReporter[],\n logLevel: LogLevel,\n logLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n customLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n const customLevels = options.customLevels || record()\n\n const store = {\n customLevels,\n customLevelsReverse: reduceByKey(customLevels, (p, k) => {\n p[customLevels[k]] = k\n return p\n }, {} as Record<number, string>)\n }\n return {\n getName(level: number) {\n return store.customLevelsReverse[level] ?? toLogLevelName(level)\n },\n getLevel(name: string) {\n return store.customLevels[name] ?? toLogLevel(name)\n },\n getAllLevels() {\n return reduceKey(logLevels, (result, name) => {\n if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n return result\n }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.ctx.d.ts","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,eAAO,MAAM,GAAG,EAAE;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;KAAE,CAAA;CACjE,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.ctx.js","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAM,EAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport type { LogStore } from './logStore.js'\nimport type { LogMethodNames, StandardLogInstance } from './types.js'\n\nexport const ctx: {\n configured?: boolean,\n gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAExE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE1H,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,CAAE,SAAQ,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACvG;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACjE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B,WAAW,CAAC,CAAC,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