Split of the line buffer from Console into ConsoleBuffer class
[supertux.git] / src / util / log.cpp
index 9b94c62..de4fb3d 100644 (file)
@@ -1,5 +1,6 @@
 //  SuperTux Debug Helper Functions
 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//  Copyright (C) 2010 Florian Forster <supertux at octo.it>
 //
 //  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
 
 #include "util/log.hpp"
 
-#include "math/rect.hpp"
+#include <iostream>
+
+#include "math/rectf.hpp"
 #include "supertux/console.hpp"
 
-#ifdef DEBUG
+LogLevel g_log_level = LOG_WARNING;
 
-std::ostream& log_debug_f(const char* file, int line) 
+static std::ostream& get_logging_instance (void)
 {
-  Console::output << "[DEBUG] " << file << ":" << line << " ";
-  return Console::output;
+  if (ConsoleBuffer::current())
+    return (ConsoleBuffer::output);
+  else
+    return (std::cerr);
 }
 
-std::ostream& log_info_f(const char* file, int line) 
+static std::ostream& log_generic_f (const char *prefix, const char* file, int line)
 {
-  Console::output << "[INFO] " << file << ":" << line << " ";
-  return Console::output;
+  get_logging_instance () << prefix << " " << file << ":" << line << " ";
+  return (get_logging_instance ());
 }
 
-std::ostream& log_warning_f(const char* file, int line) 
+std::ostream& log_debug_f(const char* file, int line)
 {
-  Console::output << "[WARNING] " << file << ":" << line << " ";
-  return Console::output;
+  return (log_generic_f ("[DEBUG]", file, line));
 }
 
-std::ostream& log_fatal_f(const char* file, int line) 
+std::ostream& log_info_f(const char* file, int line)
 {
-  Console::output << "[FATAL] " << file << ":" << line << " ";
-  return Console::output;
+  return (log_generic_f ("[INFO]", file, line));
 }
 
-#else
-
-std::ostream& log_fatal_f() 
+std::ostream& log_warning_f(const char* file, int line)
 {
-  Console::output << "Fatal: ";
-  return Console::output;
+  return (log_generic_f ("[WARNING]", file, line));
 }
 
-#endif
+std::ostream& log_fatal_f(const char* file, int line)
+{
+  return (log_generic_f ("[FATAL]", file, line));
+}
 
 std::ostream& operator<<(std::ostream& out, const Vector& vector)
 {
@@ -61,7 +64,7 @@ std::ostream& operator<<(std::ostream& out, const Vector& vector)
   return out;
 }
 
-std::ostream& operator<<(std::ostream& out, const Rect& rect)
+std::ostream& operator<<(std::ostream& out, const Rectf& rect)
 {
   out << "[" << rect.get_left() << "," << rect.get_top() << "   "
       << rect.get_right() << "," << rect.get_bottom() << "]";