Skip to content

Commit

Permalink
Merge pull request #12 from rburchell/master
Browse files Browse the repository at this point in the history
Remove custom logging framework
  • Loading branch information
lpotter committed Oct 3, 2013
2 parents 35e89a4 + a2370f7 commit 902bcab
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 465 deletions.
1 change: 0 additions & 1 deletion core/core.pro
Expand Up @@ -38,7 +38,6 @@ SOURCES += sensormanager.cpp \
plugin.cpp \
abstractsensor_a.cpp \
abstractsensor.cpp \
logging.cpp \
parameterparser.cpp \
abstractchain.cpp \
sysfsadaptor.cpp \
Expand Down
168 changes: 0 additions & 168 deletions core/logging.cpp

This file was deleted.

186 changes: 6 additions & 180 deletions core/logging.h
Expand Up @@ -27,186 +27,12 @@
#ifndef LOGGING_H
#define LOGGING_H

#include <sstream>
#include <fstream>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QMutex>
#include <QDebug>

/**
* Log levels
*/
enum SensordLogLevel
{
SensordLogTest = 1, /**< Test */
SensordLogDebug, /**< Debug */
SensordLogWarning, /**< Warning */
SensordLogCritical, /**< Critical */
SensordLogN
};

/**
* Logging utility. All sensorfw logging is done using this class.
* Set of macro functions exists for convenient usage.
*/
class SensordLogger
{
public:
/**
* Constructor.
*
* @param func Function name where logger is used.
* @param file File name where logger is used.
* @param line Line number of the file where logger is used.
* @param level Logging verbosity level.
*/
SensordLogger(const char *func, const char *file, int line, SensordLogLevel level);

/**
* Destructor.
*/
~SensordLogger();

/**
* Stream given parameter into logger.
*
* @param item item to be logged.
* @return logger.
*/
SensordLogger& operator<<(const QStringList& item)
{
if(initialized && oss && isLoggable(currentLevel))
return this->operator<<(item.join(", "));
return *this;
}

/**
* Stream given parameter into logger.
*
* @param item item to be logged.
* @return logger.
*/
SensordLogger& operator<<(const QString& item)
{
if(initialized && oss && isLoggable(currentLevel))
*oss << item.toStdString();
return *this;
}

/**
* Stream given parameter into logger.
*
* @param item item to be logged.
* @return logger.
*/
SensordLogger& operator<<(const QByteArray& item)
{
if(initialized && isLoggable(currentLevel))
*oss << item.constData();
return *this;
}

/**
* Stream given parameter into logger.
*
* @tparam T item type to be logged.
* @param item item to be logged.
* @return logger.
*/
template <typename T>
SensordLogger& operator<<(const T& item)
{
if(initialized && oss && isLoggable(currentLevel))
*oss << item;
return *this;
}

/**
* Configure global output level for the logger.
*
* @param level Only messages with this or higher level will be logged.
*/
static void setOutputLevel(SensordLogLevel level);

/**
* Get global output level for the logger.
*
* @return global output level.
*/
static inline SensordLogLevel getOutputLevel() { return outputLevel; }

/**
* Initialize logger. This must be called once in the application
* lifetime before using logger.
*
* @param target output target bits for logger. Bits are:
* 1 = stdout
* 2 = stderr
* 4 = log file
* 8 = syslog
* @param logFilePath when target (4) is enabled this is the
* log file path.
* @param name application name to be logged.
*/
static void init(int target, const QString& logFilePath, const QString& name);

/**
* Close logger. This should be called before exiting application
* when logger is not needed anymore.
*/
static void close();

private:
std::ostringstream* oss; /**< log buffer */
SensordLogLevel currentLevel; /**< level for current message */

static SensordLogLevel outputLevel; /**< logging output level */
static bool initialized; /**< is logger initialized */
static std::ofstream* logFile; /**< log file path */
static QMutex mutex; /**< logger mutex */
static int logTarget; /**< log target */
static QByteArray appName; /**< application name */

/**
* Print given data to the configured log targets.
*
* @param data text to be logged.
*/
void printToTarget(const char* data) const;

/**
* Convert log level into syslog priority.
*
* @param currentLevel log level.
* @return syslog priority.
*/
static int logPriority(int currentLevel);

/**
* Convert log level into text.
*
* @param level log level.
* @return log level in textual form.
*/
static const char* logLevelToText(int level);

/**
* Is given level loggable with current settings.
*
* @param level log level.
* @return is level loggable with current settings.
*/
inline static bool isLoggable(int level)
{
return ((level >= SensordLogTest) && (level < SensordLogN) && (level >= getOutputLevel()));
}
};

#define sensordLogT() (SensordLogger(__PRETTY_FUNCTION__, __FILE__, __LINE__, SensordLogTest))
#define sensordLogD() (SensordLogger(__PRETTY_FUNCTION__, __FILE__, __LINE__, SensordLogDebug))
#define sensordLogW() (SensordLogger(__PRETTY_FUNCTION__, __FILE__, __LINE__, SensordLogWarning))
#define sensordLogC() (SensordLogger(__PRETTY_FUNCTION__, __FILE__, __LINE__, SensordLogCritical))
#define sensordLog() (SensordLogger(__PRETTY_FUNCTION__, __FILE__, __LINE__, SensordLogTest))
#define sensordLogT() (qDebug())
#define sensordLogD() (qDebug())
#define sensordLogW() (qWarning())
#define sensordLogC() (qCritical())
#define sensordLog() (qDebug())

#endif //LOGGING_H
2 changes: 1 addition & 1 deletion rpm/sensorfw-qt5.spec
Expand Up @@ -99,7 +99,7 @@ export QT_SELECT=5

%qmake5

make %{?jobs:-j%jobs}
make %{?_smp_mflags}

# >> build post
# << build post
Expand Down
2 changes: 1 addition & 1 deletion rpm/sensorfw.spec
Expand Up @@ -53,7 +53,7 @@ unset LD_AS_NEEDED

%qmake

make %{?jobs:-j%jobs}
make %{?_smp_mflags}

# >> build post
# << build post
Expand Down

0 comments on commit 902bcab

Please sign in to comment.