standard-log 11.5.0 → 11.5.2

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 (89) hide show
  1. package/cjs/console.d.ts +3 -3
  2. package/cjs/console.d.ts.map +1 -1
  3. package/cjs/console.js +17 -8
  4. package/cjs/console.js.map +1 -1
  5. package/cjs/errors.d.ts.map +1 -1
  6. package/cjs/errors.js.map +1 -1
  7. package/cjs/formatter.d.ts +1 -1
  8. package/cjs/formatter.d.ts.map +1 -1
  9. package/cjs/formatter.js.map +1 -1
  10. package/cjs/index.d.ts.map +1 -1
  11. package/cjs/index.js.map +1 -1
  12. package/cjs/logLevels.d.ts.map +1 -1
  13. package/cjs/logLevels.js.map +1 -1
  14. package/cjs/logStore.d.ts.map +1 -1
  15. package/cjs/logStore.js.map +1 -1
  16. package/cjs/logger.d.ts.map +1 -1
  17. package/cjs/logger.js +15 -13
  18. package/cjs/logger.js.map +1 -1
  19. package/cjs/memory.d.ts +2 -2
  20. package/cjs/memory.d.ts.map +1 -1
  21. package/cjs/memory.js +15 -8
  22. package/cjs/memory.js.map +1 -1
  23. package/cjs/platform.d.ts.map +1 -1
  24. package/cjs/platform.js +1 -2
  25. package/cjs/platform.js.map +1 -1
  26. package/cjs/standardLog.ctx.d.ts.map +1 -1
  27. package/cjs/standardLog.ctx.js.map +1 -1
  28. package/cjs/standardLog.d.ts +2 -2
  29. package/cjs/standardLog.d.ts.map +1 -1
  30. package/cjs/standardLog.js +19 -14
  31. package/cjs/standardLog.js.map +1 -1
  32. package/cjs/types.d.ts +12 -12
  33. package/cjs/types.d.ts.map +1 -1
  34. package/cjs/types.js.map +1 -1
  35. package/dist/standard-log.es5.js +1190 -801
  36. package/dist/standard-log.es5.js.gz +0 -0
  37. package/dist/standard-log.es5.js.map +1 -1
  38. package/dist/standard-log.es5.js.map.gz +0 -0
  39. package/dist/standard-log.esm.js +173 -119
  40. package/dist/standard-log.esm.js.gz +0 -0
  41. package/dist/standard-log.esm.js.map +1 -1
  42. package/dist/standard-log.esm.js.map.gz +0 -0
  43. package/esm/console.d.ts +3 -3
  44. package/esm/console.d.ts.map +1 -1
  45. package/esm/console.js +20 -9
  46. package/esm/console.js.map +1 -1
  47. package/esm/errors.d.ts.map +1 -1
  48. package/esm/errors.js.map +1 -1
  49. package/esm/formatter.d.ts +1 -1
  50. package/esm/formatter.d.ts.map +1 -1
  51. package/esm/formatter.js.map +1 -1
  52. package/esm/index.d.ts.map +1 -1
  53. package/esm/index.js.map +1 -1
  54. package/esm/logLevels.d.ts.map +1 -1
  55. package/esm/logLevels.js.map +1 -1
  56. package/esm/logStore.d.ts.map +1 -1
  57. package/esm/logStore.js.map +1 -1
  58. package/esm/logger.d.ts.map +1 -1
  59. package/esm/logger.js +1 -1
  60. package/esm/logger.js.map +1 -1
  61. package/esm/memory.d.ts +2 -2
  62. package/esm/memory.d.ts.map +1 -1
  63. package/esm/memory.js +15 -8
  64. package/esm/memory.js.map +1 -1
  65. package/esm/platform.d.ts.map +1 -1
  66. package/esm/platform.js +1 -2
  67. package/esm/platform.js.map +1 -1
  68. package/esm/standardLog.ctx.d.ts.map +1 -1
  69. package/esm/standardLog.ctx.js.map +1 -1
  70. package/esm/standardLog.d.ts +2 -2
  71. package/esm/standardLog.d.ts.map +1 -1
  72. package/esm/standardLog.js +23 -18
  73. package/esm/standardLog.js.map +1 -1
  74. package/esm/types.d.ts +12 -12
  75. package/esm/types.d.ts.map +1 -1
  76. package/esm/types.js.map +1 -1
  77. package/package.json +17 -9
  78. package/ts/console.ts +54 -45
  79. package/ts/errors.ts +6 -6
  80. package/ts/formatter.ts +18 -18
  81. package/ts/index.ts +21 -6
  82. package/ts/logLevels.ts +90 -91
  83. package/ts/logStore.ts +46 -37
  84. package/ts/logger.ts +67 -57
  85. package/ts/memory.ts +66 -54
  86. package/ts/platform.ts +2 -2
  87. package/ts/standardLog.ctx.ts +2 -2
  88. package/ts/standardLog.ts +113 -94
  89. package/ts/types.ts +72 -62
