From f4141826cbfe5c32b2903d024a52b0df39e8fdc7 Mon Sep 17 00:00:00 2001 From: xk0fe Date: Sat, 29 Apr 2023 02:01:50 +0300 Subject: [PATCH] log class name (#1188) * log class name * fix logTests according to new logic --- Assets/Scripts/SS3D/Logging/Punpun.cs | 25 +++++++++++----------- Assets/Scripts/Tests/Edit Mode/LogTests.cs | 20 ++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/SS3D/Logging/Punpun.cs b/Assets/Scripts/SS3D/Logging/Punpun.cs index a968121fe6..3167bf641f 100644 --- a/Assets/Scripts/SS3D/Logging/Punpun.cs +++ b/Assets/Scripts/SS3D/Logging/Punpun.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Serilog; +using Serilog.Core; using Serilog.Events; namespace SS3D.Logging @@ -24,7 +25,7 @@ public static class Punpun public static void Verbose(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[]{infoLog}.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Verbose("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Verbose("{InfoLog}" + messageTemplate, properties); } /// @@ -40,7 +41,7 @@ public static void Verbose(object sender, string messageTemplate, Logs infoLog = public static void Verbose(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Verbose(exception,"{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Verbose(exception,"{InfoLog}" + messageTemplate, properties); } /// @@ -55,7 +56,7 @@ public static void Verbose(object sender, Exception exception, string messageTem public static void Debug(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Debug("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Debug("{InfoLog}" + messageTemplate, properties); } /// @@ -70,7 +71,7 @@ public static void Debug(object sender, string messageTemplate, Logs infoLog = L public static void Debug(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Debug(exception, "{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Debug(exception, "{InfoLog}" + messageTemplate, properties); } /// @@ -85,7 +86,7 @@ public static void Debug(object sender, Exception exception, string messageTempl public static void Information(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Information("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Information("{InfoLog}" + messageTemplate, properties); } /// @@ -100,7 +101,7 @@ public static void Information(object sender, string messageTemplate, Logs infoL public static void Information(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Debug(exception, "{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Debug(exception, "{InfoLog}" + messageTemplate, properties); } /// @@ -115,7 +116,7 @@ public static void Information(object sender, Exception exception, string messag public static void Warning(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Warning("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Warning("{InfoLog}" + messageTemplate, properties); } /// @@ -130,7 +131,7 @@ public static void Warning(object sender, string messageTemplate, Logs infoLog = public static void Warning(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Debug(exception, "{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Debug(exception, "{InfoLog}" + messageTemplate, properties); } /// @@ -145,7 +146,7 @@ public static void Warning(object sender, Exception exception, string messageTem public static void Error(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Error("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Error("{InfoLog}" + messageTemplate, properties); } /// @@ -160,7 +161,7 @@ public static void Error(object sender, string messageTemplate, Logs infoLog = L public static void Error(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Error(exception, "{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Error(exception, "{InfoLog}" + messageTemplate, properties); } /// @@ -175,7 +176,7 @@ public static void Error(object sender, Exception exception, string messageTempl public static void Fatal(object sender, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Fatal("{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Fatal("{InfoLog}" + messageTemplate, properties); } /// @@ -190,7 +191,7 @@ public static void Fatal(object sender, string messageTemplate, Logs infoLog = L public static void Fatal(object sender, Exception exception, string messageTemplate, Logs infoLog = Logs.Generic, params object[] propertyValues) { var properties = new object[] { infoLog }.Concat(propertyValues).ToArray(); - Log.ForContext(sender.GetType()).Fatal(exception, "{InfoLog}" + messageTemplate, properties); + Log.ForContext(Constants.SourceContextPropertyName, sender.GetType().Name).Fatal(exception, "{InfoLog}" + messageTemplate, properties); } } diff --git a/Assets/Scripts/Tests/Edit Mode/LogTests.cs b/Assets/Scripts/Tests/Edit Mode/LogTests.cs index e3285f00c5..6e6bbd1de6 100644 --- a/Assets/Scripts/Tests/Edit Mode/LogTests.cs +++ b/Assets/Scripts/Tests/Edit Mode/LogTests.cs @@ -67,7 +67,7 @@ public void SimpleDictionnaryDisplayAsExpectedInUnity() string color = LogColors.GetLogColor(Logs.Generic); Punpun.Information(this, "{simpleDictionary}", Logs.Generic, _simpleDictionaryToDisplay); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] {{\"one\":1,\"two\":2,\"three\":3}}"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] {{\"one\":1,\"two\":2,\"three\":3}}"); _lastUnityConsoleMessage = ""; } @@ -85,7 +85,7 @@ public void SimpleStructureDisplayAsExpectedInUnity() string color = LogColors.GetLogColor(Logs.Generic); Punpun.Information(this, "{@simpleStructure}", Logs.Generic, _simpleStructureToDisplay); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] {{\"Name\":\"simple\",\"Count\":3,\"IsCool\":true,\"$type\":\"SimpleStructure\"}}"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] {{\"Name\":\"simple\",\"Count\":3,\"IsCool\":true,\"$type\":\"SimpleStructure\"}}"); _lastUnityConsoleMessage = ""; } @@ -100,7 +100,7 @@ public void ListOfFloatDisplayAsExpectedInUnity() string color = LogColors.GetLogColor(Logs.Generic); Punpun.Information(this, "{list}", Logs.Generic, _floatListToDisplay); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] [0.4,0.222,4.7E-05,78789]"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] [0.4,0.222,4.7E-05,78789]"); _lastUnityConsoleMessage = ""; } @@ -115,43 +115,43 @@ public void MessagWithNoAddedPropertyDisplayAsExpectedInUnity() string color = LogColors.GetLogColor(Logs.Generic); Punpun.Information(this, "hello there !", Logs.Generic); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.External); Punpun.Information(this, "hello there !", Logs.External); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.ServerOnly); Punpun.Information(this, "hello there !", Logs.ServerOnly); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.ClientOnly); Punpun.Information(this, "hello there !", Logs.ClientOnly); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.None); Punpun.Information(this, "hello there !", Logs.None); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.Important); Punpun.Information(this, "hello there !", Logs.Important); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; color = LogColors.GetLogColor(Logs.Physics); Punpun.Information(this, "hello there !", Logs.Physics); while (_lastUnityConsoleMessage == "") continue; - Assert.IsTrue(_lastUnityConsoleMessage == $"[EditorTests.Log.LogTests] hello there !"); + Assert.IsTrue(_lastUnityConsoleMessage == $"[LogTests] hello there !"); _lastUnityConsoleMessage = ""; }