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;
47 } // of namespace simgear
50 * Class to manage the debug logging stream.
55 static void initGlobalLogstream();
57 * Set the global log class and priority level.
58 * @param c debug class
61 void setLogLevels( sgDebugClass c, sgDebugPriority p );
63 bool would_log( sgDebugClass c, sgDebugPriority p ) const;
65 void logToFile( const SGPath& aPath, sgDebugClass c, sgDebugPriority p );
67 void set_log_priority( sgDebugPriority p);
69 void set_log_classes( sgDebugClass c);
71 sgDebugClass get_log_classes() const;
73 sgDebugPriority get_log_priority() const;
76 * the core logging method
78 void log( sgDebugClass c, sgDebugPriority p,
79 const char* fileName, int line, const std::string& msg);
83 * Return the one and only logstream instance.
84 * We use a function instead of a global object so we are assured that cerr
85 * has been initialised.
86 * @return current logstream
88 friend logstream& sglog();
91 * register a logging callback. Note callbacks are run in a
92 * dedicated thread, so callbacks which pass data to other threads
93 * must use appropriate locking.
95 void addCallback(simgear::LogCallback* cb);
97 void removeCallback(simgear::LogCallback* cb);
106 /** \def SG_LOG(C,P,M)
108 * @param C debug class
113 # define SG_LOG(C,P,M)
115 # define SG_LOG(C,P,M) do { \
116 if(sglog().would_log(C,P)) { \
117 std::ostringstream os; \
119 sglog().log(C, P, __FILE__, __LINE__, os.str()); \
124 #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)
126 #endif // _LOGSTREAM_H