package/ts/logger.ts CHANGED
@@ -4,71 +4,81 @@ import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogR
4
4
  import { LogLevel } from './types.js'
5
5
 
6
6
  export function createLogger<N extends string = LogMethodNames>(
7
- store: LogStore, id: string, options?: LoggerOptions
7
+ store: LogStore,
8
+ id: string,
9
+ options?: LoggerOptions
8
10
  ): Logger<N | LogMethodNames> {
9
- id = sanitizeId(id)
10
- const writeTo = options?.writeTo ?? (() => true)
11
- const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'
12
- ? [id => id === writeTo, store.reporters]
13
- : writeTo instanceof RegExp
14
- ? [id => writeTo.test(id), store.reporters]
15
- : typeof writeTo === 'function'
16
- ? [writeTo, store.reporters]
17
- : [() => true, [writeTo]]
11
+ id = sanitizeId(id)
12
+ const writeTo = options?.writeTo ?? (() => true)
13
+ const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] =
14
+ typeof writeTo === 'string'
15
+ ? [id => id === writeTo, store.reporters]
16
+ : writeTo instanceof RegExp
17
+ ? [id => writeTo.test(id), store.reporters]
18
+ : typeof writeTo === 'function'
19
+ ? [writeTo, store.reporters]
20
+ : [() => true, [writeTo]]
18
21
 
19
- function write(entry: LogEntry) {
20
- writeToReporters(reporters, entry, filter)
21
- }
22
+ function write(entry: LogEntry) {
23
+ writeToReporters(reporters, entry, filter)
24
+ }
22
25
 
23
- const logger = {
24
- level: options?.level,
25
- write
26
- } as any
26
+ const logger = {
27
+ level: options?.level,
28
+ write
29
+ } as any
27
30
 
28
- Object.defineProperties(logger, {
29
- id: { value: id, writable: false },
30
- count: {
31
- writable: false,
32
- value: ((counter) => (...args: any[]) => {
33
- if (shouldLog(store, logLevels.debug, logger.level))
34
- write({
35
- id,
36
- level: logLevels.debug,
37
- args: [++counter, ...args],
38
- timestamp: new Date()
39
- })
40
- })(0)
41
- },
42
- on: {
43
- writable: false,
44
- value: (level: number | N | LogMethodNames, logFn: LogFunction) => {
45
- const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level
46
- if (shouldLog(store, logLevel, logger.level)) {
47
- const methodName = store.logLevelStore.getName(logLevel)
48
- const bindedMethod = logger[methodName].bind(logger)
49
- const result = logFn(bindedMethod, logger.level ?? store.logLevel)
50
- if (result) bindedMethod(result)
51
- }
52
- }
53
- }
54
- })
55
- store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
56
- Object.defineProperty(logger, name, {
57
- writable: false,
58
- value: (...args: any[]) => {
59
- if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })
60
- }
61
- })
62
- })
63
- return logger
31
+ Object.defineProperties(logger, {
32
+ id: { value: id, writable: false },
33
+ count: {
34
+ writable: false,
35
+ value: (
36
+ counter =>
37
+ (...args: any[]) => {
38
+ if (shouldLog(store, logLevels.debug, logger.level))
39
+ write({
40
+ id,
41
+ level: logLevels.debug,
42
+ args: [++counter, ...args],
43
+ timestamp: new Date()
44
+ })
45
+ }
46
+ )(0)
47
+ },
48
+ on: {
49
+ writable: false,
50
+ value: (level: number | N | LogMethodNames, logFn: LogFunction) => {
51
+ const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level
52
+ if (shouldLog(store, logLevel, logger.level)) {
53
+ const methodName = store.logLevelStore.getName(logLevel)
54
+ const bindedMethod = logger[methodName].bind(logger)
55
+ const result = logFn(bindedMethod, logger.level ?? store.logLevel)
56
+ if (result) bindedMethod(result)
57
+ }
58
+ }
59
+ }
60
+ })
61
+ store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
62
+ Object.defineProperty(logger, name, {
63
+ writable: false,
64
+ value: (...args: any[]) => {
65
+ if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })
66
+ }
67
+ })
68
+ })
69
+ return logger
64
70
  }
65
71
 
66
72
  function sanitizeId(id: string) {
67
- return id.replace(/[`~!#$%^&*()=+[\]{},|<>?]/g, '-')
73
+ return id.replace(/[`~!#$%^&*()=+[\]{},|<>?]/g, '-')
68
74
  }
69
75
 
70
- function writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {
71
- reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))
76
+ function writeToReporters(
77
+ reporters: LogReporter[],
78
+ logEntry: LogEntry,
79
+ filter: (reporterId: string) => boolean
80
+ ) {
81
+ reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))
72
82
  }
