Skip to content

Commit

Permalink
adds logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-dupdyke committed Mar 6, 2024
1 parent b6008fa commit 97750ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Ghosts.Api/Controllers/ClientUpdatesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Ghosts.Api.Controllers
[Route("api/[controller]")]
public class ClientUpdatesController : Controller
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
private readonly IBackgroundQueue _queue;
private readonly IMachineUpdateService _updateService;
private readonly IMachineService _machineService;
Expand All @@ -47,7 +47,7 @@ public ClientUpdatesController(IMachineService machineService, IMachineUpdateSer
public async Task<IActionResult> Index(CancellationToken ct)
{
var id = Request.Headers["ghosts-id"];
log.Trace($"Request by {id}");
_log.Trace($"Request by {id}");

var findMachineResponse = await this._machineService.FindOrCreate(HttpContext, ct);
if (!findMachineResponse.IsValid())
Expand All @@ -74,7 +74,7 @@ public async Task<IActionResult> Index(CancellationToken ct)
var u = await _updateService.GetAsync(m.Id, m.CurrentUsername, ct);
if (u == null) return NotFound();

log.Trace($"Update sent to {m.Id} {m.FQDN} {u.Id} {u.Username} {u.Update}");
_log.Trace($"Update sent to {m.Id} {m.FQDN} {u.Id} {u.Username} {u.Update}");

var update = new UpdateClientConfig { Type = u.Type, Update = u.Update };

Expand Down
2 changes: 1 addition & 1 deletion src/Ghosts.Api/Controllers/MachineUpdatesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Ghosts.Api.Controllers
[Route("api/[controller]")]
public class MachineUpdatesController : Controller
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
private readonly IBackgroundQueue _queue;
private readonly IMachineUpdateService _updateService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,24 @@ public async Task<MachineUpdate> GetAsync(Guid machineId, string currentUsername
var update = await _context.MachineUpdates
.FirstOrDefaultAsync(m => (m.MachineId == machineId) && m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct);

_log.Trace($"Update by machine id {machineId} is {update == null}");

if (update != null && !string.IsNullOrEmpty(update.Update))
{
// if the username is there, but the machine id is not
if (!string.IsNullOrEmpty(currentUsername) && machineId == Guid.Empty)
{
update = await _context.MachineUpdates
.FirstOrDefaultAsync(m => (m.Username.ToLower().StartsWith(currentUsername.ToLower())) && m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct);
_log.Trace($"Update by username {currentUsername} is {update == null}");
}
else // pick either
{
update = await _context.MachineUpdates
.FirstOrDefaultAsync(
m => (m.MachineId == machineId || m.Username.ToLower().StartsWith(currentUsername.ToLower())) &&
m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct);
_log.Trace($"Update by either {machineId} or {currentUsername} is {update == null}");
}
}

Expand Down

0 comments on commit 97750ec

Please sign in to comment.