Belle II Software  release-05-02-19
Logger.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll, Thomas Kuhr, Thomas Hauth *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/logging/LogConfig.h>
14 #include <framework/logging/LogMessage.h>
15 #include <framework/logging/LogSystem.h>
16 #include <framework/logging/LogVariableStream.h>
17 
18 
23 #define _B2_DO_NOTHING do { } while(false)
24 
29 #ifdef _PACKAGE_
30 #define PACKAGENAME() _PACKAGE_
31 #else
32 #define PACKAGENAME() nullptr
33 #endif
34 
39 #if defined(__GNUC__)
40 #define FUNCTIONNAME() __PRETTY_FUNCTION__
41 #elif defined(__ICC) || defined(__ECC) || defined(__APPLE__)
42 #define FUNCTIONNAME() __FUNCTION__
43 #else
44 #define FUNCTIONNAME() "???"
45 #endif
46 
48 #define _B2LOGMESSAGE(loglevel, debuglevel, logTextAndVariables, package, function, file, line) { \
49  LogVariableStream varStream; varStream << logTextAndVariables; \
50  Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage(loglevel, std::move(varStream), package, function, file, line, debuglevel)); \
51  }
52 
54 #define _B2LOGMESSAGE_IFENABLED(loglevel, debuglevel, logTextAndVariables, package, function, file, line) do { \
55  if (Belle2::LogSystem::Instance().isLevelEnabled(loglevel, debuglevel, package)) { \
56  _B2LOGMESSAGE(loglevel, debuglevel, logTextAndVariables, package, function, file, line); \
57  } } while(false)
58 
60 #define B2LOG(loglevel, debuglevel, streamText) \
61  _B2LOGMESSAGE_IFENABLED(loglevel, debuglevel, streamText, PACKAGENAME(), FUNCTIONNAME(), __FILE__, __LINE__)
62 
67 #ifdef LOG_NO_B2DEBUG
68 #define B2DEBUG(level, streamText) _B2_DO_NOTHING
69 #else
70 #define B2DEBUG(level, streamText) do { if (Belle2::LogSystem::debugEnabled()) B2LOG(Belle2::LogConfig::c_Debug, level, streamText); } while(false)
71 #endif
72 
77 #ifdef LOG_NO_B2INFO
78 #define B2INFO(streamText) _B2_DO_NOTHING
79 #else
80 #define B2INFO(streamText) B2LOG(Belle2::LogConfig::c_Info, 0, streamText)
81 #endif
82 
87 #ifdef LOG_NO_B2RESULT
88 #define B2RESULT(streamText) _B2_DO_NOTHING
89 #else
90 #define B2RESULT(streamText) B2LOG(Belle2::LogConfig::c_Result, 0, streamText)
91 #endif
92 
97 #ifdef LOG_NO_B2WARNING
98 #define B2WARNING(streamText) _B2_DO_NOTHING
99 #else
100 #define B2WARNING(streamText) B2LOG(Belle2::LogConfig::c_Warning, 0, streamText)
101 #endif
102 
107 #define B2ERROR(streamText) do { \
108  _B2LOGMESSAGE(Belle2::LogConfig::c_Error, 0, streamText, PACKAGENAME(), FUNCTIONNAME(), __FILE__, __LINE__) \
109  } while(false)
110 
111 
116 #define B2FATAL(streamText) do { \
117  _B2LOGMESSAGE(Belle2::LogConfig::c_Fatal, 0, streamText, PACKAGENAME(), FUNCTIONNAME(), __FILE__, __LINE__); \
118  exit(1); \
119  } while(false)
120 
121 #ifdef LOG_NO_B2ASSERT
122 #define B2ASSERT(message, condition) _B2_DO_NOTHING
123 #else
124 
128 #define B2ASSERT(message, condition) do { \
129  if (!(condition)) { \
130  B2FATAL(message); \
131  } \
132  } while(false)
133 #endif