73
83
 
74
84
  /**
@@ -77,5 +87,5 @@ function writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter:
77
87
  * It can be undefined which the global log level will be used.
78
88
  */
79
89
  function shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {
80
- return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)
90
+ return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)
81
91
  }
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()
@@ -3,6 +3,6 @@ import type { LogStore } from './logStore.js'
3
3
  import type { LogMethodNames, StandardLogInstance } from './types.js'
4
4
 
5
5
  export const ctx: {
6
- configured?: boolean,
7
- gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
6
+ configured?: boolean
7
+ gsl?: { store: LogStore; standardLog: StandardLogInstance<LogMethodNames> }
8
8
  } = record()
package/ts/standardLog.ts CHANGED
@@ -4,88 +4,103 @@ import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'
4
4
  import { createLogStore, LogStore } from './logStore.js'
5
5
  import { createMemoryLogReporter, MemoryLogReporter } from './memory.js'
6
6
  import { ctx } from './standardLog.ctx.js'
7
- import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js'
7
+ import type {
8
+ Logger,
9
+ LoggerOptions,
10
+ LogLevel,
11
+ LogMethodNames,
12
+ StandardLogInstance,
13
+ StandardLogOptions
14
+ } from './types.js'
8
15
 
9
- export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
10
- }
16
+ export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {}
11
17
 
