20 #ifndef GEOS_COMMON_LOGGER_HPP
21 #define GEOS_COMMON_LOGGER_HPP
26 #include "common/format/Format.hpp"
27 #include "LvArray/src/Macros.hpp"
33 #if defined(GEOS_USE_MPI)
41 #define GEOS_LOG( ... ) LVARRAY_LOG( __VA_ARGS__ )
47 #define GEOS_LOG_VAR( ... ) LVARRAY_LOG_VAR( __VA_ARGS__ )
55 #if defined(GEOS_DEVICE_COMPILE)
56 #define GEOS_LOG_IF( EXP, msg )
58 #define GEOS_LOG_IF( EXP, msg ) \
62 std::cout<< msg << std::endl; \
73 #define GEOS_LOG_RANK_0_IF( EXP, msg ) \
75 if( ::geos::logger::internal::g_rank == 0 && EXP ) \
77 std::ostringstream oss; \
79 std::cout << oss.str() << std::endl; \
88 #define GEOS_LOG_RANK_0_IF_NLR( EXP, msg ) \
90 if( ::geos::logger::internal::g_rank == 0 && EXP ) \
92 std::ostringstream oss; \
94 std::cout << oss.str(); \
102 #define GEOS_LOG_RANK_0( msg ) GEOS_LOG_RANK_0_IF( true, msg )
109 #if defined(GEOS_DEVICE_COMPILE)
110 #define GEOS_LOG_RANK_IF( EXP, msg )
112 #define GEOS_LOG_RANK_IF( EXP, msg ) \
116 std::ostringstream oss; \
117 oss << "Rank " << ::geos::logger::internal::g_rankString << ": " << msg; \
118 *logger::internal::g_rankStream << oss.str() << std::endl; \
127 #define GEOS_LOG_RANK( msg ) GEOS_LOG_RANK_IF( true, msg )
133 #define GEOS_LOG_RANK_VAR( var ) GEOS_LOG_RANK( #var " = " << var )
140 #if !defined(GEOS_DEVICE_COMPILE) && !defined(GEOS_ERROR_LOGGER_INSTANCE)
141 #define GEOS_ERROR_LOGGER_INSTANCE ErrorLogger::global()
153 #if !defined(GEOS_DEVICE_COMPILE)
154 #define GEOS_ERROR_IF_CAUSE( COND, CAUSE_MESSAGE, ... ) \
159 std::ostringstream __msgoss; \
160 __msgoss << GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ ); \
161 std::string __message = __msgoss.str(); \
162 __msgoss = std::ostringstream(); \
163 __msgoss << CAUSE_MESSAGE; \
164 std::string __cause = __msgoss.str(); \
165 std::ostringstream __oss; \
166 __oss << "***** ERROR\n"; \
167 __oss << "***** LOCATION: " LOCATION "\n"; \
168 __oss << "***** " << __cause << "\n"; \
169 __oss << "***** Rank " << ::geos::logger::internal::g_rankString << ": " << __message << "\n"; \
170 std::string stackHistory = LvArray::system::stackTrace( true ); \
171 __oss << stackHistory; \
172 std::cout << __oss.str() << std::endl; \
173 if( GEOS_ERROR_LOGGER_INSTANCE.isOutputFileEnabled() ) \
175 ErrorLogger::ErrorMsg msgStruct( ErrorLogger::MsgType::Error, \
177 ::geos::logger::internal::g_rank, \
180 msgStruct.setCause( __cause ); \
181 msgStruct.addCallStackInfo( stackHistory ); \
182 msgStruct.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ ) ); \
183 GEOS_ERROR_LOGGER_INSTANCE.flushErrorMsg( msgStruct ); \
185 LvArray::system::callErrorHandler(); \
189 #define GEOS_ERROR_IF_CAUSE( COND, CAUSE_MESSAGE, ... ) \
194 constexpr char const * formatString = "***** ERROR\n" \
195 "***** LOCATION" LOCATION "\n" \
196 "***** BLOCK: [%u, %u, %u]\n" \
197 "***** THREAD: [%u, %u, %u]\n" \
198 "***** " STRINGIZE( CAUSE_MESSAGE ) "\n" \
199 "***** " STRINGIZE( GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ ) ) "\n\n"; \
200 printf( formatString, blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z ); \
213 #define GEOS_ERROR_IF( COND, ... ) \
214 GEOS_ERROR_IF_CAUSE( COND, "Error cause: " STRINGIZE( COND ), __VA_ARGS__ )
222 #define GEOS_ERROR( ... ) GEOS_ERROR_IF_CAUSE( true, "", __VA_ARGS__ )
233 #if !defined(GEOS_DEVICE_COMPILE)
234 #define GEOS_THROW_IF_CAUSE( COND, CAUSE_MESSAGE, MSG, ... ) \
239 std::ostringstream __msgoss; \
241 std::string __message = __msgoss.str(); \
242 __msgoss = std::ostringstream(); \
243 __msgoss << CAUSE_MESSAGE; \
244 std::string __cause = __msgoss.str(); \
245 std::ostringstream __oss; \
246 __oss << "***** EXCEPTION\n"; \
247 __oss << "***** LOCATION: " LOCATION "\n"; \
248 __oss << "***** " << __cause << "\n"; \
249 __oss << "***** Rank " << ::geos::logger::internal::g_rankString << ": " << __message << "\n"; \
250 std::string stackHistory = LvArray::system::stackTrace( true ); \
251 __oss << stackHistory; \
252 if( GEOS_ERROR_LOGGER_INSTANCE.isOutputFileEnabled() ) \
254 if( GEOS_ERROR_LOGGER_INSTANCE.currentErrorMsg().m_type == ErrorLogger::MsgType::Undefined ) \
256 GEOS_ERROR_LOGGER_INSTANCE.currentErrorMsg() \
257 .setType( ErrorLogger::MsgType::Exception ) \
258 .setCodeLocation( __FILE__, __LINE__ ) \
259 .setCause( __cause ) \
260 .addRank( ::geos::logger::internal::g_rank ) \
261 .addCallStackInfo( stackHistory ); \
263 GEOS_ERROR_LOGGER_INSTANCE.currentErrorMsg() \
264 .addToMsg( __message ) \
265 .addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ ) ); \
267 throw GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ )( __oss.str() ); \
271 #define GEOS_THROW_IF_CAUSE( COND, CAUSE_MESSAGE, MSG, ... ) \
276 static char const formatString[] = "***** ERROR\n" \
277 "***** LOCATION" LOCATION "\n" \
278 "***** BLOCK: [%u, %u, %u]\n" \
279 "***** THREAD: [%u, %u, %u]\n" \
280 "***** " STRINGIZE( CAUSE_MESSAGE ) "\n" \
281 "***** " STRINGIZE( GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ ) ) "\n\n"; \
282 printf( formatString, blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z ); \
296 #define GEOS_THROW_IF( COND, MSG, ... ) \
297 GEOS_THROW_IF_CAUSE( COND, "Error cause: " STRINGIZE( COND ), MSG, __VA_ARGS__ )
306 #define GEOS_THROW( MSG, ... ) GEOS_THROW_IF_CAUSE( true, "", MSG, __VA_ARGS__ )
316 #if !defined(GEOS_DEVICE_COMPILE)
317 #define GEOS_WARNING_IF_CAUSE( COND, CAUSE_MESSAGE, ... ) \
322 std::ostringstream __msgoss; \
323 __msgoss << GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ ); \
324 std::string __message = __msgoss.str(); \
325 __msgoss = std::ostringstream(); \
326 __msgoss << CAUSE_MESSAGE; \
327 std::string __cause = __msgoss.str(); \
328 std::ostringstream __oss; \
329 __oss << "***** WARNING\n"; \
330 __oss << "***** LOCATION: " LOCATION "\n"; \
331 __oss << "***** " << __cause << "\n"; \
332 __oss << "***** Rank " << ::geos::logger::internal::g_rankString << ": " << __message << "\n"; \
333 std::cout << __oss.str() << std::endl; \
334 if( GEOS_ERROR_LOGGER_INSTANCE.isOutputFileEnabled() ) \
336 ErrorLogger::ErrorMsg msgStruct( ErrorLogger::MsgType::Warning, \
338 ::geos::logger::internal::g_rank, \
341 msgStruct.setCause( __cause ); \
342 msgStruct.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ ) ); \
343 GEOS_ERROR_LOGGER_INSTANCE.flushErrorMsg( msgStruct ); \
348 #define GEOS_WARNING_IF_CAUSE( COND, CAUSE_MESSAGE, ... ) \
353 static char const formatString[] = "***** WARNING\n" \
354 "***** LOCATION" LOCATION "\n" \
355 "***** BLOCK: [%u, %u, %u]\n" \
356 "***** THREAD: [%u, %u, %u]\n" \
357 "***** " STRINGIZE( CAUSE_MESSAGE ) "\n" \
358 "***** " STRINGIZE( GEOS_DETAIL_FIRST_ARG( __VA_ARGS__ ) ) "\n\n"; \
359 printf( formatString, blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z ); \
372 #define GEOS_WARNING_IF( COND, ... ) \
373 GEOS_WARNING_IF_CAUSE( COND, "Warning cause: " STRINGIZE( COND ), __VA_ARGS__ )
381 #define GEOS_WARNING( ... ) GEOS_WARNING_IF_CAUSE( true, "", __VA_ARGS__ )
388 #define GEOS_INFO_IF( EXP, msg ) LVARRAY_INFO_IF( EXP, msg )
394 #define GEOS_INFO( msg ) LVARRAY_INFO( msg )
401 #define GEOS_ERROR_LHS_RHS_DECLS( lhs, rhs ) \
402 GEOS_MAYBE_UNUSED auto const lhsResult = (lhs); \
403 GEOS_MAYBE_UNUSED auto const rhsResult = (rhs)
415 #define GEOS_ERROR_IF_OP_MSG( lhs, OP, NOP, rhs, ... ) \
417 GEOS_ERROR_LHS_RHS_DECLS( lhs, rhs ); \
418 GEOS_ERROR_IF_CAUSE( lhsResult OP rhsResult, \
419 "Expected: " #lhs " " #NOP " " #rhs "\n* " #lhs " = " << lhsResult << "\n* " #rhs " = " << rhsResult << "\n", \
432 #define GEOS_ERROR_IF_EQ_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, ==, !=, rhs, __VA_ARGS__ )
439 #define GEOS_ERROR_IF_EQ( lhs, rhs ) GEOS_ERROR_IF_EQ_MSG( lhs, rhs, "" )
449 #define GEOS_ERROR_IF_NE_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, !=, ==, rhs, __VA_ARGS__ )
456 #define GEOS_ERROR_IF_NE( lhs, rhs ) GEOS_ERROR_IF_NE_MSG( lhs, rhs, "" )
466 #define GEOS_ERROR_IF_GT_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, >, <=, rhs, __VA_ARGS__ )
473 #define GEOS_ERROR_IF_GT( lhs, rhs ) GEOS_ERROR_IF_GT_MSG( lhs, rhs, "" )
483 #define GEOS_ERROR_IF_GE_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, >=, <, rhs, __VA_ARGS__ )
490 #define GEOS_ERROR_IF_GE( lhs, rhs ) GEOS_ERROR_IF_GE_MSG( lhs, rhs, "" )
500 #define GEOS_ERROR_IF_LT_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, <, >=, rhs, __VA_ARGS__ )
507 #define GEOS_ERROR_IF_LT( lhs, rhs ) GEOS_ERROR_IF_LT_MSG( lhs, rhs, "" )
517 #define GEOS_ERROR_IF_LE_MSG( lhs, rhs, ... ) GEOS_ERROR_IF_OP_MSG( lhs, <=, >, rhs, __VA_ARGS__ )
525 #define GEOS_ERROR_IF_LE( lhs, rhs ) GEOS_ERROR_IF_LE_MSG( lhs, rhs, "" )
537 #define GEOS_WARNING_IF_OP_MSG( lhs, OP, NOP, rhs, ... ) \
539 GEOS_ERROR_LHS_RHS_DECLS( lhs, rhs ); \
540 GEOS_WARNING_IF_CAUSE( lhsResult OP rhsResult, \
541 "Expected: " #lhs " " #NOP " " #rhs "\n* " #lhs " = " << lhsResult << "\n* " #rhs " = " << rhsResult << "\n", \
554 #define GEOS_WARNING_IF_EQ_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, ==, !=, rhs, __VA_ARGS__ )
561 #define GEOS_WARNING_IF_EQ( lhs, rhs ) GEOS_WARNING_IF_EQ_MSG( lhs, rhs, "" )
571 #define GEOS_WARNING_IF_NE_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, !=, ==, rhs, __VA_ARGS__ )
578 #define GEOS_WARNING_IF_NE( lhs, rhs ) GEOS_WARNING_IF_NE_MSG( lhs, rhs, "" )
588 #define GEOS_WARNING_IF_GT_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, >, <=, rhs, __VA_ARGS__ )
595 #define GEOS_WARNING_IF_GT( lhs, rhs ) GEOS_WARNING_IF_GT_MSG( lhs, rhs, "" )
605 #define GEOS_WARNING_IF_GE_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, >=, <, rhs, __VA_ARGS__ )
612 #define GEOS_WARNING_IF_GE( lhs, rhs ) GEOS_WARNING_IF_GE_MSG( lhs, rhs, "" )
622 #define GEOS_WARNING_IF_LT_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, <, >=, rhs, __VA_ARGS__ )
629 #define GEOS_WARNING_IF_LT( lhs, rhs ) GEOS_WARNING_IF_LT_MSG( lhs, rhs, "" )
639 #define GEOS_WARNING_IF_LE_MSG( lhs, rhs, ... ) GEOS_WARNING_IF_OP_MSG( lhs, <=, >, rhs, __VA_ARGS__ )
646 #define GEOS_WARNING_IF_LE( lhs, rhs ) GEOS_WARNING_IF_LE_MSG( lhs, rhs, "" )
659 #define GEOS_THROW_IF_OP_MSG( lhs, OP, NOP, rhs, MSG, ... ) \
661 GEOS_ERROR_LHS_RHS_DECLS( lhs, rhs ); \
662 GEOS_THROW_IF_CAUSE( lhsResult OP rhsResult, \
663 "Expected: " #lhs " " #NOP " " #rhs "\n* " #lhs " = " << lhsResult << "\n* " #rhs " = " << rhsResult << "\n", \
664 MSG, __VA_ARGS__ ); \
678 #define GEOS_THROW_IF_EQ_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, ==, !=, rhs, MSG, __VA_ARGS__ )
688 #define GEOS_THROW_IF_EQ( lhs, rhs, ... ) GEOS_THROW_IF_EQ_MSG( lhs, rhs, "", __VA_ARGS__ )
699 #define GEOS_THROW_IF_NE_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, !=, ==, rhs, MSG, __VA_ARGS__ )
709 #define GEOS_THROW_IF_NE( lhs, rhs, ... ) GEOS_THROW_IF_NE_MSG( lhs, rhs, "", __VA_ARGS__ )
720 #define GEOS_THROW_IF_GT_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, >, <=, rhs, MSG, __VA_ARGS__ )
730 #define GEOS_THROW_IF_GT( lhs, rhs, ... ) GEOS_THROW_IF_GT_MSG( lhs, rhs, "", __VA_ARGS__ )
741 #define GEOS_THROW_IF_GE_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, >=, <, rhs, MSG, __VA_ARGS__ )
751 #define GEOS_THROW_IF_GE( lhs, rhs, ... ) GEOS_THROW_IF_GE_MSG( lhs, rhs, "", __VA_ARGS__ )
762 #define GEOS_THROW_IF_LT_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, <, >=, rhs, MSG, __VA_ARGS__ )
772 #define GEOS_THROW_IF_LT( lhs, rhs, ... ) GEOS_THROW_IF_LT_MSG( lhs, rhs, "", __VA_ARGS__ )
783 #define GEOS_THROW_IF_LE_MSG( lhs, rhs, MSG, ... ) GEOS_THROW_IF_OP_MSG( lhs, <=, >, rhs, MSG, __VA_ARGS__ )
793 #define GEOS_THROW_IF_LE( lhs, rhs, ... ) GEOS_THROW_IF_LE_MSG( lhs, rhs, "", __VA_ARGS__ )
795 #if !defined(NDEBUG) || defined(GEOS_ASSERT_ENABLED)
800 #define GEOS_ASSERT_ENABLED
814 #define GEOS_ASSERT_MSG( COND, ... ) \
815 GEOS_ERROR_IF_CAUSE( !( COND ), "Expected: " STRINGIZE( COND ), __VA_ARGS__ )
826 #define GEOS_ASSERT_OP_MSG( lhs, OP, rhs, ... ) \
828 GEOS_ERROR_LHS_RHS_DECLS( lhs, rhs ); \
829 GEOS_ERROR_IF_CAUSE( !( lhsResult OP rhsResult ), \
830 "Expected: " #lhs " " #OP " " #rhs "\n* " #lhs " = " << lhsResult << "\n* " #rhs " = " << rhsResult << "\n", \
836 #define GEOS_ASSERT_MSG( ... ) ((void) 0)
837 #define GEOS_ASSERT_OP_MSG( ... ) ((void) 0)
845 #define GEOS_ASSERT( COND ) GEOS_ASSERT_MSG( COND, "" )
855 #define GEOS_ASSERT_EQ_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, ==, rhs, __VA_ARGS__ )
862 #define GEOS_ASSERT_EQ( lhs, rhs ) GEOS_ASSERT_EQ_MSG( lhs, rhs, "" )
872 #define GEOS_ASSERT_NE_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, !=, rhs, __VA_ARGS__ )
879 #define GEOS_ASSERT_NE( lhs, rhs ) GEOS_ASSERT_NE_MSG( lhs, rhs, "" )
889 #define GEOS_ASSERT_GT_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, >, rhs, __VA_ARGS__ )
896 #define GEOS_ASSERT_GT( lhs, rhs ) GEOS_ASSERT_GT_MSG( lhs, rhs, "" )
906 #define GEOS_ASSERT_GE_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, >=, rhs, __VA_ARGS__ )
913 #define GEOS_ASSERT_GE( lhs, rhs ) GEOS_ASSERT_GE_MSG( lhs, rhs, "" )
923 #define GEOS_ASSERT_LT_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, <, rhs, __VA_ARGS__ )
930 #define GEOS_ASSERT_LT( lhs, rhs ) GEOS_ASSERT_LT_MSG( lhs, rhs, "" )
940 #define GEOS_ASSERT_LE_MSG( lhs, rhs, ... ) GEOS_ASSERT_OP_MSG( lhs, <=, rhs, __VA_ARGS__ )
947 #define GEOS_ASSERT_LE( lhs, rhs ) GEOS_ASSERT_LE_MSG( lhs, rhs, "" )
962 std::runtime_error( what )
970 std::runtime_error( what )
991 std::runtime_error( what )
999 std::runtime_error( what )
1024 std::runtime_error( what )
1044 extern std::ostream * g_rankStream;
1048 #if defined(GEOS_USE_MPI)
1054 void InitializeLogger( MPI_Comm comm,
const std::string & rank_output_dir=
"" );
This file provides the infrastructure to capture external errors.
void FinalizeLogger()
Finalize the logger and close the rank streams.
void InitializeLogger(const std::string &rank_output_dir="")
Initialize the logger in a serial build.
Exception class used for special control flow.
std::string string
String type.
Exception class used to report errors from type conversion.
BadTypeError(std::string const &what)
Constructor.
Exception class used to report errors in user input.
SimulationError(std::exception const &subException, std::string const &msgToInsert)
Construct a SimulationError from an underlying exception.
SimulationError(std::string const &what)
Constructor.
SimulationError(char const *const what)
Constructor.