3bd60e96c8
Each of the global logstream priorities are captured into its own std::ostringstream stream, all held together in the test suite global _iostreams class instance. This object can be obtained by calling getIOstreams(). The streams are captured using the StreamLogCallback class, which is a simple modification of the simgear FileLogCallback class, registered with the global logstream's addCallback() function. When tests fail, all of contents the different simgear logstreams are now reported. The failure report consists of the following sections: - Failure information. - SG_BULK simgear logstream (all messages). - SG_BULK only simgear logstream. - SG_DEBUG only simgear logstream. - SG_INFO only simgear logstream. - SG_WARN only simgear logstream. - SG_ALERT only simgear logstream. - Combined STDOUT and STDERR streams. Any empty sections, except for SG_BULK, will not be shown.
96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
|
|
/*
|
|
* Copyright (C) 2016 Edward d'Auvergne
|
|
*
|
|
* This file is part of the program FlightGear.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
#ifndef _FG_TEST_SUITE_LOGGING_HXX
|
|
#define _FG_TEST_SUITE_LOGGING_HXX
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
|
// A logstream callback based on the simgear FileLogCallback class.
|
|
class StreamLogCallback : public simgear::LogCallback
|
|
{
|
|
public:
|
|
StreamLogCallback(std::ostringstream& stream, sgDebugClass c, sgDebugPriority p, bool priorityMatch):
|
|
simgear::LogCallback(c, p),
|
|
m_priority(p),
|
|
m_stream(stream),
|
|
m_priorityMatch(priorityMatch)
|
|
{
|
|
}
|
|
|
|
virtual void operator()(sgDebugClass c, sgDebugPriority p, const char* file, int line, const std::string& message)
|
|
{
|
|
if (m_priorityMatch && p != m_priority) return;
|
|
if (!shouldLog(c, p)) return;
|
|
if (m_priorityMatch)
|
|
m_stream << simgear::LogCallback::debugClassToString(c) << ":" << file << ":" << line << ": " << message << std::endl;
|
|
else
|
|
m_stream << simgear::LogCallback::debugClassToString(c) << ":" << (int) p << ":" << file << ":" << line << ": " << message << std::endl;
|
|
}
|
|
|
|
private:
|
|
sgDebugPriority m_priority;
|
|
std::ostringstream &m_stream;
|
|
bool m_priorityMatch;
|
|
};
|
|
|
|
|
|
// All of the captured IO streams.
|
|
class capturedIO
|
|
{
|
|
public:
|
|
// Constructor and destructor.
|
|
capturedIO();
|
|
~capturedIO();
|
|
|
|
// The IO streams.
|
|
std::ostringstream sg_bulk;
|
|
std::ostringstream sg_bulk_only;
|
|
std::ostringstream sg_debug_only;
|
|
std::ostringstream sg_info_only;
|
|
std::ostringstream sg_warn_only;
|
|
std::ostringstream sg_alert_only;
|
|
|
|
// The callback objects.
|
|
StreamLogCallback *callback_bulk;
|
|
StreamLogCallback *callback_bulk_only;
|
|
StreamLogCallback *callback_debug_only;
|
|
StreamLogCallback *callback_info_only;
|
|
StreamLogCallback *callback_warn_only;
|
|
StreamLogCallback *callback_alert_only;
|
|
};
|
|
|
|
|
|
// Return the global stream capture data structure, creating it if needed.
|
|
capturedIO & getIOstreams();
|
|
|
|
// Set up to capture all the simgear logging priorities as separate streams.
|
|
void setupLogging();
|
|
|
|
// Deactivate all the simgear logging priority IO captures.
|
|
void stopLogging();
|
|
|
|
|
|
#endif // _FG_TEST_SUITE_LOGGING_HXX
|