@@ -8,10 +8,9 @@ import type {
8
8
LoggerMethods ,
9
9
NameSpaceConfig ,
10
10
OutputAdapter ,
11
- } from './definitions'
12
-
13
- import * as outputs from './output_adapters'
14
- import * as outputUtils from './output_utils'
11
+ } from './definitions.js'
12
+ import * as outputs from './output_adapters.js'
13
+ import * as outputUtils from './output_utils.js'
15
14
16
15
/************* LOCAL STATE *************/
17
16
const defaultConfig : Readonly < LoggerConfig > = {
@@ -23,7 +22,7 @@ const defaultConfig: Readonly<LoggerConfig> = {
23
22
globalContext : { } ,
24
23
}
25
24
26
- const mutableConfig : LoggerConfig = {
25
+ const sharedConfig : LoggerConfig = {
27
26
...defaultConfig ,
28
27
}
29
28
@@ -92,7 +91,7 @@ const parseNamespace = (namespace: string): NameSpaceConfig | undefined => {
92
91
export const createLogger = (
93
92
namespace = '' ,
94
93
canForceWrite = false ,
95
- config = mutableConfig
94
+ config = sharedConfig
96
95
) : Logger => {
97
96
if ( config . loggers [ namespace ] ) return config . loggers [ namespace ]
98
97
@@ -158,7 +157,7 @@ export const id = (): string => uuidv4()
158
157
/**
159
158
* Define enabled / disabled namespaces
160
159
*/
161
- export const setNamespaces = ( namespaceStr : string , config = mutableConfig ) : void => {
160
+ export const setNamespaces = ( namespaceStr : string , config = sharedConfig ) : void => {
162
161
config . namespaces = namespaceStr
163
162
. split ( ',' )
164
163
. map ( parseNamespace )
@@ -168,7 +167,7 @@ export const setNamespaces = (namespaceStr: string, config = mutableConfig): voi
168
167
/**
169
168
* Change log level
170
169
*/
171
- export const setLevel = ( level : LogLevel , config = mutableConfig ) : void => {
170
+ export const setLevel = ( level : LogLevel , config = sharedConfig ) : void => {
172
171
const levelIndex = config . levels . indexOf ( level )
173
172
if ( levelIndex === - 1 ) throw new Error ( `Invalid log level: ${ level } ` )
174
173
config . level = levelIndex
@@ -179,7 +178,7 @@ export const setLevel = (level: LogLevel, config = mutableConfig): void => {
179
178
*/
180
179
export const setOutput = (
181
180
outputAdapters : OutputAdapter [ ] | OutputAdapter ,
182
- config = mutableConfig
181
+ config = sharedConfig
183
182
) : void => {
184
183
config . outputs = Array . isArray ( outputAdapters ) ? outputAdapters : [ outputAdapters ]
185
184
}
@@ -190,10 +189,7 @@ export const setOutput = (
190
189
* Be warned this context will be added to all logs,
191
190
* even those from third party libraries if they use this module.
192
191
*/
193
- export const setGlobalContext = (
194
- context : Record < string , unknown > ,
195
- config = mutableConfig
196
- ) : void => {
192
+ export const setGlobalContext = ( context : Record < string , unknown > , config = sharedConfig ) : void => {
197
193
config . globalContext = { ...context }
198
194
}
199
195
@@ -205,7 +201,7 @@ setNamespaces(namespaces)
205
201
setLevel ( logLevel )
206
202
207
203
/************* EXPORT *************/
208
- export * from './definitions'
204
+ export * from './definitions.js '
209
205
export { outputUtils , outputs }
210
206
export default {
211
207
createLogger,
0 commit comments