From ea41d389800cc6a49846b884eb0b37de039da0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Lidstr=C3=B6m?= Date: Tue, 15 Oct 2024 11:17:08 +0200 Subject: [PATCH] Adjusting trace and debug log levels on logged messages --- providers/nordpool/nordpool-agent.ts | 4 ++-- providers/tesla/tesla-agent.ts | 18 +++++++++--------- providers/tesla/tesla-server.ts | 8 ++++---- server/logic.ts | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/providers/nordpool/nordpool-agent.ts b/providers/nordpool/nordpool-agent.ts index 937694ca..1894d0d7 100644 --- a/providers/nordpool/nordpool-agent.ts +++ b/providers/nordpool/nordpool-agent.ts @@ -92,7 +92,7 @@ export class NordpoolAgent extends AbstractAgent { price: price / 1e3, }); } else { - log(LogLevel.Trace, `Unknown area ${area}`); + log(LogLevel.Debug, `Unknown area ${area}`); } } } @@ -104,7 +104,7 @@ export class NordpoolAgent extends AbstractAgent { continue; } log( - LogLevel.Trace, + LogLevel.Info, `Sending updatePrice for ${name} => ${JSON.stringify(update)}` ); await this.scClient.updatePrice(update); diff --git a/providers/tesla/tesla-agent.ts b/providers/tesla/tesla-agent.ts index 3041b427..e0527b7f 100644 --- a/providers/tesla/tesla-agent.ts +++ b/providers/tesla/tesla-agent.ts @@ -116,7 +116,7 @@ export class TeslaAgent extends AbstractAgent { }); job.serviceData.token = token as TeslaToken; delete job.serviceData.invalid_token; - log(LogLevel.Trace, `Updated token for ${job.serviceID} to ${token.access_token}`); + log(LogLevel.Debug, `Updated token for ${job.serviceID} to ${token.access_token}`); } // Check token and refresh through server provider API @@ -124,7 +124,7 @@ export class TeslaAgent extends AbstractAgent { // API Token check and update const token = job.serviceData.token as TeslaToken; if (TeslaAPI.tokenExpired(token)) { - log(LogLevel.Trace, `${job.serviceID} token expired, calling server API for refresh`); + log(LogLevel.Debug, `${job.serviceID} token expired, calling server API for refresh`); // Token has expired, run it through server await this.refreshToken(job); } @@ -212,7 +212,7 @@ export class TeslaAgent extends AbstractAgent { await teslaAPI.getVehicleData(subject.vin, job.serviceData.token) ).response; log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} full poll : ${JSON.stringify(data)}` ); if (config.AGENT_SAVE_TO_TRACEFILE === "true") { @@ -233,7 +233,7 @@ export class TeslaAgent extends AbstractAgent { ) { if (subject.chargeControl === ChargeControl.Stopped) { log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} trickle-charge fix stop of ${subject.data.name} overridden by user interaction` ); } else { @@ -477,7 +477,7 @@ export class TeslaAgent extends AbstractAgent { }); } log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} list poll : ${JSON.stringify(data)}` ); @@ -565,7 +565,7 @@ export class TeslaAgent extends AbstractAgent { subject.chargeControl = undefined; } - log(LogLevel.Trace, `${subject.vin} ${JSON.stringify(subject)}`); + log(LogLevel.Debug, `${subject.vin} ${JSON.stringify(subject)}`); // Reduce the array to a map with only the first upcoming event of each type const schedule = scheduleMap(subject.data.schedule); @@ -619,7 +619,7 @@ export class TeslaAgent extends AbstractAgent { ) { if (subject.chargeControl === ChargeControl.Stopped) { log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} charge stop of ${subject.data.name} overridden by user interaction` ); } else if ( @@ -639,7 +639,7 @@ export class TeslaAgent extends AbstractAgent { if (subject.chargeEnabled !== true) { if (subject.chargeControl === ChargeControl.Started) { log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} charge start of ${subject.data.name} overridden by user interaction` ); } else if ( @@ -811,7 +811,7 @@ export class TeslaAgent extends AbstractAgent { // TODO: handle different errors? if (err.code === 401) { log( - LogLevel.Trace, + LogLevel.Debug, `${subject.vin} tesla-agent polling error 401 for ${JSON.stringify( job.serviceData )}` diff --git a/providers/tesla/tesla-server.ts b/providers/tesla/tesla-server.ts index 939bf658..4df4d3b1 100644 --- a/providers/tesla/tesla-server.ts +++ b/providers/tesla/tesla-server.ts @@ -56,12 +56,12 @@ export async function maintainServiceToken( ); // If we got a row back, we are the only thread that is refreshing the token if (updateService) { - log(LogLevel.Trace, `Token ${service.service_data.token.access_token} is expired, calling renewToken`); + log(LogLevel.Debug, `Token ${service.service_data.token.access_token} is expired, calling renewToken`); try { const newToken = await teslaAPI.renewToken(service.service_data.token.refresh_token); // Update the token in the database log(LogLevel.Trace, `Token ${service.service_data.token.access_token} renewed to ${newToken.access_token}`); - log(LogLevel.Trace, `Updating service_provider ${service.service_uuid} with new token`); + log(LogLevel.Info, `Updating service_provider ${service.service_uuid} with new token`); await db.pg.none(` UPDATE service_provider SET service_data = jsonb_strip_nulls(service_data || $2) WHERE service_uuid=$1; UPDATE vehicle SET provider_data = jsonb_strip_nulls(provider_data || $3) WHERE service_uuid=$1;`, @@ -75,7 +75,7 @@ export async function maintainServiceToken( } catch (err: any) { if (err && err.message === "login_required") { log(LogLevel.Warning, `Refresh token ${service.service_data.token.refresh_token} is invalid (login_required)`); - log(LogLevel.Trace, `Updating service_provider ${service.service_uuid} with invalid token`); + log(LogLevel.Info, `Setting service_provider ${service.service_uuid} as invalid token status`); await db.pg.none(` UPDATE service_provider SET service_data = jsonb_strip_nulls(service_data || $2) WHERE service_uuid=$1; UPDATE vehicle SET provider_data = jsonb_strip_nulls(provider_data || $3) WHERE service_uuid=$1;`, @@ -95,7 +95,7 @@ export async function maintainServiceToken( throw new ApolloError("Invalid token", "INVALID_TOKEN"); } } else { - log(LogLevel.Trace, `Token ${service.service_data.token.access_token} is already being refreshed, ignoring`); + log(LogLevel.Debug, `Token ${service.service_data.token.access_token} is already being refreshed, ignoring`); return null; } } diff --git a/server/logic.ts b/server/logic.ts index 75efba80..55648dac 100644 --- a/server/logic.ts +++ b/server/logic.ts @@ -771,7 +771,7 @@ export class Logic { bestCost = f; threshold = t; log( - LogLevel.Trace, + LogLevel.Debug, `Cost simulation ${vehicle.vehicle_uuid} t=${t} => ${f}` ); } @@ -1275,7 +1275,7 @@ export class Logic { `${capitalize(chargeType)} charge to ${level}% scheduled`; } else { log( - LogLevel.Trace, + LogLevel.Debug, `${capitalize(chargeType)} charge directly to ${level}%` ); chargePlan.push({ @@ -1293,7 +1293,7 @@ export class Logic { return true; } else { log( - LogLevel.Trace, + LogLevel.Debug, `${level} <= ${startLevel}, no ${chargeType} charge plan added for ${comment}` ); return false;