Skip to content

Commit

Permalink
feat(logging): allow specifying max log level for NetDebug
Browse files Browse the repository at this point in the history
  • Loading branch information
ProbablePrime committed Apr 18, 2024
1 parent 911f263 commit c1a05a4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions LiteNetLib/NetDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TooBigPacketException(string message) : base(message)

public enum NetLogLevel
{
Warning,
Warning = 0,
Error,
Trace,
Info
Expand All @@ -41,8 +41,18 @@ public static class NetDebug
{
public static INetLogger Logger = null;
private static readonly object DebugLogLock = new object();

#if (DEBUG || DEBUG_MESSAGES)
public static NetLogLevel MaximumLoggingLevel = NetLogLevel.Trace;
#else
// Includes Warning as warning is < Error
public static NetLogLevel MaximumLoggingLevel = NetLogLevel.Error;
#endif
private static void WriteLogic(NetLogLevel logLevel, string str, params object[] args)
{
if (logLevel > MaximumLoggingLevel)
return;

lock (DebugLogLock)
{
if (Logger == null)
Expand All @@ -60,25 +70,21 @@ private static void WriteLogic(NetLogLevel logLevel, string str, params object[]
}
}

[Conditional("DEBUG_MESSAGES")]
internal static void Write(string str)
{
WriteLogic(NetLogLevel.Trace, str);
}

[Conditional("DEBUG_MESSAGES")]
internal static void Write(NetLogLevel level, string str)
{
WriteLogic(level, str);
}

[Conditional("DEBUG_MESSAGES"), Conditional("DEBUG")]
internal static void WriteForce(string str)
{
WriteLogic(NetLogLevel.Trace, str);
}

[Conditional("DEBUG_MESSAGES"), Conditional("DEBUG")]
internal static void WriteForce(NetLogLevel level, string str)
{
WriteLogic(level, str);
Expand Down

0 comments on commit c1a05a4

Please sign in to comment.