Deprecate string format log shorthand.

This commit is contained in:
Matthias Mailänder
2023-05-04 17:44:46 +02:00
committed by abcdefg30
parent e251126dd4
commit 1c2ce0dcc0
27 changed files with 100 additions and 84 deletions

View File

@@ -187,8 +187,10 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to decrypt string with exception: {0}", e);
Console.WriteLine("String decryption failed: {0}", e);
Log.Write("debug", "Failed to decrypt string with exception:");
Log.Write("debug", e);
Console.WriteLine("String decryption failed:");
Console.WriteLine(e);
return null;
}
}
@@ -211,8 +213,10 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to sign string with exception: {0}", e);
Console.WriteLine("String signing failed: {0}", e);
Log.Write("debug", "Failed to sign string with exception");
Log.Write("debug", e);
Console.WriteLine("String signing failed:");
Console.WriteLine(e);
return null;
}
}
@@ -235,8 +239,10 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to verify signature with exception: {0}", e);
Console.WriteLine("Signature validation failed: {0}", e);
Log.Write("debug", "Failed to verify signature with exception:");
Log.Write("debug", e);
Console.WriteLine("Signature validation failed:");
Console.WriteLine(e);
return false;
}
}

View File

@@ -81,8 +81,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to parse mod metadata file '{0}'", path);
Log.Write("debug", e.ToString());
Log.Write("debug", $"Failed to parse mod metadata file '{path}'");
Log.Write("debug", e);
}
}
}
@@ -174,7 +174,7 @@ namespace OpenRA
catch (Exception e)
{
Log.Write("debug", "Failed to register current mod metadata");
Log.Write("debug", e.ToString());
Log.Write("debug", e);
}
}
}
@@ -213,8 +213,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to parse mod metadata file '{0}'", path);
Log.Write("debug", e.ToString());
Log.Write("debug", $"Failed to parse mod metadata file '{path}'");
Log.Write("debug", e);
}
// Remove from the ingame mod switcher
@@ -225,12 +225,12 @@ namespace OpenRA
try
{
File.Delete(path);
Log.Write("debug", "Removed invalid mod metadata file '{0}'", path);
Log.Write("debug", $"Removed invalid mod metadata file '{path}'");
}
catch (Exception e)
{
Log.Write("debug", "Failed to remove mod metadata file '{0}'", path);
Log.Write("debug", e.ToString());
Log.Write("debug", $"Failed to remove mod metadata file '{path}'");
Log.Write("debug", e);
}
}
}
@@ -251,8 +251,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to remove mod metadata file '{0}'", path);
Log.Write("debug", e.ToString());
Log.Write("debug", $"Failed to remove mod metadata file '{path}'");
Log.Write("debug", e);
}
}
}

View File

@@ -263,13 +263,13 @@ namespace OpenRA.Graphics
if (!collections.TryGetValue(collectionName, out var collection))
{
Log.Write("debug", "Could not find collection '{0}'", collectionName);
Log.Write("debug", $"Could not find collection '{collectionName}'");
return new Size(0, 0);
}
if (collection.PanelRegion == null || collection.PanelRegion.Length != 8)
{
Log.Write("debug", "Collection '{0}' does not define a valid PanelRegion", collectionName);
Log.Write("debug", $"Collection '{collectionName}' does not define a valid PanelRegion");
return new Size(0, 0);
}

View File

