33 #define INCLXX_IN_GEANT4_MODE 1
37 #ifndef G4INCLLogger_hh
38 #define G4INCLLogger_hh 1
59 #if defined(INCL_DEBUG_LOG) && !defined(INCLXX_IN_GEANT4_MODE)
64 LoggerSlave(std::string
const &logFileName) : logStream(0), verbosityLevel(4) {
65 if(logFileName==
"-") {
66 logStream = &(std::cout);
70 logStream =
new std::ofstream(logFileName.c_str());
73 std::cerr <<
"Fatal error: couldn't open log file " << logFileName << std::endl;
74 std::exit(EXIT_FAILURE);
79 std::boolalpha(*logStream);
81 logMessage(
InfoMsg, __FILE__,__LINE__,
"# Logging enabled!\n");
96 G4int getVerbosityLevel() {
return verbosityLevel; }
99 void logMessage(
const MessageType type,
const std::string &fileName,
const G4int lineNumber, std::string
const &
s)
const;
102 void flush() { logStream->flush(); }
105 void logDataBlock(
const std::string &
block,
const std::string &fileName,
const G4int lineNumber)
const;
107 typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
108 typedef CoutType& (*StandardEndLine)(CoutType&);
123 std::ostream *logStream;
124 G4int verbosityLevel;
131 static void logMessage(
const MessageType type, std::string
const &fileName,
const G4int lineNumber, std::string
const &
s) {
132 theLoggerSlave->logMessage(type, fileName, lineNumber, s);
136 static void flush() { theLoggerSlave->flush(); }
139 static void dataBlock(
const std::string &
block,
const std::string &fileName,
const G4int lineNumber) {
140 theLoggerSlave->logDataBlock(block, fileName, lineNumber);
144 static void setLoggerSlave(LoggerSlave *
const logger) { theLoggerSlave = logger; }
150 static G4int getVerbosityLevel() {
return theLoggerSlave->getVerbosityLevel(); }
154 delete theLoggerSlave;
159 static LoggerSlave *theLoggerSlave;
165 std::stringstream ss;\
167 G4INCL::Logger::logMessage(G4INCL::FatalMsg, __FILE__,__LINE__, ss.str());\
168 G4INCL::Logger::flush();\
169 std::exit(EXIT_FAILURE);\
172 if(G4INCL::ErrorMsg <= G4INCL::Logger::getVerbosityLevel()) {\
173 std::stringstream ss;\
175 G4INCL::Logger::logMessage(G4INCL::ErrorMsg, __FILE__,__LINE__, ss.str());\
178 if(G4INCL::WarningMsg <= G4INCL::Logger::getVerbosityLevel()) {\
179 std::stringstream ss;\
181 G4INCL::Logger::logMessage(G4INCL::WarningMsg, __FILE__,__LINE__, ss.str());\
184 if(G4INCL::InfoMsg <= G4INCL::Logger::getVerbosityLevel()) {\
185 std::stringstream ss;\
187 G4INCL::Logger::logMessage(G4INCL::InfoMsg, __FILE__,__LINE__, ss.str());\
190 if(G4INCL::DebugMsg <= G4INCL::Logger::getVerbosityLevel()) {\
191 std::stringstream ss;\
193 G4INCL::Logger::logMessage(G4INCL::DebugMsg, __FILE__,__LINE__, ss.str());\
195 #define DATABLOCK(x) \
196 if(G4INCL::DataBlockMsg <= G4INCL::Logger::getVerbosityLevel()) {\
197 G4INCL::Logger::dataBlock(x,__FILE__,__LINE__);\
217 delete theLoggerSlave;
226 std::stringstream ss;\
228 std::stringstream location;\
229 location << __FILE__ << ":" << __LINE__;\
230 G4Exception(location.str().c_str(), "INCLXX0000", FatalException, ss.str().c_str());\
236 #define DATABLOCK(x);