2125afca7a337490287cc3888ff42dd2c0207854
[supertux.git] / src / util / log.cpp
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
25 LogLevel g_log_level = LOG_WARNING;
26
27 static std::ostream& get_logging_instance (void)
28 {
29   if (Console::instance != NULL)
30     return (Console::output);
31   else
32     return (std::cerr);
33 }
34
35 static std::ostream& log_generic_f (const char *prefix, const char* file, int line)
36 {
37   get_logging_instance () << prefix << " " << file << ":" << line << " ";
38   return (get_logging_instance ());
39 }
40
41 std::ostream& log_debug_f(const char* file, int line) 
42 {
43   return (log_generic_f ("[DEBUG]", file, line));
44 }
45
46 std::ostream& log_info_f(const char* file, int line) 
47 {
48   return (log_generic_f ("[INFO]", file, line));
49 }
50
51 std::ostream& log_warning_f(const char* file, int line) 
52 {
53   return (log_generic_f ("[WARNING]", file, line));
54 }
55
56 std::ostream& log_fatal_f(const char* file, int line) 
57 {
58   return (log_generic_f ("[FATAL]", file, line));
59 }
60
61 std::ostream& operator<<(std::ostream& out, const Vector& vector)
62 {
63   out << '[' << vector.x << ',' << vector.y << ']';
64   return out;
65 }
66
67 std::ostream& operator<<(std::ostream& out, const Rectf& rect)
68 {
69   out << "[" << rect.get_left() << "," << rect.get_top() << "   "
70       << rect.get_right() << "," << rect.get_bottom() << "]";
71   return out;
72 }
73
74 /* EOF */