* @brief Logger interface for eVaf
* @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.
*
Error, ///< Unexpected issues in the software that could be solved automatically.
Warning, ///< Expected issues in the software that will be solved automatically.
Info, ///< General information output by the application or modules.
- Debug ///< Information for debugging purposes.
+ Debug, ///< Information for debugging purposes.
+ Count ///< Number of severity levels
};
/// Interface constructor
* are expected to be linked against the Common library, then this is the preferred method of obtaining
* the iLogger interface. The other method is by using the iRegistry interface.
*/
- static iLogger::instance();
+ static iLogger * instance();
/**
* Returns the current default source name.
*
* Use the setDefaultSource() function to change the default source name. If not set, then
* uses the default source name "common".
+ *
+ * Changing the name of the default source resets any other settings set for the default source.
*/
virtual void setDefaultSource(QString const & source) = 0;
* Returns the current severity level
* @param source Name of the source or default if omitted.
*/
- virtual Severity severity(QString const & source = 0) const = 0;
+ virtual Severity severity(QString const & source = QString()) = 0;
/**
* Changes the current severity level.
* are output. With this function the severity level can be changed so that also less important
* messages are output.
*/
- virtual void setSeverity(Severity severity, QString const & source) = 0;
+ virtual void setSeverity(Severity severity, QString const & source = QString()) = 0;
/**
* Returns the current maximum size of log files in KiB.
* @param source Name of the source or default if omitted.
*/
- virtual uint maxSize(QString const & source = 0) const = 0;
+ virtual uint maxSize(QString const & source = QString()) = 0;
/**
* Changes the maximum size of log files for the given source
*
* Set the maximum size to 0 for no limits (dangerous!).
*/
- virtual void setMaxSize(uint maxSize, QString const & source = 0) = 0;
+ virtual void setMaxSize(uint maxSize, QString const & source = QString()) = 0;
/**
* Returns the maximum number of log files.
* @param source Name of the source or default if omitted.
*/
- virtual uint maxCount(QString const & source = 0) const = 0;
+ virtual uint maxCount(QString const & source = QString()) = 0;
/**
* Changes the maximum number of log files
*
* Set the maximum number of log files to 0 for no limits (dangerous!).
*/
- virtual void setMaxCount(uint maxCount, QString const & source = 0) = 0;
+ virtual void setMaxCount(uint maxCount, QString const & source = QString()) = 0;
/**
* Returns the current console severity level.
* Messages for the default source are also output to the console if the console severity
* level is high enough.
*/
- virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0) = 0;
+ virtual void write(Severity severity, QString const & msg, QString const & source = QString(), QString const & where = QString()) = 0;
/**
* Helper function for formatting messages using the standard printf() function.
* @return The formatted string
*/
virtual QString printf(char const * const fmt, ...) const
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
__attribute__((format(printf, 2, 3)))
#endif
= 0;
*/
virtual FatalMsgHandler installFatalMsgHandler(FatalMsgHandler newHandler) = 0;
+
+signals:
+
+ /**
+ * Logger event signal
+ * @param severity Severity of the message
+ * @param text The message
+ * @param source Source of the message
+ * @param where Where the message was output
+ *
+ * This signal is emitted for every message output with the iLogger interface. Connect
+ * your receiver to this signal if you want to add your own message handling. For example,
+ * use this signal to show messages in a log window etc.
+ */
+ void loggerEvent(Common::iLogger::Severity severity, QString const & text, QString const & source, QString const & where);
+
};
} // namespace eVaf::Common
} // namespace eVaf
/**
- * Outputs info messages
- * @param msg The format string
- * @param ... Variable list of arguments
+ * Macro for fatal error messages.
+ *
+ * This macro expands to a fatal error message output with the location in the source code where the error
+ * occurred.
+ */
+#define EVAF_FATAL_ERROR(...) \
+ do { \
+ eVaf::Common::iLogger::instance()->write( \
+ eVaf::Common::iLogger::Fatal, \
+ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
+ QString(), \
+ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
+ ); \
+ } while (0)
+
+/**
+ * Macro for error messages.
+ *
+ * This macro expands to an error message output with the location in the source code where the error
+ * occurred.
+ */
+#define EVAF_ERROR(...) \
+ do { \
+ eVaf::Common::iLogger::instance()->write( \
+ eVaf::Common::iLogger::Error, \
+ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
+ QString(), \
+ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
+ ); \
+ } while (0)
+
+/**
+ * Macro for warning messages.
+ *
+ * This macro expands to a warning message output with the location in the source code where the warning
+ * occurred.
+ */
+#define EVAF_WARNING(...) \
+ do { \
+ eVaf::Common::iLogger::instance()->write( \
+ eVaf::Common::iLogger::Warning, \
+ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
+ QString(), \
+ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
+ ); \
+ } while (0)
+
+/**
+ * Macro for info messages.
+ *
+ * This macro expands to an info message output with the location in the source code where the message
+ * is output.
+ */
+#define EVAF_INFO(...) \
+ do { \
+ eVaf::Common::iLogger::instance()->write( \
+ eVaf::Common::iLogger::Info, \
+ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
+ QString(), \
+ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
+ ); \
+ } while (0)
+
+/**
+ * Macro for debug messages.
*
- * The qInfo() function adds info messages to the Qt family of functions qDebug(), qWarning(), qError() and qFatal().
+ * This macro expands to a debug message output with the location in the source code where the message
+ * is output. All the debug messages are supressed when the NDEBUG directive is defined.
*/
-void COMMON_EXPORT qInfo(char const * const msg, ...)
-#ifdef Q_OS_LINUX
- __attribute__((format(printf, 1, 2)))
+#ifndef NDEBUG
+# define EVAF_DEBUG(...) \
+ do { \
+ eVaf::Common::iLogger::instance()->write( \
+ eVaf::Common::iLogger::Debug, \
+ eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
+ QString(), \
+ eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
+ ); \
+ } while (0)
+#else
+# define EVAF_DEBUG(...) \
+ do { } while (0)
#endif
-;
#endif // ilogger.h