Skip to content

Commit

Permalink
Adjusting trace and debug log levels on logged messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fredli74 committed Oct 15, 2024
1 parent 0caa013 commit ea41d38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions providers/nordpool/nordpool-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions providers/tesla/tesla-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ 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
public async maintainToken(job: TeslaAgentJob) {
// 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);
}
Expand Down Expand Up @@ -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") {
Expand All @@ -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 {
Expand Down Expand Up @@ -477,7 +477,7 @@ export class TeslaAgent extends AbstractAgent {
});
}
log(
LogLevel.Trace,
LogLevel.Debug,
`${subject.vin} list poll : ${JSON.stringify(data)}`
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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
)}`
Expand Down
8 changes: 4 additions & 4 deletions providers/tesla/tesla-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;`,
Expand All @@ -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;`,
Expand All @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions server/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ export class Logic {
bestCost = f;
threshold = t;
log(
LogLevel.Trace,
LogLevel.Debug,
`Cost simulation ${vehicle.vehicle_uuid} t=${t} => ${f}`
);
}
Expand Down Expand Up @@ -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({
Expand All @@ -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;
Expand Down

0 comments on commit ea41d38

Please sign in to comment.