From 12e263f8b279c61dfc61e0a3081dc89ad91e711a Mon Sep 17 00:00:00 2001
From: Ac_K <Acoustik666@gmail.com>
Date: Fri, 9 Feb 2018 20:39:50 +0100
Subject: [PATCH] Logging Improvements (#7)

* Logging Improvements

Add Trace functions to SVC.
Add function to get the function name who called.
---
 Ryujinx/Logging.cs              | 16 +++++++++++-----
 Ryujinx/OsHle/Svc/SvcHandler.cs |  2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Ryujinx/Logging.cs b/Ryujinx/Logging.cs
index f575549e..e96fd957 100644
--- a/Ryujinx/Logging.cs
+++ b/Ryujinx/Logging.cs
@@ -1,6 +1,7 @@
 using System;
 using System.Diagnostics;
 using System.IO;
+using System.Reflection;
 using System.Text;
 
 namespace Ryujinx
@@ -30,6 +31,11 @@ namespace Ryujinx
             return ExecutionTime.ElapsedMilliseconds.ToString().PadLeft(8, '0') + "ms";
         }
 
+        private static string WhoCalledMe()
+        {
+            return new StackTrace().GetFrame(2).GetMethod().Name;
+        }
+
         private static void LogFile(string Message)
         {
             if (EnableLogFile)
@@ -59,7 +65,7 @@ namespace Ryujinx
         {
             if (EnableTrace)
             {
-                string Text = $"{GetExecutionTime()} | TRACE > {Message}";
+                string Text = $"{GetExecutionTime()} | TRACE > {WhoCalledMe()} - {Message}";
 
                 Console.ForegroundColor = ConsoleColor.DarkGray;
                 Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
@@ -73,7 +79,7 @@ namespace Ryujinx
         {
             if (EnableDebug)
             {
-                string Text = $"{GetExecutionTime()} | DEBUG > {Message}";
+                string Text = $"{GetExecutionTime()} | DEBUG > {WhoCalledMe()} - {Message}";
 
                 Console.ForegroundColor = ConsoleColor.Gray;
                 Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
@@ -87,7 +93,7 @@ namespace Ryujinx
         {
             if (EnableWarn)
             {
-                string Text = $"{GetExecutionTime()} | WARN  > {Message}";
+                string Text = $"{GetExecutionTime()} | WARN  > {WhoCalledMe()} - {Message}";
 
                 Console.ForegroundColor = ConsoleColor.Yellow;
                 Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
@@ -101,7 +107,7 @@ namespace Ryujinx
         {
             if (EnableError)
             {
-                string Text = $"{GetExecutionTime()} | ERROR > {Message}";
+                string Text = $"{GetExecutionTime()} | ERROR > {WhoCalledMe()} - {Message}";
 
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
@@ -115,7 +121,7 @@ namespace Ryujinx
         {
             if (EnableFatal)
             {
-                string Text = $"{GetExecutionTime()} | FATAL > {Message}";
+                string Text = $"{GetExecutionTime()} | FATAL > {WhoCalledMe()} - {Message}";
 
                 Console.ForegroundColor = ConsoleColor.Magenta;
                 Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
diff --git a/Ryujinx/OsHle/Svc/SvcHandler.cs b/Ryujinx/OsHle/Svc/SvcHandler.cs
index 937c341e..9aea2ded 100644
--- a/Ryujinx/OsHle/Svc/SvcHandler.cs
+++ b/Ryujinx/OsHle/Svc/SvcHandler.cs
@@ -69,7 +69,9 @@ namespace Ryujinx.OsHle.Svc
 
             if (SvcFuncs.TryGetValue(e.Id, out SvcFunc Func))
             {
+                Logging.Trace($"{Func.Method.Name} called.");
                 Func(Ns, Registers, Memory);
+                Logging.Trace($"{Func.Method.Name} ended.");
             }
             else
             {