standard-log 11.5.1 → 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.
- package/cjs/console.d.ts +3 -3
- package/cjs/console.d.ts.map +1 -1
- package/cjs/console.js +17 -8
- package/cjs/console.js.map +1 -1
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js.map +1 -1
- package/cjs/formatter.d.ts +1 -1
- package/cjs/formatter.d.ts.map +1 -1
- package/cjs/formatter.js.map +1 -1
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/logLevels.d.ts.map +1 -1
- package/cjs/logLevels.js.map +1 -1
- package/cjs/logStore.d.ts.map +1 -1
- package/cjs/logStore.js.map +1 -1
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +15 -13
- package/cjs/logger.js.map +1 -1
- package/cjs/memory.d.ts +2 -2
- package/cjs/memory.d.ts.map +1 -1
- package/cjs/memory.js +15 -8
- package/cjs/memory.js.map +1 -1
- package/cjs/platform.d.ts.map +1 -1
- package/cjs/platform.js +1 -2
- package/cjs/platform.js.map +1 -1
- package/cjs/standardLog.ctx.d.ts.map +1 -1
- package/cjs/standardLog.ctx.js.map +1 -1
- package/cjs/standardLog.d.ts +2 -2
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +19 -14
- package/cjs/standardLog.js.map +1 -1
- package/cjs/types.d.ts +12 -12
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +1090 -700
- 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 +167 -113
- 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/esm/console.d.ts +3 -3
- package/esm/console.d.ts.map +1 -1
- package/esm/console.js +20 -9
- package/esm/console.js.map +1 -1
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js.map +1 -1
- package/esm/formatter.d.ts +1 -1
- package/esm/formatter.d.ts.map +1 -1
- package/esm/formatter.js.map +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/logLevels.d.ts.map +1 -1
- package/esm/logLevels.js.map +1 -1
- package/esm/logStore.d.ts.map +1 -1
- package/esm/logStore.js.map +1 -1
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +1 -1
- package/esm/logger.js.map +1 -1
- package/esm/memory.d.ts +2 -2
- package/esm/memory.d.ts.map +1 -1
- package/esm/memory.js +15 -8
- package/esm/memory.js.map +1 -1
- package/esm/platform.d.ts.map +1 -1
- package/esm/platform.js +1 -2
- package/esm/platform.js.map +1 -1
- package/esm/standardLog.ctx.d.ts.map +1 -1
- package/esm/standardLog.ctx.js.map +1 -1
- package/esm/standardLog.d.ts +2 -2
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +23 -18
- package/esm/standardLog.js.map +1 -1
- package/esm/types.d.ts +12 -12
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +14 -8
- package/ts/console.ts +54 -45
- package/ts/errors.ts +6 -6
- package/ts/formatter.ts +18 -18
- package/ts/index.ts +21 -6
- package/ts/logLevels.ts +90 -91
- package/ts/logStore.ts +46 -37
- package/ts/logger.ts +67 -57
- package/ts/memory.ts +66 -54
- package/ts/platform.ts +2 -2
- package/ts/standardLog.ctx.ts +2 -2
- package/ts/standardLog.ts +113 -94
- package/ts/types.ts +72 -62
package/ts/console.ts
CHANGED
|
@@ -5,66 +5,75 @@ import { polyfill } from './platform.js'
|
|
|
5
5
|
import type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
|
|
6
6
|
|
|
7
7
|
export function toConsoleMethod(level: number) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
switch (true) {
|
|
9
|
+
// edge case in case none is somehow written
|
|
10
|
+
case level <= 0:
|
|
11
|
+
return 'debug'
|
|
12
|
+
case level <= logLevels.error:
|
|
13
|
+
return 'error'
|
|
14
|
+
case level <= logLevels.warn:
|
|
15
|
+
return 'warn'
|
|
16
|
+
case level <= logLevels.info:
|
|
17
|
+
return 'info'
|
|
18
|
+
default:
|
|
19
|
+
return 'debug'
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
// istanbul ignore next
|
|
19
24
|
/* eslint-disable no-console */
|
|
20
25
|
function buildPolyfillConsole() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
26
|
+
// old phantomjs does not have bind function
|
|
27
|
+
const hasBind = !!console.log.bind as boolean
|
|
28
|
+
if (hasBind) {
|
|
29
|
+
return {
|
|
30
|
+
// the `typeof` guards against IE where `console.log.apply()`
|
|
31
|
+
// results in error `Object doesn't support property or method 'apply'`
|
|
32
|
+
debug: (typeof console.info === 'function' ? console.debug : console.log).bind(console),
|
|
33
|
+
info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
|
|
34
|
+
warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
|
|
35
|
+
error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
return {
|
|
39
|
+
debug: buildFn(typeof console.debug === 'function' ? 'debug' : 'log'),
|
|
40
|
+
info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
|
|
41
|
+
warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
|
|
42
|
+
error: buildFn(typeof console.error === 'function' ? 'error' : 'log')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
// istanbul ignore next
|
|
44
48
|
function buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {
|
|
45
|
-
|
|
49
|
+
return function (...args: any[]) {
|
|
50
|
+
console[name](...args)
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
|
|
49
54
|
export type ConsoleLogFormatter = LogFormatter<any[]>
|
|
50
55
|
export type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }
|
|
51
56
|
export type ConsoleLogReporterOptions = LogReporterOptions<any[]>
|
|
52
57
|
|
|
53
58
|
export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
const { id, formatter, filter } = unpartial({ id: 'console', formatter: consoleFormatter }, options)
|
|
60
|
+
if (!polyfill.console) polyfill.console = buildPolyfillConsole()
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
id,
|
|
64
|
+
isConsoleReporter: true,
|
|
65
|
+
get formatter() {
|
|
66
|
+
return formatter
|
|
67
|
+
},
|
|
68
|
+
get filter() {
|
|
69
|
+
return filter
|
|
70
|
+
},
|
|
71
|
+
console: polyfill.console,
|
|
72
|
+
write(entry: LogEntry) {
|
|
73
|
+
if (filter && !filter(entry)) return
|
|
74
|
+
const values = formatter(entry)
|
|
75
|
+
const method = toConsoleMethod(entry.level)
|
|
76
|
+
this.console[method](...values)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
70
79
|
}
|
package/ts/errors.ts
CHANGED
|
@@ -4,16 +4,16 @@ import { IsoError, ModuleError } from 'iso-error'
|
|
|
4
4
|
* @deprecated No longer used since 11.2.0
|
|
5
5
|
*/
|
|
6
6
|
export class StandardLogError extends ModuleError {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
constructor(description: string, options?: IsoError.Options) {
|
|
8
|
+
super('standard-log', description, options)
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated no longer used since 11.2.0
|
|
14
14
|
*/
|
|
15
15
|
export class InvalidId extends StandardLogError {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
constructor(public id: string, options?: IsoError.Options) {
|
|
17
|
+
super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)
|
|
18
|
+
}
|
|
19
19
|
}
|
package/ts/formatter.ts
CHANGED
|
@@ -6,25 +6,25 @@ import type { LogEntry } from './types.js'
|
|
|
6
6
|
export type TimestampFormat = 'none' | 'iso' | 'elapsed'
|
|
7
7
|
|
|
8
8
|
export function createTimestampFormatter(format: TimestampFormat): (timestamp: Date) => string | undefined {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
switch (format) {
|
|
10
|
+
case 'none':
|
|
11
|
+
return (_timestamp: Date) => undefined
|
|
12
|
+
case 'iso':
|
|
13
|
+
return (timestamp: Date) => timestamp.toISOString()
|
|
14
|
+
case 'elapsed': {
|
|
15
|
+
let lastTick: number
|
|
16
|
+
return (timestamp: Date) => {
|
|
17
|
+
const newTick = timestamp.getTime()
|
|
18
|
+
const result = ms(lastTick === undefined ? 0 : newTick - lastTick)
|
|
19
|
+
lastTick = newTick
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function formatLogLevel(level: number) {
|
|
27
|
-
|
|
27
|
+
return `(${upperCase(toLogLevelName(level))})`
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -34,12 +34,12 @@ export function formatLogLevel(level: number) {
|
|
|
34
34
|
* This is typically useful for writing logs to file
|
|
35
35
|
*/
|
|
36
36
|
export function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {
|
|
37
|
-
|
|
37
|
+
return [timestamp.toISOString(), id, formatLogLevel(level), ...args]
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Formats log entry like default console log.
|
|
42
42
|
*/
|
|
43
43
|
export function consoleFormatter({ args }: LogEntry) {
|
|
44
|
-
|
|
44
|
+
return args
|
|
45
45
|
}
|
package/ts/index.ts
CHANGED
|
@@ -4,13 +4,28 @@ export * from './formatter.js'
|
|
|
4
4
|
export * from './logLevels.js'
|
|
5
5
|
export * from './memory.js'
|
|
6
6
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
configGlobal,
|
|
8
|
+
createStandardLog,
|
|
9
|
+
createStandardLogForTest,
|
|
10
|
+
getLogger,
|
|
11
|
+
suppressLogs
|
|
9
12
|
} from './standardLog.js'
|
|
10
13
|
export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'
|
|
11
14
|
export type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
ConsoleLike,
|
|
16
|
+
LogEntry,
|
|
17
|
+
LogFilter,
|
|
18
|
+
LogFormatter,
|
|
19
|
+
LogFunction,
|
|
20
|
+
Logger,
|
|
21
|
+
LoggerOptions,
|
|
22
|
+
LogLevel,
|
|
23
|
+
LogLevelEntry,
|
|
24
|
+
LogMethod,
|
|
25
|
+
LogMethodNames,
|
|
26
|
+
LogReporter,
|
|
27
|
+
LogReporterOptions,
|
|
28
|
+
ReporterFilter,
|
|
29
|
+
StandardLogInstance,
|
|
30
|
+
StandardLogOptions
|
|
15
31
|
} from './types.js'
|
|
16
|
-
|
package/ts/logLevels.ts
CHANGED
|
@@ -1,108 +1,107 @@
|
|
|
1
|
-
|
|
2
1
|
export const logLevels = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
2
|
+
/**
|
|
3
|
+
* none: 0
|
|
4
|
+
*/
|
|
5
|
+
none: 0 as const,
|
|
6
|
+
/**
|
|
7
|
+
* emergency: 100
|
|
8
|
+
*
|
|
9
|
+
* emergency -> alert
|
|
10
|
+
*/
|
|
11
|
+
emergency: 100 as const,
|
|
12
|
+
/**
|
|
13
|
+
* alert: 200
|
|
14
|
+
*
|
|
15
|
+
* emergency -> alert -> critical
|
|
16
|
+
*/
|
|
17
|
+
alert: 200 as const,
|
|
18
|
+
/**
|
|
19
|
+
* critical: 300
|
|
20
|
+
*
|
|
21
|
+
* alert -> critical -> error
|
|
22
|
+
*/
|
|
23
|
+
critical: 300 as const,
|
|
24
|
+
/**
|
|
25
|
+
* error: 400
|
|
26
|
+
*
|
|
27
|
+
* critical -> error -> warn
|
|
28
|
+
*/
|
|
29
|
+
error: 400 as const,
|
|
30
|
+
/**
|
|
31
|
+
* warn: 500
|
|
32
|
+
*
|
|
33
|
+
* error -> warn -> notice
|
|
34
|
+
*/
|
|
35
|
+
warn: 500 as const,
|
|
36
|
+
/**
|
|
37
|
+
* notice: 600
|
|
38
|
+
*
|
|
39
|
+
* warn -> notice -> info
|
|
40
|
+
*/
|
|
41
|
+
notice: 600 as const,
|
|
42
|
+
/**
|
|
43
|
+
* info: 700
|
|
44
|
+
*
|
|
45
|
+
* notice -> info -> debug
|
|
46
|
+
*/
|
|
47
|
+
info: 700 as const,
|
|
48
|
+
/**
|
|
49
|
+
* debug: 800
|
|
50
|
+
*
|
|
51
|
+
* info -> debug -> trace
|
|
52
|
+
*/
|
|
53
|
+
debug: 800 as const,
|
|
54
|
+
/**
|
|
55
|
+
* trace: 900
|
|
56
|
+
*
|
|
57
|
+
* debug -> trace -> planck
|
|
58
|
+
*/
|
|
59
|
+
trace: 900 as const,
|
|
60
|
+
/**
|
|
61
|
+
* planck: Infinity
|
|
62
|
+
* `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.
|
|
63
|
+
*
|
|
64
|
+
* trace -> planck
|
|
65
|
+
*/
|
|
66
|
+
planck: Infinity,
|
|
67
|
+
/**
|
|
68
|
+
* all: Infinity
|
|
69
|
+
*/
|
|
70
|
+
all: Infinity
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
/**
|
|
75
74
|
* Convert default log level value to log level name.
|
|
76
75
|
*/
|
|
77
76
|
export function toLogLevelName(level: number) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
if (level <= 100) return 'emergency'
|
|
78
|
+
if (level <= 200) return 'alert'
|
|
79
|
+
if (level <= 300) return 'critical'
|
|
80
|
+
if (level <= 400) return 'error'
|
|
81
|
+
if (level <= 500) return 'warn'
|
|
82
|
+
if (level <= 600) return 'notice'
|
|
83
|
+
if (level <= 700) return 'info'
|
|
84
|
+
if (level <= 800) return 'debug'
|
|
85
|
+
if (level <= 900) return 'trace'
|
|
86
|
+
return 'planck'
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
/**
|
|
91
90
|
* Convert default log level name to log level value.
|
|
92
91
|
*/
|
|
93
92
|
export function toLogLevel(name: string): number | undefined {
|
|
94
|
-
|
|
93
|
+
return (logLevels as any)[name.toLocaleLowerCase()]
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
export const DEFAULT_LOG_METHOD_NAMES: string[] = [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
'emergency',
|
|
98
|
+
'alert',
|
|
99
|
+
'critical',
|
|
100
|
+
'error',
|
|
101
|
+
'warn',
|
|
102
|
+
'notice',
|
|
103
|
+
'info',
|
|
104
|
+
'debug',
|
|
105
|
+
'trace',
|
|
106
|
+
'planck'
|
|
108
107
|
]
|
package/ts/logStore.ts
CHANGED
|
@@ -1,54 +1,63 @@
|
|
|
1
|
-
|
|
2
1
|
import { mapKey, record, reduceByKey, reduceKey } from 'type-plus'
|
|
3
2
|
import { createConsoleLogReporter } from './console.js'
|
|
4
3
|
import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'
|
|
5
4
|
import type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'
|
|
6
5
|
|
|
7
|
-
export function createLogStore<N extends string = LogMethodNames>(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export function createLogStore<N extends string = LogMethodNames>(
|
|
7
|
+
options: Required<StandardLogOptions<N>>
|
|
8
|
+
): LogStore {
|
|
9
|
+
return {
|
|
10
|
+
loggers: record(),
|
|
11
|
+
nonConsoleLoggers: record(),
|
|
12
|
+
reporters: options.reporters || [createConsoleLogReporter()],
|
|
13
|
+
logLevel: options.logLevel,
|
|
14
|
+
logLevelStore: logLevelStore(options)
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export interface LogStore {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
loggers: Record<string, Logger>
|
|
20
|
+
nonConsoleLoggers: Record<string, Logger>
|
|
21
|
+
reporters: LogReporter[]
|
|
22
|
+
logLevel: LogLevel
|
|
23
|
+
logLevelStore: ReturnType<typeof logLevelStore>
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface LogLevelStoreOptions {
|
|
26
|
-
|
|
27
|
+
customLevels?: Record<string, number>
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export function logLevelStore(options: LogLevelStoreOptions) {
|
|
30
|
-
|
|
31
|
+
const customLevels = options.customLevels || record()
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
const store = {
|
|
34
|
+
customLevels,
|
|
35
|
+
customLevelsReverse: reduceByKey(
|
|
36
|
+
customLevels,
|
|
37
|
+
(p, k) => {
|
|
38
|
+
p[customLevels[k]] = k
|
|
39
|
+
return p
|
|
40
|
+
},
|
|
41
|
+
{} as Record<number, string>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
getName(level: number) {
|
|
46
|
+
return store.customLevelsReverse[level] ?? toLogLevelName(level)
|
|
47
|
+
},
|
|
48
|
+
getLevel(name: string) {
|
|
49
|
+
return store.customLevels[name] ?? toLogLevel(name)
|
|
50
|
+
},
|
|
51
|
+
getAllLevels() {
|
|
52
|
+
return reduceKey(
|
|
53
|
+
logLevels,
|
|
54
|
+
(result, name) => {
|
|
55
|
+
if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
return result
|
|
58
|
+
},
|
|
59
|
+
mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] }))
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
54
63
|
}
|