[mono/monkeywrench] fed2421e: Include caller in timed logs.

"Rolf Bjarne Kvinge ([email protected])" <[email protected]> Tue, 12 Nov 2013 11:14:12 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001424c04cd76-ad7610e4-ee91-4209-8675-f1a51d5473f0-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monkeywrench
  Compare: https://github.com/mono/monkeywrench/compare/ad8613b535f3...fed2421e3e2d

   Commit: fed2421e3e2dd8daa304e94253ba697b76cedf16
   Author: Rolf Bjarne Kvinge <[email protected]> (rolfbjarne)
     Date: 2013-11-12 11:12:08 GMT
      URL: https://github.com/mono/monkeywrench/commit/fed2421e3e2dd8daa304e94253ba697b76cedf16

Include caller in timed logs.

Changed paths:
  M MonkeyWrench.Database/DB.cs

Modified: MonkeyWrench.Database/DB.cs
===================================================================
@@ -34,6 +34,7 @@ public class DB : IDisposable, IDB
 
 		List<string> log;
 		Stopwatch watch;
+		string who;
 
 		public LargeObjectManager Manager
 		{
@@ -88,11 +89,14 @@ public DB (bool Connect)
 
 		void Initialize ()
 		{
-			if (Configuration.LogVerbosity > 2) {
-				log = new List<string> ();
-				watch = new Stopwatch ();
-				watch.Start ();
-			}
+			if (Configuration.LogVerbosity <= 2)
+				return;
+
+			log = new List<string> ();
+			watch = new Stopwatch ();
+			watch.Start ();
+			var fr = new StackFrame (2, false).GetMethod ();
+			who = fr == null ? "?" : fr.Name;
 		}
 
 		public void Log (string format, params object[] args)
@@ -120,7 +124,7 @@ private void Connect ()
 
 				dbcon = new NpgsqlConnection (connectionString);
 
-				Log ("Connecting to database, connection string: {0}", connectionString);
+				Log ("Connecting to database ({1}), connection string: {0}", connectionString, who);
 
 				dbcon.Open ();
 
@@ -149,7 +153,7 @@ public void Dispose ()
 			}
 			if (log != null) {
 				watch.Stop ();
-				Log ("Closed database connection. Total duration: {0} ms", watch.ElapsedMilliseconds);
+				Log ("Closed database connection ({1}). Total duration: {0} ms", watch.ElapsedMilliseconds, who);
 				log.Add (string.Empty);
 				Logger.LogRaw (string.Join ("\n", log.ToArray ()));
 			}


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches