From 1c709f5f73e35a6e6d37e490523bd2d90cca45db Mon Sep 17 00:00:00 2001 From: vanilla-wave Date: Wed, 28 Aug 2024 11:42:42 +0200 Subject: [PATCH] fix: add default logger options --- src/controller.ts | 8 +++++++- src/logger.ts | 6 +----- src/promo-manager/core/controller.ts | 15 +++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/controller.ts b/src/controller.ts index 94c610c..cdcfc21 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -9,6 +9,9 @@ type Listener = () => void; let instanceCounter = 0; +const defaultLoggerOptions = { + context: 'Onboarding', +}; const getDefaultBaseState = (): BaseState => ({ availablePresets: [], activePresets: [], @@ -88,7 +91,10 @@ export class Controller {}; -export const createLogger = ({ - level = 'error', - logger = console, - context = 'Onboarding', -}: LoggerOptions) => { +export const createLogger = ({level = 'error', logger = console, context}: LoggerOptions) => { return { debug: level === 'debug' diff --git a/src/promo-manager/core/controller.ts b/src/promo-manager/core/controller.ts index 772fe14..9b1b711 100644 --- a/src/promo-manager/core/controller.ts +++ b/src/promo-manager/core/controller.ts @@ -41,6 +41,10 @@ const defaultInitOptions: InitPromoManagerOptions = { timeout: 0, }; +const defaultLoggerOptions = { + context: 'Promo manager', +}; + const delay = (timeout: number) => new Promise((resolve) => { setTimeout(resolve, timeout); @@ -72,11 +76,10 @@ export class Controller { this.status = 'idle'; - this.logger = createLogger( - this.options.logger ?? { - context: 'Promo manager', - }, - ); + this.logger = createLogger({ + ...defaultLoggerOptions, + ...this.options.logger, + }); this.logger.debug('Initialization started'); this.state = JSON.parse( @@ -543,7 +546,7 @@ export class Controller { }; private activatePromo = (slug: PromoSlug) => { - this.logger.debug('Actibate promo', slug); + this.logger.debug('Activate promo', slug); this.stateActions.setActivePromo(slug); this.stateActions.removeFromQueue(slug);