X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Flogger.h;h=742ab9036a7957d48ea42cbd9170306f4418f4bd;hb=13dedf19c628b9967e4c4106ab0fd967f1df0b90;hp=1dfdc62408a805f0ed985b93b36eb638898bbdc8;hpb=720224734cb4f6ea2708c6b5ecf93cc666aad378;p=evaf
diff --git a/src/libs/Common/logger.h b/src/libs/Common/logger.h
index 1dfdc62..742ab90 100644
--- a/src/libs/Common/logger.h
+++ b/src/libs/Common/logger.h
@@ -3,7 +3,7 @@
* @brief iLogger interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
class QThread;
@@ -36,7 +37,7 @@ namespace Common {
namespace Internal {
/// Default fatal error message handler
-void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where);
+[[noreturn]] void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where);
/**
* Logger source.
@@ -54,8 +55,6 @@ public:
/**
* Initializes the source
* @param source Name of the source
- * @param logDir Full path to the log directory
- * @param etcDir Full path to the configuration files directory
*
* This function initializes the newly created logger source and sets initial
* parameters for the source.
@@ -73,25 +72,28 @@ public:
* Example logger.ini file:
* @code
* [.default]
- * severity = Fatal
- * maxSize = 100
- * maxCount = 3
+ * log_level = Fatal
+ * log_size = 100
+ * log_count = 3
*
* [my-source]
- * severity = Warning
- * maxSize = 1000
- * maxCount = 10
+ * log_level = Warning
+ * log_size = 1000
+ * log_count = 10
* @endcode
*/
- void init(QString const & source, QString const & logDir, QString const & etcDir);
+ void init(QString const & source);
public: // Members (we don't bother adding getter/setter functions)
+ /// Name of the source
+ QString name;
+
/// Current severity level
iLogger::Severity severity;
- /// Current log file name
+ /// File name
QString fileName;
/// Current maximum size of log files
@@ -137,12 +139,17 @@ class Logger : public iLogger
public:
+ /**
+ * Destroys the iLogger interface instance
+ */
+ static void destroyInstance();
+
Logger();
virtual ~Logger();
/**
- * Initializes the interface implementation
+ * Initializes the iLogger interface implementation
* @return True if ok; false if initialization failed
*/
bool init();
@@ -151,27 +158,27 @@ public:
iLogger interface
*/
- virtual QString defaultSource() const { return mDefaultSource; }
+ virtual QString defaultSource() const;
virtual void setDefaultSource(QString const & source);
- virtual iLogger::Severity severity(QString const & source = 0);
+ virtual iLogger::Severity severity(QString const & source = QString());
- virtual void setSeverity(iLogger::Severity severity, QString const & source = 0);
+ virtual void setSeverity(iLogger::Severity severity, QString const & source = QString());
- virtual uint maxSize(QString const & source = 0);
+ virtual uint maxSize(QString const & source = QString());
- virtual void setMaxSize(uint maxSize, QString const & source = 0);
+ virtual void setMaxSize(uint maxSize, QString const & source = QString());
- virtual uint maxCount(QString const & source = 0);
+ virtual uint maxCount(QString const & source = QString());
- virtual void setMaxCount(uint maxCount, QString const & source = 0);
+ virtual void setMaxCount(uint maxCount, QString const & source = QString());
virtual iLogger::Severity consoleSeverity() const { return mConsoleSeverity; }
virtual void setConsoleSeverity(iLogger::Severity severity);
- virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0);
+ virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString());
virtual QString printf(char const * const fmt, ...) const;
@@ -187,29 +194,32 @@ signals:
private: // Members
+ /// Flag indicating that logger is fully initialized
+ bool mReady;
+
/// Current fatal error message handler
FatalMsgHandler mFatalMsgHandler;
/// Console output severity level
iLogger::Severity mConsoleSeverity;
- /// Current default source (defaults to "evaf")
- QString mDefaultSource;
+ /// Default logger source
+ QExplicitlySharedDataPointer mDefaultSource;
- /// Logger sources
+ /// Other logger sources
QHash > mSources;
/// Worker thread
- QThread * mThread;
+ QScopedPointer mThread;
/// Worker object
- LoggerWorker * mWorker;
+ QScopedPointer mWorker;
private: // Methods
/// Returns the source by the name. The source is created if it does not exist yet.
- LoggerSource * getSource(QString const & name);
+ LoggerSource * getSource(QString const & name = QString());
#ifdef Q_OS_WIN32
/// Changes text colors on the Windows console