]> vaikene.ee Git - evaf/blobdiff - src/libs/Common/logger.h
Numeric character and character entity references are now also supported when convert...
[evaf] / src / libs / Common / logger.h
index c47be4f409d88306728d9e52fd356b19c6e07281..1dfdc62408a805f0ed985b93b36eb638898bbdc8 100644 (file)
 #include "ilogger.h"
 
 #include <QObject>
+#include <QString>
+#include <QHash>
+#include <QExplicitlySharedDataPointer>
+#include <QSharedData>
+
+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<QString, QExplicitlySharedDataPointer<LoggerSource> > 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