Debian Codegraph @

test_suite/logging.hxx

raw symbols SCIP
1
2 /*
3 * Copyright (C) 2016 Edward d'Auvergne
4 *
5 * This file is part of the program FlightGear.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22 #ifndef _FG_TEST_SUITE_LOGGING_HXX
23 #define _FG_TEST_SUITE_LOGGING_HXX
24
25
26 #include <sstream>
27
28 #include <simgear/debug/LogCallback.hxx>
29
30
31 // A logstream callback based on the simgear FileLogCallback class.
32 class StreamLogCallback : public simgear::LogCallback
33 {
34 public:
35 StreamLogCallback(std::ostringstream& stream, sgDebugClass c, sgDebugPriority p, bool priorityMatch):
36 simgear::LogCallback(c, p),
37 m_priority(p),
38 m_stream(stream),
39 m_priorityMatch(priorityMatch)
40 {
41 }
42
43 virtual void operator()(sgDebugClass c, sgDebugPriority p, const char* file, int line, const std::string& message)
44 {
45 if (m_priorityMatch && p != m_priority) return;
46 if (!shouldLog(c, p)) return;
47 if (m_priorityMatch)
48 m_stream << debugClassToString(c) << ":" << file << ":" << line << ": " << message << std::endl;
49 else
50 m_stream << debugClassToString(c) << ":" << (int)p << ":" << file << ":" << line << ": " << message << std::endl;
51 }
52
53 private:
54 sgDebugPriority m_priority;
55 std::ostringstream &m_stream;
56 bool m_priorityMatch;
57 };
58
59
60 // All of the captured IO streams.
61 class capturedIO
62 {
63 public:
64 // Constructor and destructor.
65 capturedIO(sgDebugClass, sgDebugPriority);
66 ~capturedIO();
67
68 // The IO streams.
69 std::ostringstream sg_interleaved;
70 std::ostringstream sg_bulk_only;
71 std::ostringstream sg_debug_only;
72 std::ostringstream sg_info_only;
73 std::ostringstream sg_warn_only;
74 std::ostringstream sg_alert_only;
75
76 // The callback objects.
77 StreamLogCallback *callback_interleaved;
78 StreamLogCallback *callback_bulk_only;
79 StreamLogCallback *callback_debug_only;
80 StreamLogCallback *callback_info_only;
81 StreamLogCallback *callback_warn_only;
82 StreamLogCallback *callback_alert_only;
83
84 // The logging class and priority text.
85 std::string log_class;
86 std::string log_priority;
87 };
88
89
90 // Return the global stream capture data structure, creating it if needed.
91 capturedIO & getIOstreams(sgDebugClass c=SG_ALL, sgDebugPriority p=SG_BULK);
92
93 // Set up to capture all the simgear logging priorities as separate streams.
94 void setupLogging(sgDebugClass, sgDebugPriority, bool);
95
96 // Deactivate all the simgear logging priority IO captures.
97 void stopLogging();
98
99
100 #endif // _FG_TEST_SUITE_LOGGING_HXX