12
18
  export function createStandardLog<N extends string = LogMethodNames>(
13
- options?: StandardLogOptions<N>
19
+ options?: StandardLogOptions<N>
14
20
  ): StandardLog<N> {
15
- const closure = createStandardLogClosure(options)
16
- if (options?.reporters?.some(r => !r.id)) {
17
- const log = closure.standardLog.getLogger('standard-log')
18
- 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.`)
19
- }
20
-
21
- if (!ctx.gsl) ctx.gsl = closure as any
22
- return closure.standardLog
21
+ const closure = createStandardLogClosure(options)
22
+ if (options?.reporters?.some(r => !r.id)) {
23
+ const log = closure.standardLog.getLogger('standard-log')
24
+ log.critical(
25
+ `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.`
26
+ )
27
+ }
28
+
29
+ if (!ctx.gsl) ctx.gsl = closure as any
30
+ return closure.standardLog
23
31
  }
24
32
 
25
- function noop() { }
33
+ function noop() {}
26
34
 
27
35
  export function createStandardLogClosure<N extends string = LogMethodNames>(
28
- options?: StandardLogOptions<N>
29
- ): { store: LogStore, standardLog: StandardLog<N> } {
30
- // TODO reporter.id must not be empty
31
- const store = createLogStore(required({ logLevel: logLevels.info }, options))
32
- const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []
33
- const logMethods = DEFAULT_LOG_METHOD_NAMES
34
- .concat(Object.keys(options?.customLevels ?? {}))
35
- .concat(['on', 'count', 'write'])
36
- return {
37
- store,
38
- standardLog: {
39
- get logLevel() { return store.logLevel },
40
-
41
- toLogLevelName(level: number) {
42
- return store.logLevelStore.getName(level)
43
- },
44
- toLogLevel(name: string) {
45
- return store.logLevelStore.getLevel(name)
46
- },
47
- getLogger(id: string, options?: LoggerOptions) {
48
- if (store.loggers[id]) return store.loggers[id] as any
49
- return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any
50
- },
51
- getNonConsoleLogger(id, options?) {
52
- if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any
53
-
54
- if (store.loggers[id]) {
55
- const log = this.getLogger('standard-log')
56
- log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)
57
- return store.nonConsoleLoggers[id] = createDummyLogger(logMethods)
58
- }
59
-
60
- return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0
61
- ? createDummyLogger(logMethods)
62
- : createLogger(store, id, {
63
- ssf: this.getNonConsoleLogger,
64
- ...options,
65
- writeTo(reporterId) {
66
- return nonConsoleReporters.indexOf(reporterId) >= 0
67
- }
68
- })
69
- },
70
- }
71
- }
36
+ options?: StandardLogOptions<N>
37
+ ): { store: LogStore; standardLog: StandardLog<N> } {
38
+ // TODO reporter.id must not be empty
39
+ const store = createLogStore(required({ logLevel: logLevels.info }, options))
40
+ const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []
41
+ const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([
42
+ 'on',
43
+ 'count',
44
+ 'write'
45
+ ])
46
+ return {
47
+ store,
48
+ standardLog: {
49
+ get logLevel() {
50
+ return store.logLevel
51
+ },
52
+
53
+ toLogLevelName(level: number) {
54
+ return store.logLevelStore.getName(level)
55
+ },
56
+ toLogLevel(name: string) {
57
+ return store.logLevelStore.getLevel(name)
58
+ },
59
+ getLogger(id: string, options?: LoggerOptions) {
60
+ if (store.loggers[id]) return store.loggers[id] as any
61
+ return (store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any)
62
+ },
63
+ getNonConsoleLogger(id, options?) {
64
+ if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any
65
+
66
+ if (store.loggers[id]) {
67
+ const log = this.getLogger('standard-log')
68
+ log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)
69
+ return (store.nonConsoleLoggers[id] = createDummyLogger(logMethods))
70
+ }
71
+
72
+ return (store.nonConsoleLoggers[id] =
73
+ nonConsoleReporters.length === 0
74
+ ? createDummyLogger(logMethods)
75
+ : createLogger(store, id, {
76
+ ssf: this.getNonConsoleLogger,
77
+ ...options,
78
+ writeTo(reporterId) {
79
+ return nonConsoleReporters.indexOf(reporterId) >= 0
80
+ }
81
+ }))
82
+ }
83
+ }
84
+ }
72
85
  }
73
86
 
74
87
  function createDummyLogger(logMethods: string[]) {
75
- return logMethods.reduce((p, m) => {
76
- p[m] = noop
77
- return p
78
- }, record()) as Logger
88
+ return logMethods.reduce((p, m) => {
89
+ p[m] = noop
90
+ return p
91
+ }, record()) as Logger
79
92
  }
80
93
 
81
- export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & { reporter: MemoryLogReporter }
94
+ export type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
95
+ reporter: MemoryLogReporter
96
+ }
82
97
 
83
98
  export function createStandardLogForTest<N extends string = LogMethodNames>(
84
- logLevel: LogLevel = logLevels.debug
99
+ logLevel: LogLevel = logLevels.debug
85
100
  ): StandardLogForTest<N> {
86
- const reporter = createMemoryLogReporter()
87
- const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })
88
- return { ...closure.standardLog, reporter }
101
+ const reporter = createMemoryLogReporter()
102
+ const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })
103
+ return { ...closure.standardLog, reporter }
89
104
  }
90
105
 
91
106
  /**
@@ -93,43 +108,47 @@ export function createStandardLogForTest<N extends string = LogMethodNames>(
93
108
  */
94
109
  export function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R
95
110
  export function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {
96
- const origLevels = logs.map(l => l.level)
97
- logs.forEach(l => l.level = logLevels.none)
98
- const result = block()
99
- logs.forEach((l, i) => l.level = origLevels[i])
100
- return result
111
+ const origLevels = logs.map(l => l.level)
112
+ logs.forEach(l => (l.level = logLevels.none))
113
+ const result = block()
114
+ logs.forEach((l, i) => (l.level = origLevels[i]))
115
+ return result
101
116
  }
102
117
 
103
- export type GetLogger<N extends string = LogMethodNames> = (id: string, options?: LoggerOptions) => Logger<LogMethodNames | N>
118
+ export type GetLogger<N extends string = LogMethodNames> = (
119
+ id: string,
120
+ options?: LoggerOptions
121
+ ) => Logger<LogMethodNames | N>
104
122
 
105
123
  export function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {
106
- return getGlobalSL<N>().getLogger(id, options)
124
+ return getGlobalSL<N>().getLogger(id, options)
107
125
  }
108
126
 
109
127
  function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
110
- if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
128
+ if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
111
129
 
112
- return ctx.gsl!.standardLog as StandardLogInstance<N>
130
+ return ctx.gsl!.standardLog as StandardLogInstance<N>
113
131
  }
114
132
 
115
133
  export function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {
116
- if (ctx.configured) {
117
- const log = ctx.gsl!.standardLog.getLogger('standard-log')
118
- log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')
119
- }
120
-
121
- if (ctx.gsl) {
122
- if (options.logLevel) {
123
- ctx.gsl.store.logLevel = options.logLevel
124
- }
125
- if (options.reporters) {
126
- const reporters = ctx.gsl.store.reporters
127
- reporters.length = 0
128
- reporters.push(...options.reporters)
129
- }
130
- }
131
- else {
132
- ctx.gsl = createStandardLogClosure(options)
133
- }
134
- ctx.configured = true
134
+ if (ctx.configured) {
135
+ const log = ctx.gsl!.standardLog.getLogger('standard-log')
136
+ log.warn(
137
+ 'configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.'
138
+ )
139
+ }
140
+
141
+ if (ctx.gsl) {
142
+ if (options.logLevel) {
143
+ ctx.gsl.store.logLevel = options.logLevel
144
+ }
145
+ if (options.reporters) {
146
+ const reporters = ctx.gsl.store.reporters
147
+ reporters.length = 0
148
+ reporters.push(...options.reporters)
149
+ }
150
+ } else {
151
+ ctx.gsl = createStandardLogClosure(options)
152
+ }
153
+ ctx.configured = true
135
154
  }