From 96600af0ec50d601b2e206ddbf2cea6d990b1d99 Mon Sep 17 00:00:00 2001 From: mdvanes <4253562+mdvanes@users.noreply.github.com> Date: Mon, 13 May 2024 13:11:20 +0200 Subject: [PATCH] fix: add logger --- .../src/energyusage/energyusage.controller.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/server/src/energyusage/energyusage.controller.ts b/apps/server/src/energyusage/energyusage.controller.ts index 5585bd5a..702612bf 100644 --- a/apps/server/src/energyusage/energyusage.controller.ts +++ b/apps/server/src/energyusage/energyusage.controller.ts @@ -132,7 +132,8 @@ const getNormalizedEntries = const getDayUsage = ( day: Date, - usePerDayTotals: GetDomoticzUsePerDayResponse["result"] + usePerDayTotals: GetDomoticzUsePerDayResponse["result"], + logger: Logger ): number | undefined => { const yearMonthDay = day.toISOString().slice(0, 10); try { @@ -144,7 +145,7 @@ const getDayUsage = ( // console.log("dayUsage1", dayUsage, yearMonthDay, dayUsageDay, day); return dayUsage; } catch (err) { - console.log(`Can't get dayUsage for ${yearMonthDay}`); + logger.warn(`Can't get dayUsage for ${yearMonthDay}`); return undefined; } }; @@ -152,7 +153,7 @@ const getDayUsage = ( const ELECTRIC_EXPORTS_ROOT_DIR = "./0_electric_exports"; const exportJsonToRow = - (usePerDayTotals: GetDomoticzUsePerDayResponse["result"]) => + (usePerDayTotals: GetDomoticzUsePerDayResponse["result"], logger: Logger) => async ( fileInDir: string ): Promise => { @@ -170,7 +171,7 @@ const exportJsonToRow = getNormalizedEntries(fileJson) ); - const dayUsage = getDayUsage(day, usePerDayTotals); + const dayUsage = getDayUsage(day, usePerDayTotals, logger); const result: EnergyUsageGetElectricExportsResponse[0] = { exportName: fileInDir, @@ -185,7 +186,7 @@ const exportJsonToRow = return result; } catch (err) { - console.log(`Can't process ${fileInDir}`); + logger.warn(`Can't process ${fileInDir}`); return undefined; } }; @@ -411,7 +412,7 @@ export class EnergyUsageController { await Promise.all( filteredFilesInDir.map< Promise - >(exportJsonToRow(usePerDayTotals)) + >(exportJsonToRow(usePerDayTotals, this.logger)) ); return usagePerDay.filter(isDefined);