summaryrefslogtreecommitdiff
path: root/TraceFile.cpp
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:31 +0200
committerChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:31 +0200
commit0e579a45e2e5823f90e2632073749583cd15fa0d (patch)
tree5e709e13d41c8ea0da0968fb6c4566057b4b7909 /TraceFile.cpp
parent28d1767618141cd6481de2e93e36e3dfa555d4b4 (diff)
parent2d1068e60bce7ae1fff11623454900e8cee956b1 (diff)
Update upstream source from tag 'upstream/2.6.0_rc3+repack'
Update to upstream version '2.6.0~rc3+repack' with Debian dir 9ee8bc3a4b60bb88f4d57c7d1f2d37dbc1632144
Diffstat (limited to 'TraceFile.cpp')
-rwxr-xr-xTraceFile.cpp186
1 files changed, 93 insertions, 93 deletions
diff --git a/TraceFile.cpp b/TraceFile.cpp
index 22284d9b..4ea1a384 100755
--- a/TraceFile.cpp
+++ b/TraceFile.cpp
@@ -1,93 +1,93 @@
-#include "TraceFile.hpp"
-
-#include <stdexcept>
-
-#include <QDebug>
-#include <QMutex>
-#include <QMutexLocker>
-#include <QString>
-#include <QFile>
-#include <QTextStream>
-
-#include "pimpl_impl.hpp"
-
-class TraceFile::impl
-{
-public:
- impl (QString const& trace_file_path);
- ~impl ();
-
- // no copying
- impl (impl const&) = delete;
- impl& operator = (impl const&) = delete;
-
-private:
- // write Qt messages to the diagnostic log file
- static void message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg);
-
- QFile file_;
- QTextStream stream_;
- QTextStream * original_stream_;
- QtMessageHandler original_handler_;
- static QTextStream * current_stream_;
- static QMutex mutex_;
-};
-
-QTextStream * TraceFile::impl::current_stream_;
-QMutex TraceFile::impl::mutex_;
-
-// delegate to implementation class
-TraceFile::TraceFile (QString const& trace_file_path)
- : m_ {trace_file_path}
-{
-}
-
-TraceFile::~TraceFile ()
-{
-}
-
-
-TraceFile::impl::impl (QString const& trace_file_path)
- : file_ {trace_file_path}
- , original_stream_ {current_stream_}
- , original_handler_ {nullptr}
-{
- // if the log file is writeable; initialise diagnostic logging to it
- // for append and hook up the Qt global message handler
- if (file_.open (QFile::WriteOnly | QFile::Append | QFile::Text))
- {
- stream_.setDevice (&file_);
- current_stream_ = &stream_;
- original_handler_ = qInstallMessageHandler (message_handler);
- }
-}
-
-TraceFile::impl::~impl ()
-{
- // unhook our message handler before the stream and file are destroyed
- if (original_handler_)
- {
- qInstallMessageHandler (original_handler_);
- }
- current_stream_ = original_stream_; // revert to prior stream
-}
-
-// write Qt messages to the diagnostic log file
-void TraceFile::impl::message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg)
-{
- Q_ASSERT_X (current_stream_, "TraceFile:message_handler", "no stream to write to");
- {
- QMutexLocker lock {&mutex_}; // thread safety - serialize writes to the trace file
- *current_stream_ << qFormatLogMessage (type, context, msg) <<
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- endl;
-#else
- Qt::endl;
-#endif
- }
-
- if (QtFatalMsg == type)
- {
- throw std::runtime_error {"Fatal Qt Error"};
- }
-}
+#include "TraceFile.hpp"
+
+#include <stdexcept>
+
+#include <QDebug>
+#include <QMutex>
+#include <QMutexLocker>
+#include <QString>
+#include <QFile>
+#include <QTextStream>
+
+#include "pimpl_impl.hpp"
+
+class TraceFile::impl
+{
+public:
+ impl (QString const& trace_file_path);
+ ~impl ();
+
+ // no copying
+ impl (impl const&) = delete;
+ impl& operator = (impl const&) = delete;
+
+private:
+ // write Qt messages to the diagnostic log file
+ static void message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg);
+
+ QFile file_;
+ QTextStream stream_;
+ QTextStream * original_stream_;
+ QtMessageHandler original_handler_;
+ static QTextStream * current_stream_;
+ static QMutex mutex_;
+};
+
+QTextStream * TraceFile::impl::current_stream_;
+QMutex TraceFile::impl::mutex_;
+
+// delegate to implementation class
+TraceFile::TraceFile (QString const& trace_file_path)
+ : m_ {trace_file_path}
+{
+}
+
+TraceFile::~TraceFile ()
+{
+}
+
+
+TraceFile::impl::impl (QString const& trace_file_path)
+ : file_ {trace_file_path}
+ , original_stream_ {current_stream_}
+ , original_handler_ {nullptr}
+{
+ // if the log file is writeable; initialise diagnostic logging to it
+ // for append and hook up the Qt global message handler
+ if (file_.open (QFile::WriteOnly | QFile::Append | QFile::Text))
+ {
+ stream_.setDevice (&file_);
+ current_stream_ = &stream_;
+ original_handler_ = qInstallMessageHandler (message_handler);
+ }
+}
+
+TraceFile::impl::~impl ()
+{
+ // unhook our message handler before the stream and file are destroyed
+ if (original_handler_)
+ {
+ qInstallMessageHandler (original_handler_);
+ }
+ current_stream_ = original_stream_; // revert to prior stream
+}
+
+// write Qt messages to the diagnostic log file
+void TraceFile::impl::message_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg)
+{
+ Q_ASSERT_X (current_stream_, "TraceFile:message_handler", "no stream to write to");
+ {
+ QMutexLocker lock {&mutex_}; // thread safety - serialize writes to the trace file
+ *current_stream_ << qFormatLogMessage (type, context, msg) <<
+#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
+ endl;
+#else
+ Qt::endl;
+#endif
+ }
+
+ if (QtFatalMsg == type)
+ {
+ throw std::runtime_error {"Fatal Qt Error"};
+ }
+}