void throw_on_fatal() { loguru::set_fatal_handler([](const loguru::Message& message){ LOG_F(INFO, "Throwing exception..."); throw std::runtime_error(std::string(message.prefix) + message.message); }); { LOG_SCOPE_F(INFO, "CHECK_F throw + catch"); try { CHECK_F(false, "some CHECK_F message"); } catch (std::runtime_error& e) { LOG_F(INFO, "CHECK_F threw this: '%s'", e.what()); } } #if LOGURU_WITH_STREAMS { LOG_SCOPE_F(INFO, "CHECK_S throw + catch"); try { CHECK_S(false) << "Some CHECK_S message"; } catch (std::runtime_error& e) { LOG_F(INFO, "CHECK_S threw this: '%s'", e.what()); } } LOG_F(INFO, "Trying an uncaught exception:"); CHECK_S(false); #else CHECK_F(false); #endif // LOGURU_WITH_STREAMS }
int main_test(int argc, char* argv[]) { loguru::init(argc, argv); LOG_SCOPE_FUNCTION(INFO); LOG_F(INFO, "Doing some stuff..."); for (int i=0; i<2; ++i) { LOG_SCOPE_F(1, "Iteration %d", i); auto result = some_expensive_operation(); LOG_IF_F(WARNING, result == BAD, "Bad result"); } LOG_F(INFO, "Time to go!"); return 0; }
void test_scopes() { LOG_SCOPE_FUNCTION(INFO); LOG_F(INFO, "Should be indented one step"); LOG_F(1, "First thing"); LOG_F(1, "Second thing"); { LOG_SCOPE_F(1, "Some indentation at level 1"); LOG_F(INFO, "Should only be indented one more step iff verbosity is 1 or higher"); LOG_F(2, "Some info"); sleep_ms(123); } sleep_ms(64); }