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