From 34083f0741a7b4ed090460bb3fbb67e0f5912967 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Mon, 11 Aug 2014 23:53:14 +0200 Subject: [PATCH] Added support for different log levels --- src/util/log.cpp | 2 ++ src/util/log.hpp | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) 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); -- 2.11.0