| 1 | // SuperTux Debug Helper Functions |
| 2 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
| 3 | // Copyright (C) 2010 Florian Forster <supertux at octo.it> |
| 4 | // |
| 5 | // This program is free software: you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation, either version 3 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | #include "util/log.hpp" |
| 19 | |
| 20 | #include <iostream> |
| 21 | |
| 22 | #include "math/rectf.hpp" |
| 23 | #include "supertux/console.hpp" |
| 24 | #include "supertux/gameconfig.hpp" |
| 25 | #include "supertux/globals.hpp" |
| 26 | |
| 27 | LogLevel g_log_level = LOG_WARNING; |
| 28 | |
| 29 | static std::ostream& get_logging_instance (bool use_console_buffer = true) |
| 30 | { |
| 31 | if (ConsoleBuffer::current() && use_console_buffer) |
| 32 | return (ConsoleBuffer::output); |
| 33 | else |
| 34 | return (std::cerr); |
| 35 | } |
| 36 | |
| 37 | static std::ostream& log_generic_f (const char *prefix, const char* file, int line, bool use_console_buffer = true) |
| 38 | { |
| 39 | get_logging_instance (use_console_buffer) << prefix << " " << file << ":" << line << " " ; |
| 40 | return (get_logging_instance (use_console_buffer)); |
| 41 | } |
| 42 | |
| 43 | std::ostream& log_debug_f(const char* file, int line, bool use_console_buffer = true) |
| 44 | { |
| 45 | return (log_generic_f ("[DEBUG]" , file, line, use_console_buffer)); |
| 46 | } |
| 47 | |
| 48 | std::ostream& log_info_f(const char* file, int line) |
| 49 | { |
| 50 | return (log_generic_f ("[INFO]" , file, line)); |
| 51 | } |
| 52 | |
| 53 | std::ostream& log_warning_f(const char* file, int line) |
| 54 | { |
| 55 | if (g_config && g_config->developer_mode && |
| 56 | Console::current() && !Console::current()->hasFocus()) { |
| 57 | Console::current()->open(); |
| 58 | } |
| 59 | return (log_generic_f ("[WARNING]" , file, line)); |
| 60 | } |
| 61 | |
| 62 | std::ostream& log_fatal_f(const char* file, int line) |
| 63 | { |
| 64 | if (g_config && g_config->developer_mode && |
| 65 | Console::current() && !Console::current()->hasFocus()) { |
| 66 | Console::current()->open(); |
| 67 | } |
| 68 | return (log_generic_f ("[FATAL]" , file, line)); |
| 69 | } |
| 70 | |
| 71 | /* Callbacks used by tinygettext */ |
| 72 | void log_info_callback(const std::string& str) |
| 73 | { |
| 74 | log_info << "\r\n[TINYGETTEXT] " << str << std::endl; |
| 75 | } |
| 76 | |
| 77 | void log_warning_callback(const std::string& str) |
| 78 | { |
| 79 | log_debug << "\r\n[TINYGETTEXT] " << str << std::endl; |
| 80 | } |
| 81 | |
| 82 | void log_error_callback(const std::string& str) |
| 83 | { |
| 84 | log_warning << "\r\n[TINYGETTEXT] " << str << std::endl; |
| 85 | } |
| 86 | |
| 87 | /* EOF */ |
| 88 | |