@@ -66,8 +66,10 @@ namespace OpenRA
}
catch (Exception e)
{
Console.WriteLine("Failed to load keys: {0}", e);
Log.Write("debug", "Failed to load player keypair from `{0}` with exception: {1}", filePath, e);
Console.WriteLine("Failed to load keys:");
Console.WriteLine(e);
Log.Write("debug", $"Failed to load player keypair from `{filePath}` with exception:");
Log.Write("debug", e);
}
}
@@ -91,7 +93,7 @@ namespace OpenRA
innerData = FieldLoader.Load<PlayerProfile>(yaml.Value);
if (innerData.KeyRevoked)
{
Log.Write("debug", "Revoking key with fingerprint {0}", Fingerprint);
Log.Write("debug", $"Revoking key with fingerprint {Fingerprint}");
DeleteKeypair();
}
else
@@ -102,7 +104,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to parse player data result with exception: {0}", e);
Log.Write("debug", "Failed to parse player data result with exception:");
Log.Write("debug", e);
innerState = LinkState.ConnectionFailed;
}
finally
@@ -136,8 +139,10 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to generate keypair with exception: {1}", e);
Console.WriteLine("Key generation failed: {0}", e);
Log.Write("debug", "Failed to generate keypair with exception:");
Log.Write("debug", e);
Console.WriteLine("Key generation failed:");
Console.WriteLine(e);
innerState = LinkState.Uninitialized;
}
@@ -152,8 +157,10 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to delete keypair with exception: {1}", e);
Console.WriteLine("Key deletion failed: {0}", e);
Log.Write("debug", "Failed to delete keypair with exception:");
Log.Write("debug", e);
Console.WriteLine("Key deletion failed:");
Console.WriteLine(e);
}
innerState = LinkState.Uninitialized;

View File

@@ -441,7 +441,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e);
Log.Write("debug", $"Failed to load rules for {Title} with error");
Log.Write("debug", e);
InvalidCustomRules = true;
InvalidCustomRulesException = e;
Rules = Ruleset.LoadDefaultsForTileSet(modData, Tileset);
@@ -1204,7 +1205,7 @@ namespace OpenRA
// This shouldn't happen. But if it does, return the original value and hope the caller doesn't explode.
if (unProjected.Count == 0)
{
Log.Write("debug", "Failed to clamp map cell {0} to map bounds", uv);
Log.Write("debug", $"Failed to clamp map cell {uv} to map bounds");
return uv;
}
}
@@ -1276,7 +1277,7 @@ namespace OpenRA
// This shouldn't happen. But if it does, return the original value and hope the caller doesn't explode.
if (unProjected.Count == 0)
{
Log.Write("debug", "Failed to find closest edge for map cell {0}", uv);
Log.Write("debug", $"Failed to find closest edge for map cell {uv}");
return uv;
}
}

View File

@@ -158,10 +158,12 @@ namespace OpenRA
catch (Exception e)
{
mapPackage?.Dispose();
Console.WriteLine("Failed to load map: {0}", map);
Console.WriteLine("Details: {0}", e);
Log.Write("debug", "Failed to load map: {0}", map);
Log.Write("debug", "Details: {0}", e);
Console.WriteLine($"Failed to load map: {map}");
Console.WriteLine("Details:");
Console.WriteLine(e);
Log.Write("debug", $"Failed to load map: {map}");
Log.Write("debug", "Details:");
Log.Write("debug", e);
}
}
@@ -253,8 +255,9 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Remote map query failed with error: {0}", e);
Log.Write("debug", "URL was: {0}", url);
Log.Write("debug", "Remote map query failed with error:");
Log.Write("debug", e);
Log.Write("debug", $"URL was: {url}");
foreach (var uid in batchUids)
{
@@ -315,7 +318,8 @@ namespace OpenRA
}
catch (Exception e)
{
Log.Write("debug", "Failed to load minimap with exception: {0}", e);
Log.Write("debug", "Failed to load minimap with exception:");
Log.Write("debug", e);
}
});
}

View File

@@ -128,7 +128,8 @@ namespace OpenRA.Network
}
catch (Exception e)
{
Log.Write("geoip", "DatabaseReader failed: {0}", e);
Log.Write("geoip", "DatabaseReader failed:");
Log.Write("geoip", e);
}
}
@@ -142,7 +143,8 @@ namespace OpenRA.Network
}
catch (Exception e)
{
Log.Write("geoip", "LookupCountry failed: {0}", e);
Log.Write("geoip", "LookupCountry failed:");
Log.Write("geoip", e);
}
}

View File

