Skip to content

Commit

Permalink
For log lines displayed on the debugger, print the calling method name
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Feb 8, 2025
1 parent 68bca9c commit 5fcde1a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/UniGetUI.Core.Logger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,64 @@ public static class Logger
private static readonly List<LogEntry> LogContents = [];

// String parameter log functions
public static void ImportantInfo(string s)
public static void ImportantInfo(string s, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(s);
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Success));
}

public static void Debug(string s)
public static void Debug(string s, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(s);
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Debug));
}

public static void Info(string s)
public static void Info(string s, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(s);
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Info));
}

public static void Warn(string s)
public static void Warn(string s, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(s);
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Warning));
}

public static void Error(string s)
public static void Error(string s, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(s);
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Error));
}

// Exception parameter log functions
public static void ImportantInfo(Exception e)
public static void ImportantInfo(Exception e, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(e.ToString());
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Success));
}

public static void Debug(Exception e)
public static void Debug(Exception e, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(e.ToString());
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Debug));
}

public static void Info(Exception e)
public static void Info(Exception e, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(e.ToString());
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Info));
}

public static void Warn(Exception e)
public static void Warn(Exception e, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(e.ToString());
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Warning));
}

public static void Error(Exception e)
public static void Error(Exception e, [System.Runtime.CompilerServices.CallerMemberName] string caller = "")
{
Diagnostics.Debug.WriteLine(e.ToString());
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Error));
}

Expand Down

0 comments on commit 5fcde1a

Please sign in to comment.