[svn] r6106: nemerle/trunk/macros/Logging.n

malekith svnadmin at nemerle.org
Fri Feb 3 15:57:51 CET 2006


Log:
Add LogFormat(PrependFlag).

Author: malekith
Date: Fri Feb  3 15:57:51 2006
New Revision: 6106

Modified:
   nemerle/trunk/macros/Logging.n

Modified: nemerle/trunk/macros/Logging.n
==============================================================================
--- nemerle/trunk/macros/Logging.n	(original)
+++ nemerle/trunk/macros/Logging.n	Fri Feb  3 15:57:51 2006
@@ -42,6 +42,7 @@
     // empty string holds default print function (also set when no VERB=>expr mapping is specified)
     public FlagsToFunctions : Hashtable [string, PExpr] = Hashtable ();
     public mutable SetPrintExpression = false;
+    public mutable PrependFlag = false;
     public mutable AdditionalLoggingCondition : PExpr = null;
     
     public GetName (expr : PExpr) : string
@@ -151,6 +152,18 @@
     AdditionalLoggingCondition = expr;
   }
 
+  [Nemerle.MacroUsage (Nemerle.MacroPhase.BeforeInheritance,
+                       Nemerle.MacroTargets.Assembly)]
+  macro LogFormat (params flags : list [PExpr])
+  {
+    foreach (flag in flags) {
+      | <[ PrependFlag ]> =>
+        PrependFlag = true
+      | f =>
+        Message.Error ($ "invalid LogFormat: $f")
+    }
+  }
+
   macro log (flag, params exprs : list [PExpr])
   {
     def name = GetName (flag);
@@ -159,6 +172,14 @@
         | Some (e) => e
         | _ => FlagsToFunctions [""]
       }
+    def exprs =
+      if (PrependFlag)
+        match (exprs) {
+          | x :: xs =>
+            <[ $(name + ": " : string) + $x ]> :: xs
+          | [] => []
+        }
+      else exprs;
       
     if (Flags.Contains (name))
       if (Flags [name])



More information about the svn mailing list