1 /** \file logstream.hxx
2 * Stream based logging mechanism.
5 // Written by Bernie Bright, 1998
7 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Library General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Library General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/debug/debug_types.h>
42 virtual ~LogCallback() {}
43 virtual void operator()(sgDebugClass c, sgDebugPriority p,
44 const char* file, int line, const std::string& aMessage) = 0;
46 void setLogLevels(sgDebugClass c, sgDebugPriority p);
48 LogCallback(sgDebugClass c, sgDebugPriority p);
50 bool shouldLog(sgDebugClass c, sgDebugPriority p) const;
53 sgDebugPriority m_priority;
57 * Helper force a console on platforms where it might optional, when
58 * we need to show a console. This basically means Windows at the
59 * moment - on other plaforms it's a no-op
61 void requestConsole();
63 } // of namespace simgear
66 * Class to manage the debug logging stream.
71 static void initGlobalLogstream();
73 * Set the global log class and priority level.
74 * @param c debug class
77 void setLogLevels( sgDebugClass c, sgDebugPriority p );
79 bool would_log( sgDebugClass c, sgDebugPriority p ) const;
81 void logToFile( const SGPath& aPath, sgDebugClass c, sgDebugPriority p );
83 void set_log_priority( sgDebugPriority p);
85 void set_log_classes( sgDebugClass c);
87 sgDebugClass get_log_classes() const;
89 sgDebugPriority get_log_priority() const;
92 * the core logging method
94 void log( sgDebugClass c, sgDebugPriority p,
95 const char* fileName, int line, const std::string& msg);
99 * Return the one and only logstream instance.
100 * We use a function instead of a global object so we are assured that cerr
101 * has been initialised.
102 * @return current logstream
104 friend logstream& sglog();
107 * register a logging callback. Note callbacks are run in a
108 * dedicated thread, so callbacks which pass data to other threads
109 * must use appropriate locking.
111 void addCallback(simgear::LogCallback* cb);
113 void removeCallback(simgear::LogCallback* cb);
124 /** \def SG_LOG(C,P,M)
126 * @param C debug class
131 # define SG_LOG(C,P,M)
133 # define SG_LOG(C,P,M) do { \
134 if(sglog().would_log(C,P)) { \
135 std::ostringstream os; \
137 sglog().log(C, P, __FILE__, __LINE__, os.str()); \
142 #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)
144 #endif // _LOGSTREAM_H