Skip to content

Commit

Permalink
Set log level for battery update to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Nov 28, 2024
1 parent ac36b4d commit ebdc080
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public async Task<Robot> UpdateRobotStatus(string robotId, RobotStatus status)

public async Task<Robot> UpdateRobotBatteryLevel(string robotId, float batteryLevel)
{
var robot = await UpdateRobotProperty(robotId, "BatteryLevel", batteryLevel);
var robot = await UpdateRobotProperty(robotId, "BatteryLevel", batteryLevel, isLogLevelDebug: true);
ThrowIfRobotIsNull(robot, robotId);
return robot;
}
Expand Down Expand Up @@ -317,7 +317,7 @@ private IQueryable<Robot> GetRobotsWithSubModels(bool readOnly = true)
return readOnly ? query.AsNoTracking() : query.AsTracking();
}

private async Task<Robot> UpdateRobotProperty(string robotId, string propertyName, object? value)
private async Task<Robot> UpdateRobotProperty(string robotId, string propertyName, object? value, bool isLogLevelDebug = false)
{
var robot = await ReadById(robotId, readOnly: false);
if (robot is null)
Expand All @@ -331,7 +331,10 @@ private async Task<Robot> UpdateRobotProperty(string robotId, string propertyNam
{
if (property.Name == propertyName)
{
logger.LogInformation("Setting {robotName} field {propertyName} from {oldValue} to {NewValue}", robot.Name, propertyName, property.GetValue(robot), value);
if (isLogLevelDebug)
logger.LogDebug("Setting {robotName} field {propertyName} from {oldValue} to {NewValue}", robot.Name, propertyName, property.GetValue(robot), value);
else
logger.LogInformation("Setting {robotName} field {propertyName} from {oldValue} to {NewValue}", robot.Name, propertyName, property.GetValue(robot), value);
property.SetValue(robot, value);
}
}
Expand Down

0 comments on commit ebdc080

Please sign in to comment.