Changeset 8088 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 10/17/06 13:57:59 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MLog.cc
r7941 r8088 108 108 #include <TGTextView.h> 109 109 110 #include <TEnv.h> // gEnv (ErrorHandler) 111 #include <TError.h> // TError (SetErrorHandler) 112 110 113 #include "MArgs.h" 111 114 #include "MTime.h" … … 113 116 114 117 #include "MLogHtml.h" 118 #include "MLogManip.h" // inf,warn,err (MLog::ErrorHandler) 115 119 116 120 ClassImp(MLog); … … 153 157 void MLog::Init() 154 158 { 155 156 159 // 157 160 // Creat drawing semaphore … … 745 748 return rc; 746 749 } 750 751 // -------------------------------------------------------------------------- 752 // 753 // Check whether errors at this level should be ignored. 754 // 755 bool MLog::ErrorHandlerIgnore(Int_t level) 756 { 757 // The default error handler function. It prints the message on stderr and 758 // if abort is set it aborts the application. 759 if (gErrorIgnoreLevel == kUnset) { 760 R__LOCKGUARD2(gErrorMutex); 761 762 gErrorIgnoreLevel = 0; 763 if (gEnv) { 764 TString level = gEnv->GetValue("Root.ErrorIgnoreLevel", "Info"); 765 if (!level.CompareTo("Info",TString::kIgnoreCase)) 766 gErrorIgnoreLevel = kInfo; 767 else if (!level.CompareTo("Warning",TString::kIgnoreCase)) 768 gErrorIgnoreLevel = kWarning; 769 else if (!level.CompareTo("Error",TString::kIgnoreCase)) 770 gErrorIgnoreLevel = kError; 771 else if (!level.CompareTo("Break",TString::kIgnoreCase)) 772 gErrorIgnoreLevel = kBreak; 773 else if (!level.CompareTo("SysError",TString::kIgnoreCase)) 774 gErrorIgnoreLevel = kSysError; 775 else if (!level.CompareTo("Fatal",TString::kIgnoreCase)) 776 gErrorIgnoreLevel = kFatal; 777 } 778 } 779 780 return level < gErrorIgnoreLevel; 781 } 782 783 // -------------------------------------------------------------------------- 784 // 785 // Output the root error message to the log-stream. 786 // 787 void MLog::ErrorHandlerPrint(Int_t level, const char *location, const char *msg) 788 { 789 R__LOCKGUARD2(gErrorMutex); 790 791 if (level >= kError) 792 gLog << "ROOT:Error"; 793 else 794 if (level >= kSysError) 795 gLog << "SysError"; 796 else 797 if (level >= kBreak) 798 gLog << "\n *** Break ***"; 799 else 800 if (level >= kFatal) 801 gLog << "Fatal"; 802 else 803 if (level >= kWarning) 804 gLog << "ROOT:Warning"; 805 else 806 if (level >= kInfo) 807 gLog << "ROOT:Info"; 808 809 if (level >= kBreak && level < kSysError) 810 gLog << " " << msg << std::endl; 811 else 812 if (!location || strlen(location) == 0) 813 gLog << ": " << msg << std::endl; 814 else 815 gLog << " in <" << location << ">: " << msg << std::endl; 816 } 817 818 // -------------------------------------------------------------------------- 819 // 820 // A new error handler using gLog instead of stderr as output. 821 // It is mainly a copy of root's DefaultErrorHandler 822 // (see TError.h and TError.cxx) 823 // 824 void MLog::ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg) 825 { 826 if (ErrorHandlerIgnore(level)) 827 return; 828 829 gLog << std::flush; 830 831 if (level >= kInfo) 832 gLog << inf; 833 if (level >= kWarning) 834 gLog << warn; 835 if (level >= kError) 836 gLog << err; 837 838 ErrorHandlerPrint(level, location, msg); 839 840 gLog << std::flush; 841 if (!abort) 842 return; 843 844 gLog << err << "aborting" << std::endl; 845 if (gSystem) { 846 gSystem->StackTrace(); 847 gSystem->Abort(); 848 } else 849 ::abort(); 850 } 851 852 // -------------------------------------------------------------------------- 853 // 854 // A new error handler using gLog instead of stderr as output. 855 // It is mainly a copy of root's DefaultErrorHandler 856 // (see TError.h and TError.cxx) 857 // 858 void MLog::ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg) 859 { 860 if (ErrorHandlerIgnore(level)) 861 return; 862 863 gLog << std::flush << all; 864 865 ErrorHandlerPrint(level, location, msg); 866 867 gLog << std::flush; 868 if (!abort) 869 return; 870 871 gLog << err << "aborting" << std::endl; 872 if (gSystem) { 873 gSystem->StackTrace(); 874 gSystem->Abort(); 875 } else 876 ::abort(); 877 } 878 879 // -------------------------------------------------------------------------- 880 // 881 // Redirect the root ErrorHandler (see TError.h) output to gLog. 882 // 883 // The diffrent types are: 884 // kColor: Use gLog colors 885 // kBlackWhite: Use all-qualifier (as in gLog << all << endl;) 886 // kDefault: Set back to root's default error handler 887 // (redirect output to stderr) 888 // 889 void MLog::RedirectErrorHandler(ELogType typ) 890 { 891 switch (typ) 892 { 893 case kColor: 894 SetErrorHandler(MLog::ErrorHandlerCol); 895 break; 896 case kBlackWhite: 897 SetErrorHandler(MLog::ErrorHandlerAll); 898 break; 899 case kDefault: 900 SetErrorHandler(DefaultErrorHandler); 901 } 902 } -
trunk/MagicSoft/Mars/mbase/MLog.h
r7949 r8088 35 35 enum ELogBits { 36 36 kHasChanged = BIT(14) // if gui has changed 37 }; 38 39 enum ELogType { 40 kDefault, 41 kColor, 42 kBlackWhite 37 43 }; 38 44 … … 95 101 void AddGuiLine(const TString& line); 96 102 103 // User defined error handling (see TError.h) 104 static bool ErrorHandlerIgnore(Int_t level); 105 static void ErrorHandlerPrint(Int_t level, const char *location, const char *msg); 106 static void ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg); 107 static void ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg); 108 97 109 public: 110 98 111 MLog(int i=eStdout); 99 112 MLog(ofstream &out); … … 110 123 111 124 static TString Intro(); 125 static void RedirectErrorHandler(ELogType typ=kColor); 112 126 113 127 bool LockUpdate(const char *msg);
Note:
See TracChangeset
for help on using the changeset viewer.