X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Flogger.h;h=1dfdc62408a805f0ed985b93b36eb638898bbdc8;hb=60aebc188674bbfb67be51958ec33171c72986b9;hp=c47be4f409d88306728d9e52fd356b19c6e07281;hpb=4d81227da330c21c7aa0badc88bd5ad4467067fb;p=evaf
diff --git a/src/libs/Common/logger.h b/src/libs/Common/logger.h
index c47be4f..1dfdc62 100644
--- a/src/libs/Common/logger.h
+++ b/src/libs/Common/logger.h
@@ -23,6 +23,12 @@
#include "ilogger.h"
#include
+#include
+#include
+#include
+#include
+
+class QThread;
namespace eVaf {
@@ -96,6 +102,30 @@ public: // Members (we don't bother adding getter/setter functions)
};
+/**
+ * Worker class for the logger.
+ *
+ * This class separates potentially expensive I/O from the iLogger interface making sure
+ * that writing to the log file does not block the main thread.
+ */
+class LoggerWorker : public QObject
+{
+ Q_OBJECT
+
+public slots:
+
+ /**
+ * Writes a message to the log file
+ * @param src The logger source
+ * @param msg The message
+ *
+ * This function writes the message to the log file. It also controls the size and
+ * number of log files.
+ */
+ void writeToLogFile(LoggerSource const & src, QString const & msg);
+
+};
+
/**
* iLogger interface implementation.
*
@@ -125,48 +155,61 @@ public:
virtual void setDefaultSource(QString const & source);
- virtual Severity severity(QString const & source = 0) const;
+ virtual iLogger::Severity severity(QString const & source = 0);
- virtual void setSeverity(Severity severity, QString const & source = 0);
+ virtual void setSeverity(iLogger::Severity severity, QString const & source = 0);
- virtual uint maxSize(QString const & source = 0) const;
+ virtual uint maxSize(QString const & source = 0);
virtual void setMaxSize(uint maxSize, QString const & source = 0);
- virtual uint maxCount(QString const & source = 0) const;
+ virtual uint maxCount(QString const & source = 0);
virtual void setMaxCount(uint maxCount, QString const & source = 0);
- virtual Severity consoleSeverity() const { return mConsoleSeverity; }
+ virtual iLogger::Severity consoleSeverity() const { return mConsoleSeverity; }
- virtual void setConsoleSeverity(Severity severity);
+ virtual void setConsoleSeverity(iLogger::Severity severity);
virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0);
virtual QString printf(char const * const fmt, ...) const;
+ virtual QString printable(QByteArray const & msg) const;
+
virtual FatalMsgHandler installFatalMsgHandler(FatalMsgHandler newHandler);
+signals:
+
+ void writeToLogFile(LoggerSource const & src, QString const & msg);
+
+
private: // Members
/// Current fatal error message handler
FatalMsgHandler mFatalMsgHandler;
+ /// Console output severity level
+ iLogger::Severity mConsoleSeverity;
+
/// Current default source (defaults to "evaf")
QString mDefaultSource;
/// Logger sources
QHash > mSources;
+ /// Worker thread
+ QThread * mThread;
-private: // Methods
+ /// Worker object
+ LoggerWorker * mWorker;
- /// Returns the source by the name
- LoggerSource * getSource(QString const & name) const;
- /// Creates a new source
- LoggerSource * addSource(QString const & name);
+private: // Methods
+
+ /// Returns the source by the name. The source is created if it does not exist yet.
+ LoggerSource * getSource(QString const & name);
#ifdef Q_OS_WIN32
/// Changes text colors on the Windows console