33 #define INCLXX_IN_GEANT4_MODE 1
37 #ifndef G4INCLLogger_hh
38 #define G4INCLLogger_hh 1
46 #ifdef INCLXX_IN_GEANT4_MODE
63 #if defined(INCL_DEBUG_LOG) && !defined(INCLXX_IN_GEANT4_MODE)
68 LoggerSlave(std::string
const &logFileName) : logStream(0), verbosityLevel(4) {
69 if(logFileName==
"-") {
70 logStream = &(std::cout);
74 logStream =
new std::ofstream(logFileName.c_str());
77 std::cerr <<
"Fatal error: couldn't open log file " << logFileName << std::endl;
78 std::exit(EXIT_FAILURE);
83 std::boolalpha(*logStream);
85 logMessage(
InfoMsg, __FILE__,__LINE__,
"# Logging enabled!\n");
95 void setVerbosityLevel(
G4int lvl) { verbosityLevel = lvl; }
103 void logMessage(
const MessageType type,
const std::string &fileName,
const G4int lineNumber, std::string
const &
s)
const;
106 void flush() { logStream->flush(); }
109 void logDataBlock(
const std::string &
block,
const std::string &fileName,
const G4int lineNumber)
const;
111 typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
112 typedef CoutType& (*StandardEndLine)(CoutType&);
114 LoggerSlave
const &
operator<<(StandardEndLine
const &manip)
const {
121 LoggerSlave
const &
operator<<(
const T &t)
const {
127 std::ostream *logStream;
128 G4int verbosityLevel;
134 void logMessage(
const MessageType type, std::string
const &fileName,
const G4int lineNumber, std::string
const &
s);
140 void dataBlock(
const std::string &
block,
const std::string &fileName,
const G4int lineNumber);
143 void setLoggerSlave(LoggerSlave *
const logger);
146 void setVerbosityLevel(
G4int lvl);
152 void deleteLoggerSlave();
157 #define INCL_FATAL(x) \
159 std::stringstream ss_;\
161 G4INCL::Logger::logMessage(G4INCL::FatalMsg, __FILE__,__LINE__, ss_.str());\
162 G4INCL::Logger::flush();\
163 std::exit(EXIT_FAILURE);\
165 #define INCL_ERROR(x) \
166 if(G4INCL::ErrorMsg <= G4INCL::Logger::getVerbosityLevel()) {\
167 std::stringstream ss_;\
169 G4INCL::Logger::logMessage(G4INCL::ErrorMsg, __FILE__,__LINE__, ss_.str());\
171 #define INCL_WARN(x) \
172 if(G4INCL::WarningMsg <= G4INCL::Logger::getVerbosityLevel()) {\
173 std::stringstream ss_;\
175 G4INCL::Logger::logMessage(G4INCL::WarningMsg, __FILE__,__LINE__, ss_.str());\
177 #define INCL_INFO(x) \
178 if(G4INCL::InfoMsg <= G4INCL::Logger::getVerbosityLevel()) {\
179 std::stringstream ss_;\
181 G4INCL::Logger::logMessage(G4INCL::InfoMsg, __FILE__,__LINE__, ss_.str());\
183 #define INCL_DEBUG(x) \
184 if(G4INCL::DebugMsg <= G4INCL::Logger::getVerbosityLevel()) {\
185 std::stringstream ss_;\
187 G4INCL::Logger::logMessage(G4INCL::DebugMsg, __FILE__,__LINE__, ss_.str());\
189 #define INCL_DATABLOCK(x) \
190 if(G4INCL::DataBlockMsg <= G4INCL::Logger::getVerbosityLevel()) {\
191 G4INCL::Logger::dataBlock(x,__FILE__,__LINE__);\
194 #else // defined(INCL_DEBUG_LOG) && !defined(INCLXX_IN_GEANT4_MODE)
200 #define INCL_FATAL(x) \
202 std::stringstream ss_;\
204 std::stringstream location_;\
205 std::string fileName_(__FILE__);\
206 location_ << fileName_.substr(fileName_.find_last_of("/")+1) << ":" << __LINE__;\
207 G4Exception(location_.str().c_str(), "INCLXX0000", FatalException, ss_.str().c_str());\
209 #define INCL_ERROR(x) \
210 if(G4INCL::ErrorMsg <= G4INCL::Logger::getVerbosityLevel()) {\
211 std::string fileName_(__FILE__);\
212 std::stringstream ss_;\
213 ss_ << "INCL++ error [" << fileName_.substr(fileName_.find_last_of("/")+1) << ":" << __LINE__ << "] " << x;\
214 G4cout << ss_.str() << std::endl;\
216 #define INCL_WARN(x) \
217 if(G4INCL::WarningMsg <= G4INCL::Logger::getVerbosityLevel()) {\
218 std::string fileName_(__FILE__);\
219 std::stringstream ss_;\
220 ss_ << "INCL++ warning [" << fileName_.substr(fileName_.find_last_of("/")+1) << ":" << __LINE__ << "] " << x;\
221 G4cout << ss_.str() << std::endl;\
223 #define INCL_INFO(x);
224 #define INCL_DEBUG(x) \
225 if(G4INCL::DebugMsg <= G4INCL::Logger::getVerbosityLevel()) {\
226 std::string fileName_(__FILE__);\
227 std::stringstream ss_;\
228 ss_ << "INCL++ debug [" << fileName_.substr(fileName_.find_last_of("/")+1) << ":" << __LINE__ << "] " << x;\
229 G4cout << ss_.str() << std::endl;\
231 #define INCL_DATABLOCK(x);
233 #endif // defined(INCL_DEBUG_LOG) && !defined(INCLXX_IN_GEANT4_MODE)
std::ostream & operator<<(std::ostream &ostr, const G4String &astr)
void initVerbosityLevelFromEnvvar()
G4int getVerbosityLevel()