@@ -49,8 +49,8 @@ namespace OpenRA.Network
// Only interact with one at a time. Some support both UPnP and NAT-PMP.
natDevice = args.Device;
Log.Write("nat", "Device found: {0}", natDevice.DeviceEndpoint);
Log.Write("nat", "Type: {0}", natDevice.NatProtocol);
Log.Write("nat", $"Device found: {natDevice.DeviceEndpoint}");
Log.Write("nat", $"Type: {natDevice.NatProtocol}");
}
finally
{

View File

@@ -209,7 +209,7 @@ namespace OpenRA
default:
{
Log.Write("debug", "Received unknown order with type {0}", type);
Log.Write("debug", $"Received unknown order with type {type}");
return null;
}
}
@@ -217,7 +217,7 @@ namespace OpenRA
catch (Exception e)
{
Log.Write("debug", "Caught exception while processing order");
Log.Write("debug", e.ToString());
Log.Write("debug", e);
// HACK: this can hopefully go away in the future
TextNotificationsManager.Debug("Ignoring malformed order that would have crashed the game");

View File

@@ -119,12 +119,12 @@ namespace OpenRA.Network
{
desyncFrameFound = true;
var mod = Game.ModData.Manifest.Metadata;
Log.Write("sync", "Player: {0} ({1} {2} {3})", Game.Settings.Player.Name, Platform.CurrentPlatform, Environment.OSVersion, Platform.RuntimeVersion);
Log.Write("sync", $"Player: {Game.Settings.Player.Name} ({Platform.CurrentPlatform} {Environment.OSVersion} {Platform.RuntimeVersion})");
if (Game.IsHost)
Log.Write("sync", "Player is host.");
Log.Write("sync", "Game ID: {0} (Mod: {1} at Version {2})", orderManager.LobbyInfo.GlobalSettings.GameUid, mod.Title, mod.Version);
Log.Write("sync", "Sync for net frame {0} -------------", r.Frame);
Log.Write("sync", "SharedRandom: {0} (#{1})", r.SyncedRandom, r.TotalCount);
Log.Write("sync", $"Game ID: {orderManager.LobbyInfo.GlobalSettings.GameUid} (Mod: {mod.Title} at Version {mod.Version})");
Log.Write("sync", $"Sync for net frame {r.Frame} -------------");
Log.Write("sync", $"SharedRandom: {r.SyncedRandom} (#{r.TotalCount})");
Log.Write("sync", "Synced Traits:");
foreach (var a in r.Traits)
{
@@ -139,7 +139,7 @@ namespace OpenRA.Network
Log.Write("sync", "Synced Effects:");
foreach (var e in r.Effects)
{
Log.Write("sync", "\t {0} ({1})", e.Name, e.Hash);
Log.Write("sync", $"\t {e.Name} ({e.Hash})");
var nvp = e.NamesValues;
for (var i = 0; i < nvp.Names.Length; i++)
@@ -149,7 +149,7 @@ namespace OpenRA.Network
Log.Write("sync", "Orders Issued:");
foreach (var o in r.Orders)
Log.Write("sync", "\t {0}", o.ToString());
Log.Write("sync", $"\t {o}");
}
}

View File

@@ -216,7 +216,7 @@ namespace OpenRA
{
var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Type == BotType);
if (logic == null)
Log.Write("debug", "Invalid bot type: {0}", BotType);
Log.Write("debug", $"Invalid bot type: {BotType}");
else
logic.Activate(this);
}

View File

@@ -219,10 +219,10 @@ namespace OpenRA.Scripting
public void FatalError(string message)
{
var stacktrace = new StackTrace().ToString();
Console.WriteLine("Fatal Lua Error: {0}", message);
Console.WriteLine($"Fatal Lua Error: {message}");
Console.WriteLine(stacktrace);
Log.Write("lua", "Fatal Lua Error: {0}", message);
Log.Write("lua", $"Fatal Lua Error: {message}");
Log.Write("lua", stacktrace);
FatalErrorOccurred = true;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Server
void OnLintFailure(string message)
{
Log.Write("server", "Map {0} failed lint with error: {1}", map.Title, message);
Log.Write("server", $"Map {map.Title} failed lint with error: {message}");
failed = true;
}
@@ -84,13 +84,13 @@ namespace OpenRA.Server
}
catch (Exception e)
{
Log.Write("server", "Failed to load rules for `{0}` with error :{1}", map.Title, e.Message);
Log.Write("server", $"Failed to load rules for `{map.Title}` with error: {e.Message}");
status = Session.MapStatus.Incompatible;
}
if (map.Players.Players.Count > MapPlayers.MaximumPlayerCount)
{
Log.Write("server", "Failed to load `{0}`: Player count exceeds maximum ({1}/{2}).", map.Title, map.Players.Players.Count, MapPlayers.MaximumPlayerCount);
Log.Write("server", $"Failed to load `{map.Title}`: Player count exceeds maximum ({map.Players.Players.Count}/{MapPlayers.MaximumPlayerCount}).");
status = Session.MapStatus.Incompatible;
}

View File

@@ -60,7 +60,7 @@ namespace OpenRA
{
if (!fileSystem.Exists(filename))
{
Log.Write("sound", "LoadSound, file does not exist: {0}", filename);
Log.Write("sound", $"LoadSound, file does not exist: {filename}");
return default;
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA
Log.Write("exception", $"Date: {DateTime.UtcNow:u}");
Log.Write("exception", $"Operating System: {Platform.CurrentPlatform} ({Platform.CurrentArchitecture}, {Environment.OSVersion})");
Log.Write("exception", $"Runtime Version: {Platform.RuntimeVersion}", Platform.RuntimeVersion);
Log.Write("exception", $"Runtime Version: {Platform.RuntimeVersion}");
Log.Write("exception", $"Installed Language: {CultureInfo.InstalledUICulture.TwoLetterISOLanguageName} (Installed) {CultureInfo.CurrentCulture.TwoLetterISOLanguageName} (Current) {CultureInfo.CurrentUICulture.TwoLetterISOLanguageName} (Current UI)");
var rpt = BuildExceptionReport(ex).ToString();

View File

@@ -60,7 +60,7 @@ namespace OpenRA
}
catch (Exception ex)
{
Log.Write("client", "Failed to parse Launch.URI or Launch.Connect: {0}", ex.Message);
Log.Write("client", $"Failed to parse Launch.URI or Launch.Connect: {ex.Message}");
return null;
}
}

View File

@@ -176,11 +176,6 @@ namespace OpenRA
ChannelWriter.TryWrite(new ChannelData(channelName, $"{e.Message}{Environment.NewLine}{e.StackTrace}"));
}
public static void Write(string channelName, string format, params object[] args)
{
ChannelWriter.TryWrite(new ChannelData(channelName, format.F(args)));
}
public static void Dispose()
{
CancellationToken.Cancel();

View File

@@ -67,10 +67,10 @@ namespace OpenRA.Support
Log.Write("perf", GetHeader(Indentation, name));
foreach (var child in children)
child.Write();
Log.Write("perf", FormatString, ElapsedMs, GetFooter(Indentation));
Log.Write("perf", string.Format(FormatString, ElapsedMs, GetFooter(Indentation)));
}
else if (ElapsedMs >= thresholdMs)
Log.Write("perf", FormatString, ElapsedMs, Indentation + name);
Log.Write("perf", string.Format(FormatString, ElapsedMs, Indentation + name));
}
float ElapsedMs => 1000f * ticks / Stopwatch.Frequency;
@@ -79,9 +79,9 @@ namespace OpenRA.Support
{
var type = item.GetType();
var label = type == typeof(string) || type.IsGenericType ? item.ToString() : type.Name;
Log.Write("perf", FormatString,
Log.Write("perf", string.Format(FormatString,
1000f * (endStopwatchTicks - startStopwatchTicks) / Stopwatch.Frequency,
"[" + Game.LocalTick + "] " + name + ": " + label);
"[" + Game.LocalTick + "] " + name + ": " + label));
}
public static long LongTickThresholdInStopwatchTicks => (long)(Stopwatch.Frequency * Game.Settings.Debug.LongTickThresholdMs / 1000f);

View File

@@ -60,7 +60,7 @@ namespace OpenRA
{
Log.AddChannel("traitreport", "traitreport.log");
foreach (var t in traits.OrderByDescending(t => t.Value.Queries).TakeWhile(t => t.Value.Queries > 0))
Log.Write("traitreport", "{0}: {1}", t.Key.Name, t.Value.Queries);
Log.Write("traitreport", $"{t.Key.Name}: {t.Value.Queries}");
}
public void AddTrait(Actor actor, object val)