Skip to content

Commit bf26c5f

Browse files
committed
fix: optimize init logger
1 parent 6c20f16 commit bf26c5f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/option.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,24 @@ export type TypoaRuntimeOptions = {
2828

2929
export const options: Omit<TypoaRuntimeOptions, 'customLogger'> & {
3030
getCustomLogger: () => CustomLogger
31-
} = {
32-
getCustomLogger: () => initLogger(),
33-
features: {
34-
enableLogUnexpectedAdditionalData: false,
35-
enableThrowOnUnexpectedAdditionalData: false
31+
} = (() => {
32+
const initializedLogger = initLogger()
33+
return {
34+
getCustomLogger: () => initializedLogger,
35+
features: {
36+
enableLogUnexpectedAdditionalData: false,
37+
enableThrowOnUnexpectedAdditionalData: false
38+
}
3639
}
37-
}
40+
})()
3841

3942
/**
4043
* Update options to affect library's behaviour
4144
*/
4245
export function setRuntimeOptions(incomingOptions: TypoaRuntimeOptions): void {
43-
options.getCustomLogger = () => initLogger(incomingOptions.customLogger)
46+
const initializedLogger = initLogger(incomingOptions.customLogger)
47+
48+
options.getCustomLogger = () => initializedLogger
4449
options.features.enableLogUnexpectedAdditionalData =
4550
incomingOptions.features.enableLogUnexpectedAdditionalData ?? false
4651
options.features.enableThrowOnUnexpectedAdditionalData =

0 commit comments

Comments
 (0)