From 5e987a16cb44ef86858d9a27fd191f29fecebad2 Mon Sep 17 00:00:00 2001 From: florianf Date: Thu, 11 Feb 2010 16:07:56 +0000 Subject: [PATCH] Bug 574: Check whether the Console instance still exists before accessing it. If the global Console instance doesn't exist anymore (or not yet), "std::cerr" will be used instead. Resolves: #574. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6322 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/util/log.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/util/log.cpp b/src/util/log.cpp index 036ada58c..6ce6f73b4 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -1,5 +1,6 @@ // SuperTux Debug Helper Functions // Copyright (C) 2006 Christoph Sommer +// Copyright (C) 2010 Florian Forster // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -16,33 +17,43 @@ #include "util/log.hpp" +#include + #include "math/rectf.hpp" #include "supertux/console.hpp" +static std::ostream& get_logging_instance (void) +{ + if (Console::instance != NULL) + return (Console::output); + else + return (std::cerr); +} + +static std::ostream& log_generic_f (const char *prefix, const char* file, int line) +{ + get_logging_instance () << prefix << " " << file << ":" << line << " "; + return (get_logging_instance ()); +} + std::ostream& log_debug_f(const char* file, int line) { - Console::output << "[DEBUG] " << file << ":" << line << " "; - return Console::output; + return (log_generic_f ("[DEBUG]", file, line)); } std::ostream& log_info_f(const char* file, int line) { - Console::output << "[INFO] " << file << ":" << line << " "; - return Console::output; + return (log_generic_f ("[INFO]", file, line)); } std::ostream& log_warning_f(const char* file, int line) { - Console::instance->open(); - Console::output << "[WARNING] " << file << ":" << line << " "; - return Console::output; + return (log_generic_f ("[WARNING]", file, line)); } std::ostream& log_fatal_f(const char* file, int line) { - Console::instance->open(); - Console::output << "[FATAL] " << file << ":" << line << " "; - return Console::output; + return (log_generic_f ("[FATAL]", file, line)); } std::ostream& operator<<(std::ostream& out, const Vector& vector) -- 2.11.0