00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "BCLog.h"
00011
00012 std::ofstream BCLog::fOutputStream;
00013
00014 BCLog::LogLevel BCLog::fMinimumLogLevelFile = BCLog::debug;
00015
00016 BCLog::LogLevel BCLog::fMinimumLogLevelScreen = BCLog::summary;
00017
00018 const char * BCLog::fVersion = BAT_VERSION;
00019
00020 int BCLog::fHindex = 0;
00021
00022
00023
00024 BCLog::BCLog()
00025 {
00026
00027
00028
00029 gErrorIgnoreLevel=2000;
00030
00031 }
00032
00033
00034
00035 BCLog::~BCLog()
00036 {}
00037
00038
00039
00040 void BCLog::OpenLog(const char * filename, BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen)
00041 {
00042
00043
00044
00045 gErrorIgnoreLevel=2000;
00046
00047
00048
00049 BCLog::fOutputStream.open(filename);
00050
00051 if (!BCLog::fOutputStream.is_open())
00052 {
00053 std::cout << " Could not open log file " << filename << ". " << std::endl;
00054 return;
00055 }
00056
00057 BCLog::StartupInfo();
00058
00059 BCLog::Out(BCLog::summary,BCLog::summary,Form("Opening logfile %s",filename));
00060
00061
00062
00063 BCLog::SetMinimumLogLevelFile(loglevelfile);
00064 BCLog::SetMinimumLogLevelScreen(loglevelscreen);
00065
00066 }
00067
00068
00069
00070 void BCLog::OpenLog(const char * filename)
00071 {
00072
00073 BCLog::OpenLog(filename, BCLog::debug, BCLog::summary);
00074
00075 }
00076
00077
00078
00079 void BCLog::OpenLog()
00080 {
00081
00082 BCLog::OpenLog("log.txt", BCLog::debug, BCLog::summary);
00083
00084 }
00085
00086
00087
00088 void BCLog::CloseLog()
00089 {
00090
00091 BCLog::fOutputStream.close();
00092
00093 }
00094
00095
00096
00097 void BCLog::Out(BCLog::LogLevel loglevelfile, BCLog::LogLevel loglevelscreen, const char * message)
00098 {
00099
00100
00101
00102 if (!BCLog::fOutputStream.is_open())
00103 {
00104 std::cout << " Log file not opended. " << std::endl;
00105 return;
00106 }
00107
00108
00109
00110 if (loglevelfile >= BCLog::fMinimumLogLevelFile)
00111 BCLog::fOutputStream << BCLog::ToString(loglevelfile) << " : " << message << std::endl;
00112
00113
00114
00115 if (loglevelscreen >= BCLog::fMinimumLogLevelScreen)
00116 std::cout << BCLog::ToString(loglevelscreen) << " : " << message << std::endl;
00117
00118 }
00119
00120
00121
00122 void BCLog::Out(const char * message)
00123 {
00124
00125 BCLog::Out(BCLog::fMinimumLogLevelFile, BCLog::fMinimumLogLevelScreen, message);
00126
00127 }
00128
00129
00130
00131 void BCLog::StartupInfo()
00132 {
00133
00134
00135
00136 if (!BCLog::fOutputStream.is_open())
00137 {
00138 std::cout << " Log file not opended. " << std::endl;
00139 return;
00140 }
00141
00142 char * message = Form(
00143 " +------------------------------\n"
00144 " |\n"
00145 " | Running with BAT\n"
00146 " | Version %s\n"
00147 " |\n"
00148 " | http://www.mppmu.mpg.de/bat\n"
00149 " +------------------------------\n",
00150 BCLog::fVersion);
00151
00152 BCLog::fOutputStream << message;
00153 std::cout << message;
00154
00155 }
00156
00157
00158
00159 const char * BCLog::ToString(BCLog::LogLevel loglevel)
00160 {
00161
00162 switch (loglevel)
00163 {
00164 case debug:
00165 return "Debug ";
00166 case detail:
00167 return "Detail ";
00168 case summary:
00169 return "Summary";
00170 case warning:
00171 return "Warning";
00172 default:
00173 return "";
00174 }
00175
00176 }
00177
00178
00179