Browse Source

Added class and function information to log messages based on where the log message was initiated.

frankwong 11 years ago
parent
commit
5abb778b16
1 changed files with 26 additions and 2 deletions
  1. 26 2
      laravel/log.php

+ 26 - 2
laravel/log.php

@@ -56,7 +56,31 @@ class Log {
 			Event::fire('laravel.log', array($type, $message));
 			Event::fire('laravel.log', array($type, $message));
 		}
 		}
 
 
-		$message = static::format($type, $message);
+		$trace=debug_backtrace();
+
+		foreach($trace as $item)
+		{
+			if ($item['class'] == __CLASS__)
+			{
+				continue;
+			}
+
+			$caller = $item;
+
+			break;
+		}
+
+		$function = $caller['function'];
+		if (isset($caller['class']))
+		{
+			$class = $caller['class'] . '::';
+		}
+		else
+		{
+			$class = '';
+		}
+
+		$message = static::format($type, $class . $function . ' - ' . $message);
 
 
 		File::append(path('storage').'logs/'.date('Y-m-d').'.log', $message);
 		File::append(path('storage').'logs/'.date('Y-m-d').'.log', $message);
 	}
 	}
@@ -96,4 +120,4 @@ class Log {
 		static::write($method, $parameters[0], $parameters[1]);
 		static::write($method, $parameters[0], $parameters[1]);
 	}
 	}
 
 
-}
+}