Skip to content

Commit

Permalink
Properly use Logger (#416)
Browse files Browse the repository at this point in the history
Properly use logger
closes #394
  • Loading branch information
Aaron2550 authored Jan 21, 2024
1 parent d7c0ec2 commit e3df216
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Obsidian/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public async Task StartConnectionAsync()
}
}

Logger.LogInformation($"Disconnected client");
Logger.LogInformation("Disconnected client");

if (State == ClientState.Play)
{
Expand Down Expand Up @@ -603,7 +603,7 @@ internal async Task HandleKeepAliveAsync(KeepAlivePacket keepAlive)
{
if (!missedKeepAlives.Contains(keepAlive.KeepAliveId))
{
Logger.LogWarning($"Received invalid KeepAlive from {Player.Username}?? Naughty???? ({Player.Uuid})");
Logger.LogWarning("Received invalid KeepAlive from {Username}?? Naughty???? ({Uuid})", Player?.Username, Player?.Uuid);
await DisconnectAsync(ChatMessage.Simple("Kicked for invalid KeepAlive."));
return;
}
Expand All @@ -614,7 +614,7 @@ internal async Task HandleKeepAliveAsync(KeepAlivePacket keepAlive)
ping = Math.Max(0, ping); // negative ping is impossible.

this.ping = (int)ping;
Logger.LogDebug($"Valid KeepAlive ({keepAlive.KeepAliveId}) handled from {Player.Username} ({Player.Uuid})");
Logger.LogDebug("Valid KeepAlive ({KeepAliveId}) handled from {Username} ({Uuid})", keepAlive.KeepAliveId, Player?.Username, Player?.Uuid);
// KeepAlive is handled.
missedKeepAlives.Remove(keepAlive.KeepAliveId);
}
Expand Down
8 changes: 4 additions & 4 deletions Obsidian/Net/MinecraftStream.Reading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public ItemStack ReadItemStack()
{
var enchantments = (NbtList)child;

//Globals.PacketLogger.LogDebug($"List Type: {enchantments.ListType}");
//Globals.PacketLogger.LogDebug("List Type: {ListType}", enchantments.ListType);

foreach (var enchantment in enchantments)
{
Expand Down Expand Up @@ -651,7 +651,7 @@ public ItemStack ReadItemStack()
var intTag = (NbtTag<int>)child;

itemMetaBuilder.WithDurability(intTag.Value);
//Globals.PacketLogger.LogDebug($"Setting damage: {tag.IntValue}");
//Globals.PacketLogger.LogDebug("Setting damage: {IntValue}", tag.IntValue);
break;
}

Expand Down Expand Up @@ -733,7 +733,7 @@ public async Task<ItemStack> ReadSlotAsync()
{
var enchantments = (NbtList)child;

//Globals.PacketLogger.LogDebug($"List Type: {enchantments.ListType}");
//Globals.PacketLogger.LogDebug("List Type: {ListType}", enchantments.ListType);

foreach (var enchantment in enchantments)
{
Expand Down Expand Up @@ -761,7 +761,7 @@ public async Task<ItemStack> ReadSlotAsync()
var intTag = (NbtTag<int>)child;

itemMetaBuilder.WithDurability(intTag.Value);
//Globals.PacketLogger.LogDebug($"Setting damage: {tag.IntValue}");
//Globals.PacketLogger.LogDebug("Setting damage: {IntValue}", tag.IntValue);
break;
}
case "display":
Expand Down
4 changes: 2 additions & 2 deletions Obsidian/Net/MinecraftStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task DumpAsync(bool clear = true, IPacket packet = null)
if (clear)
await ClearDebug();

//Globals.PacketLogger.LogDebug($"Dumped stream to {filePath}");
//Globals.PacketLogger.LogDebug("Dumped stream to {FilePath}", filePath);
}

// unused
Expand All @@ -83,7 +83,7 @@ public async Task DumpAsync(bool clear = true, string name = "")
if (clear)
await ClearDebug();

//Globals.PacketLogger.LogDebug($"Dumped stream to {filePath}");
//Globals.PacketLogger.LogDebug("Dumped stream to {FilePath}", filePath);
}

public Task ClearDebug()
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Plugins/PluginProviders/RemotePluginProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private PluginContainer CompilePluginFiles((string owner, string name) repositor
if (diagnostic.Severity != DiagnosticSeverity.Error || diagnostic.IsWarningAsError)
continue;

logger.LogError($"Compilation failed: {diagnostic.Location} {diagnostic.GetMessage()}");
logger.LogError("Compilation failed: {Location} {Message}", diagnostic.Location, diagnostic.GetMessage());
}
}

Expand Down
4 changes: 2 additions & 2 deletions Obsidian/Plugins/PluginProviders/UncompiledPluginProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public PluginContainer GetPlugin(string path, ILogger logger)
}
catch
{
logger.LogError($"Reloading '{Path.GetFileName(path)}' failed, file is not accessible.");
logger.LogError("Reloading '{Path}' failed, file is not accessible.", Path.GetFileName(path));
return new PluginContainer(new PluginInfo(name), name);
}
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(fileStream));
Expand All @@ -69,7 +69,7 @@ public PluginContainer GetPlugin(string path, ILogger logger)
if (diagnostic.Severity != DiagnosticSeverity.Error || diagnostic.IsWarningAsError)
continue;

logger.LogError($"Compilation failed: {diagnostic.Location} {diagnostic.GetMessage()}");
logger.LogError("Compilation failed: {Location} {Message}", diagnostic.Location, diagnostic.GetMessage());
}
}

Expand Down
4 changes: 2 additions & 2 deletions Obsidian/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public async Task RunAsync()

await this.userCache.LoadAsync(this._cancelTokenSource.Token);

_logger.LogInformation($"Loading properties...");
_logger.LogInformation("Loading properties...");

await (Operators as OperatorList).InitializeAsync();

Expand All @@ -267,7 +267,7 @@ public async Task RunAsync()
await Task.WhenAll(Configuration.DownloadPlugins.Select(path => PluginManager.LoadPluginAsync(path)));

if (!Configuration.OnlineMode)
_logger.LogInformation($"Starting in offline mode...");
_logger.LogInformation("Starting in offline mode...");

CommandsRegistry.Register(this);

Expand Down
2 changes: 1 addition & 1 deletion Obsidian/WorldData/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public async Task<bool> LoadAsync(DimensionCodec codec)
if (levelCompound.TryGetTag("Version", out var tag))
LevelData.VersionData = tag as NbtCompound;

Logger.LogInformation($"Loading spawn chunks into memory...");
Logger.LogInformation("Loading spawn chunks into memory...");
for (int rx = -1; rx < 1; rx++)
for (int rz = -1; rz < 1; rz++)
LoadRegion(rx, rz);
Expand Down

0 comments on commit e3df216

Please sign in to comment.