IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
BaseLog.h
Go to the documentation of this file.
1 // BaseLog.h:
3 // ----------
4 //
14 
15 #ifndef __IPSDKUTIL_BASELOG_H__
16 #define __IPSDKUTIL_BASELOG_H__
17 
18 #include <log4cplus/logger.h>
19 #include <log4cplus/loglevel.h>
20 #include <log4cplus/loggingmacros.h>
21 #include <string>
24 #include <IPSDKUtil/Logger/LogMessageFormater.h>
25 #include <IPSDKUtil/Logger/BaseException.h>
26 #include <IPSDKUtil/Logger/UnHandleException.h>
27 #include <boost/preprocessor/seq.hpp>
28 #include <boost/current_function.hpp>
29 
32 
33 namespace ipsdk {
34 
36 IPSDKUTIL_API const std::string& getBaseLoggerName();
37 
39 IPSDKUTIL_API log4cplus::Logger& getBaseLogger();
40 
41 } // end of namespace ipsdk
42 
44 //
50 
54 #define IPSDK_LOG(libraryName, msg, level) \
55  do { \
56  try { \
57  log4cplus::Logger usedLogger = (IPSDK_LIB_LOGGER(libraryName)); \
58  if(usedLogger.isEnabledFor(log4cplus::level) == true) { \
59  ipsdk::LogMessageFormater msgInternal(IPSDK_LIB_LOG_MSG_MANAGER(libraryName)); \
60  msgInternal msg; \
61  ipsdk::logMessage(usedLogger, log4cplus::level, msgInternal.string(), \
62  __FILE__, __LINE__); \
63  } \
64  } \
65  catch (const ipsdk::BaseException& e) { \
66  std::string errMsg("Exception thrown while processing message"); \
67  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
68  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, \
69  __FILE__, __LINE__, e); \
70  } \
71  catch (const std::exception& e) { \
72  std::string errMsg("Exception thrown while processing message"); \
73  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
74  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, \
75  __FILE__, __LINE__, e); \
76  } \
77  catch (...) { \
78  std::string errMsg("Exception thrown while processing message"); \
79  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
80  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, \
81  __FILE__, __LINE__, ipsdk::UnHandleException()); \
82  } \
83  } while (0);
84 
88 #define IPSDK_LOG_TRACE(libraryName, msg) \
89  IPSDK_LOG(libraryName, msg, TRACE_LOG_LEVEL);
90 
94 #define IPSDK_LOG_DEBUG(libraryName, msg) \
95  IPSDK_LOG(libraryName, msg, DEBUG_LOG_LEVEL);
96 
100 #define IPSDK_LOG_INFO(libraryName, msg) \
101  IPSDK_LOG(libraryName, msg, INFO_LOG_LEVEL);
102 
106 #define IPSDK_LOG_WARN(libraryName, msg) \
107  IPSDK_LOG(libraryName, msg, WARN_LOG_LEVEL);
108 
112 #define IPSDK_LOG_ERROR(libraryName, msg) \
113  IPSDK_LOG(libraryName, msg, ERROR_LOG_LEVEL);
114 
116 
118 //
122 //
124 
128 #define IPSDK_THROW(libraryName, msg) \
129  do { \
130  ipsdk::LogMessageFormater msgInternalThrow(IPSDK_LIB_LOG_MSG_MANAGER(libraryName)); \
131  try { \
132  msgInternalThrow msg; \
133  } \
134  catch (const ipsdk::BaseException& e) { \
135  std::string errMsg("Exception thrown while processing message"); \
136  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
137  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
138  } \
139  catch (const std::exception& e) { \
140  std::string errMsg("Exception thrown while processing message"); \
141  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
142  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
143  } \
144  catch (...) { \
145  std::string errMsg("Exception thrown while processing message"); \
146  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
147  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
148  ipsdk::UnHandleException()); \
149  } \
150  IPSDK_LOG_ERROR(libraryName, << msgInternalThrow.string()); \
151  throw IPSDK_LIB_EXCEPTION(libraryName)(msgInternalThrow.string(), \
152  BOOST_CURRENT_FUNCTION, __FILE__, __LINE__); \
153  } while(0);
154 
158 #define IPSDK_RETHROW(libraryName, msg, previousExcp) \
159  do { \
160  ipsdk::LogMessageFormater msgInternalReThrow(IPSDK_LIB_LOG_MSG_MANAGER(libraryName)); \
161  try { \
162  msgInternalReThrow msg; \
163  } \
164  catch (const ipsdk::BaseException& e) { \
165  std::string errMsg("Exception thrown while processing message"); \
166  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
167  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
168  } \
169  catch (const std::exception& e) { \
170  std::string errMsg("Exception thrown while processing message"); \
171  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
172  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
173  } \
174  catch (...) { \
175  std::string errMsg("Exception thrown while processing message"); \
176  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
177  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
178  ipsdk::UnHandleException()); \
179  } \
180  IPSDK_LOG_ERROR(libraryName, << msgInternalReThrow.string()); \
181  throw IPSDK_LIB_EXCEPTION(libraryName)(msgInternalReThrow.string(), \
182  BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
183  previousExcp); \
184  } while(0);
185 
189 #define IPSDK_CHECK(libraryName, bPredicate, msg) \
190  do { \
191  if (!(bPredicate)) { \
192  ipsdk::LogMessageFormater msgInternalCheck(IPSDK_LIB_LOG_MSG_MANAGER(libraryName)); \
193  try { \
194  msgInternalCheck msg; \
195  } \
196  catch (const ipsdk::BaseException& e) { \
197  std::string errMsg("Exception thrown while processing message"); \
198  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
199  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
200  } \
201  catch (const std::exception& e) { \
202  std::string errMsg("Exception thrown while processing message"); \
203  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
204  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, e); \
205  } \
206  catch (...) { \
207  std::string errMsg("Exception thrown while processing message"); \
208  LOG4CPLUS_ERROR(ipsdk::getBaseLogger(), errMsg); \
209  throw ipsdk::BaseException(errMsg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
210  ipsdk::UnHandleException()); \
211  } \
212  IPSDK_LOG_ERROR(libraryName, << msgInternalCheck.string()); \
213  throw IPSDK_LIB_EXCEPTION(libraryName)(msgInternalCheck.string(), \
214  BOOST_CURRENT_FUNCTION, __FILE__, __LINE__); \
215  } \
216  } while(0);
217 
219 
222 
223 #endif // __IPSDKUTIL_BASELOG_H__
IPSDKUTIL_API log4cplus::Logger & getBaseLogger()
Recovery of main logger associated to library.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
IPSDKUTIL_API const std::string & getBaseLoggerName()
Recovery of main logger name associated to library.
Utility functions for logging system management.
#define IPSDKUTIL_API
Import/Export macro for library IPSDKUtil.
Definition: IPSDKUtilExports.h:27
Definition of import/export macro for library.