Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 8073)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 8088)
@@ -108,4 +108,7 @@
 #include <TGTextView.h>
 
+#include <TEnv.h>       // gEnv (ErrorHandler)
+#include <TError.h>     // TError (SetErrorHandler)
+
 #include "MArgs.h"
 #include "MTime.h"
@@ -113,4 +116,5 @@
 
 #include "MLogHtml.h"
+#include "MLogManip.h"  // inf,warn,err (MLog::ErrorHandler)
 
 ClassImp(MLog);
@@ -153,5 +157,4 @@
 void MLog::Init()
 {
-
     //
     // Creat drawing semaphore
@@ -745,2 +748,155 @@
     return rc;
 }
+
+// --------------------------------------------------------------------------
+//
+// Check whether errors at this level should be ignored.
+//
+bool MLog::ErrorHandlerIgnore(Int_t level)
+{
+    // The default error handler function. It prints the message on stderr and
+    // if abort is set it aborts the application.
+   if (gErrorIgnoreLevel == kUnset) {
+      R__LOCKGUARD2(gErrorMutex);
+
+      gErrorIgnoreLevel = 0;
+      if (gEnv) {
+         TString level = gEnv->GetValue("Root.ErrorIgnoreLevel", "Info");
+         if (!level.CompareTo("Info",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kInfo;
+         else if (!level.CompareTo("Warning",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kWarning;
+         else if (!level.CompareTo("Error",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kError;
+         else if (!level.CompareTo("Break",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kBreak;
+         else if (!level.CompareTo("SysError",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kSysError;
+         else if (!level.CompareTo("Fatal",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kFatal;
+      }
+   }
+
+   return level < gErrorIgnoreLevel;
+}
+
+// --------------------------------------------------------------------------
+//
+// Output the root error message to the log-stream.
+//
+void MLog::ErrorHandlerPrint(Int_t level, const char *location, const char *msg)
+{
+    R__LOCKGUARD2(gErrorMutex);
+
+    if (level >= kError)
+        gLog << "ROOT:Error";
+    else
+        if (level >= kSysError)
+            gLog << "SysError";
+        else
+            if (level >= kBreak)
+                gLog << "\n *** Break ***";
+            else
+                if (level >= kFatal)
+                    gLog << "Fatal";
+                else
+                    if (level >= kWarning)
+                        gLog << "ROOT:Warning";
+                    else
+                        if (level >= kInfo)
+                            gLog << "ROOT:Info";
+
+    if (level >= kBreak && level < kSysError)
+        gLog << " " << msg << std::endl;
+    else
+        if (!location || strlen(location) == 0)
+            gLog << ": " << msg << std::endl;
+        else
+            gLog << " in <" << location << ">: " << msg << std::endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// A new error handler using gLog instead of stderr as output.
+// It is mainly a copy of root's DefaultErrorHandler
+// (see TError.h and TError.cxx)
+//
+void MLog::ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg)
+{
+    if (ErrorHandlerIgnore(level))
+        return;
+
+    gLog << std::flush;
+
+    if (level >= kInfo)
+       gLog << inf;
+    if (level >= kWarning)
+        gLog << warn;
+    if (level >= kError)
+        gLog << err;
+
+    ErrorHandlerPrint(level, location, msg);
+
+    gLog << std::flush;
+    if (!abort)
+        return;
+
+    gLog << err << "aborting" << std::endl;
+    if (gSystem) {
+        gSystem->StackTrace();
+        gSystem->Abort();
+    } else
+        ::abort();
+}
+
+// --------------------------------------------------------------------------
+//
+// A new error handler using gLog instead of stderr as output.
+// It is mainly a copy of root's DefaultErrorHandler
+// (see TError.h and TError.cxx)
+//
+void MLog::ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg)
+{
+    if (ErrorHandlerIgnore(level))
+        return;
+
+    gLog << std::flush << all;
+
+    ErrorHandlerPrint(level, location, msg);
+
+    gLog << std::flush;
+    if (!abort)
+        return;
+
+    gLog << err << "aborting" << std::endl;
+    if (gSystem) {
+        gSystem->StackTrace();
+        gSystem->Abort();
+    } else
+        ::abort();
+}
+
+// --------------------------------------------------------------------------
+//
+// Redirect the root ErrorHandler (see TError.h) output to gLog.
+//
+// The diffrent types are:
+//  kColor:      Use gLog colors
+//  kBlackWhite: Use all-qualifier (as in gLog << all << endl;)
+//  kDefault:    Set back to root's default error handler
+//               (redirect output to stderr)
+//
+void MLog::RedirectErrorHandler(ELogType typ)
+{
+    switch (typ)
+    {
+    case kColor:
+        SetErrorHandler(MLog::ErrorHandlerCol);
+        break;
+    case kBlackWhite:
+        SetErrorHandler(MLog::ErrorHandlerAll);
+        break;
+    case kDefault:
+        SetErrorHandler(DefaultErrorHandler);
+    }
+}
Index: trunk/MagicSoft/Mars/mbase/MLog.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.h	(revision 8073)
+++ trunk/MagicSoft/Mars/mbase/MLog.h	(revision 8088)
@@ -35,4 +35,10 @@
     enum ELogBits {
         kHasChanged = BIT(14)  // if gui has changed
+    };
+
+    enum ELogType {
+        kDefault,
+        kColor,
+        kBlackWhite
     };
 
@@ -95,5 +101,12 @@
     void AddGuiLine(const TString& line);
 
+    // User defined error handling (see TError.h)
+    static bool ErrorHandlerIgnore(Int_t level);
+    static void ErrorHandlerPrint(Int_t level, const char *location, const char *msg);
+    static void ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg);
+    static void ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg);
+
 public:
+
     MLog(int i=eStdout);
     MLog(ofstream &out);
@@ -110,4 +123,5 @@
 
     static TString Intro();
+    static void RedirectErrorHandler(ELogType typ=kColor);
 
     bool LockUpdate(const char *msg);
