From: Janne Kiiski Date: Wed, 24 Nov 2010 13:59:58 +0000 (+0200) Subject: Fixed LOG_LEVEL from Logger X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=b8a862df83f40e7a406cf737acd53edac3b08efa;p=situare Fixed LOG_LEVEL from Logger --- diff --git a/src/logger.h b/src/logger.h index c8f924b..9733335 100644 --- a/src/logger.h +++ b/src/logger.h @@ -6,55 +6,55 @@ #include #include "common.h" -class Logger +namespace Situare { -public: - /** Logging level - * Exists as "LogLevel" entry in Situare.conf - * Valid values: - * QtDebugMsg -> 0 - * QtWarningMsg -> 1 - * QtCriticalMsg -> 2 - * QtFatalMsg -> 3 - * QtSystemMsg -> QtCriticalMsg -> 2 - * @see QtMsgType - * Default: QtSystemMsg - */ - static QtMsgType LOG_LEVEL; - -public: - Logger(QtMsgType level, const char* msg) : - level(level), - msg(msg) + class Logger { - static bool initialized = false; - if (!initialized) { - const QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME); - LOG_LEVEL = static_cast(settings.value("LogLevel", (int)LOG_LEVEL).toInt()); - initialized = true; + public: + + public: + Logger(QtMsgType level, const char* msg) : + level(level), + msg(msg) + { + if (matchLogLevel(level)) { + time.start(); + QDebug(QtDebugMsg) << msg << "enter"; + } } - if (LOG_LEVEL <= level) { - time.start(); - QDebug(QtDebugMsg) << msg << "enter"; + ~Logger() + { + if (matchLogLevel(level)) { + QDebug(level) << msg << "exit, elapsed:" << time.elapsed() << "ms"; + } } - } - ~Logger() - { - if (LOG_LEVEL <= level) { - QDebug(level) << msg << "exit, elapsed:" << time.elapsed() << "ms"; - } - } -private: - QTime time; - QtMsgType level; - const char* msg; -}; + /** Test if given logging level matches with application logging level + * Application logging level exists as "LogLevel" entry in Situare.conf + * Valid values: + * QtDebugMsg -> 0 + * QtWarningMsg -> 1 + * QtCriticalMsg -> 2 + * QtFatalMsg -> 3 + * QtSystemMsg -> QtCriticalMsg -> 2 + * @see QtMsgType + */ + static bool matchLogLevel(QtMsgType level) + { + static const QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME); + static QtMsgType LOG_LEVEL = static_cast(settings.value("LogLevel", (int)QtSystemMsg).toInt()); + return LOG_LEVEL <= level; + } -QtMsgType Logger::LOG_LEVEL = QtSystemMsg; + private: + QTime time; + QtMsgType level; + const char* msg; + }; +} /** @brief Log function time */ -#define DEBUG_FUNCTION_TIME Logger function_time_logger(QtDebugMsg, __PRETTY_FUNCTION__) +#define DEBUG_FUNCTION_TIME Situare::Logger function_time_logger(QtDebugMsg, __PRETTY_FUNCTION__) #endif // LOGGER_H