Skip to content

Commit

Permalink
log class name (#1188)
Browse files Browse the repository at this point in the history
* log class name

* fix logTests according to new logic
  • Loading branch information
xk0fe authored Apr 28, 2023
1 parent 7cac7a9 commit f414182
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
25 changes: 13 additions & 12 deletions Assets/Scripts/SS3D/Logging/Punpun.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Serilog;
using Serilog.Core;
using Serilog.Events;

namespace SS3D.Logging
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

}
Expand Down
20 changes: 10 additions & 10 deletions Assets/Scripts/Tests/Edit Mode/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 == $"[<color={color}>EditorTests.Log.LogTests</color>] {{\"one\":1,\"two\":2,\"three\":3}}");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] {{\"one\":1,\"two\":2,\"three\":3}}");
_lastUnityConsoleMessage = "";
}

Expand All @@ -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 == $"[<color={color}>EditorTests.Log.LogTests</color>] {{\"Name\":\"simple\",\"Count\":3,\"IsCool\":true,\"$type\":\"SimpleStructure\"}}");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] {{\"Name\":\"simple\",\"Count\":3,\"IsCool\":true,\"$type\":\"SimpleStructure\"}}");
_lastUnityConsoleMessage = "";
}

Expand All @@ -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 == $"[<color={color}>EditorTests.Log.LogTests</color>] [0.4,0.222,4.7E-05,78789]");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] [0.4,0.222,4.7E-05,78789]");
_lastUnityConsoleMessage = "";
}

Expand All @@ -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 == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.External);
Punpun.Information(this, "hello there !", Logs.External);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.ServerOnly);
Punpun.Information(this, "hello there !", Logs.ServerOnly);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.ClientOnly);
Punpun.Information(this, "hello there !", Logs.ClientOnly);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.None);
Punpun.Information(this, "hello there !", Logs.None);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.Important);
Punpun.Information(this, "hello there !", Logs.Important);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";

color = LogColors.GetLogColor(Logs.Physics);
Punpun.Information(this, "hello there !", Logs.Physics);
while (_lastUnityConsoleMessage == "") continue;
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>EditorTests.Log.LogTests</color>] hello there !");
Assert.IsTrue(_lastUnityConsoleMessage == $"[<color={color}>LogTests</color>] hello there !");
_lastUnityConsoleMessage = "";
}

Expand Down

0 comments on commit f414182

Please sign in to comment.