Browse Source

added haxe.Log specification

Simon Krajewski 12 years ago
parent
commit
164aded664
2 changed files with 41 additions and 0 deletions
  1. 27 0
      std/haxe/Log.hx
  2. 14 0
      tests/unit/unitstd/haxe/Log.unit.hx

+ 27 - 0
std/haxe/Log.hx

@@ -21,8 +21,27 @@
  */
  */
 package haxe;
 package haxe;
 
 
+/**
+	Log primarily provides the trace() method, which is invoked upon a call to
+	trace() in haxe code.
+**/
 class Log {
 class Log {
 
 
+	/**
+		Outputs [v] in a platform-dependent way.
+		
+		The second parameter [infos] is injected by the compiler and contains
+		information about the position where the trace() call was made.
+		
+		This method can be rebound to a custom function:
+			var oldTrace = haxe.Log.trace; // store old function
+			haxe.Log.trace = function(v,infos) { // handle trace }
+			...
+			haxe.Log.trace = oldTrace;
+			
+		If it is bound to null, subsequent calls to trace() will cause an
+		exception.
+	**/
 	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
 	public static dynamic function trace( v : Dynamic, ?infos : PosInfos ) : Void {
 		#if flash
 		#if flash
 			#if (fdb || native_trace)
 			#if (fdb || native_trace)
@@ -48,6 +67,10 @@ class Log {
 		#end
 		#end
 	}
 	}
 
 
+	#if (flash || js)
+	/**
+		Clears the trace output.
+	**/
 	public static dynamic function clear() : Void {
 	public static dynamic function clear() : Void {
 		#if flash
 		#if flash
 		untyped flash.Boot.__clear_trace();
 		untyped flash.Boot.__clear_trace();
@@ -55,8 +78,12 @@ class Log {
 		untyped js.Boot.__clear_trace();
 		untyped js.Boot.__clear_trace();
 		#end
 		#end
 	}
 	}
+	#end
 
 
 	#if flash
 	#if flash
+	/**
+		Sets the color of the trace output to [rgb].
+	**/
 	public static dynamic function setColor( rgb : Int ) {
 	public static dynamic function setColor( rgb : Int ) {
 		untyped flash.Boot.__set_trace_color(rgb);
 		untyped flash.Boot.__set_trace_color(rgb);
 	}
 	}

+ 14 - 0
tests/unit/unitstd/haxe/Log.unit.hx

@@ -0,0 +1,14 @@
+var s = "";
+var p:haxe.PosInfos = null;
+var old = haxe.Log.trace;
+haxe.Log.trace = function(v, ?i) {
+	s = v;
+	p = i;
+}
+trace("test trace");
+s == "test trace";
+p.fileName == "Log.unit.hx";
+p.lineNumber == 8;
+haxe.Log.trace = null;
+exc(function() trace("exc test"));
+haxe.Log.trace = old;