From: Ingo Ruhnke Date: Mon, 11 Aug 2014 21:53:14 +0000 (+0200) Subject: Added support for different log levels X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=34083f0741a7b4ed090460bb3fbb67e0f5912967;p=supertux.git Added support for different log levels --- diff --git a/src/util/log.cpp b/src/util/log.cpp index 6ce6f73b4..2125afca7 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -22,6 +22,8 @@ #include "math/rectf.hpp" #include "supertux/console.hpp" +LogLevel g_log_level = LOG_WARNING; + static std::ostream& get_logging_instance (void) { if (Console::instance != NULL) diff --git a/src/util/log.hpp b/src/util/log.hpp index 7882eac8e..a4bfabec8 100644 --- a/src/util/log.hpp +++ b/src/util/log.hpp @@ -20,17 +20,20 @@ #include #include +enum LogLevel { LOG_NONE, LOG_FATAL, LOG_WARNING, LOG_INFO, LOG_DEBUG }; +extern LogLevel g_log_level; + std::ostream& log_debug_f(const char* file, int line); -#define log_debug log_debug_f(__FILE__, __LINE__) +#define log_debug if (g_log_level < LOG_DEBUG) {} else log_debug_f(__FILE__, __LINE__) std::ostream& log_info_f(const char* file, int line); -#define log_info log_info_f(__FILE__, __LINE__) +#define log_info if (g_log_level < LOG_INFO) {} else log_info_f(__FILE__, __LINE__) std::ostream& log_warning_f(const char* file, int line); -#define log_warning log_warning_f(__FILE__, __LINE__) +#define log_warning if (g_log_level < LOG_WARNING) {} else log_warning_f(__FILE__, __LINE__) std::ostream& log_fatal_f(const char* file, int line); -#define log_fatal log_fatal_f(__FILE__, __LINE__) +#define log_fatal if (g_log_level < LOG_FATAL) {} else log_fatal_f(__FILE__, __LINE__) class Vector; std::ostream& operator<< (std::ostream& str, const Vector& vector);