Buteo Synchronization Framework: LogMacros.h Source File

Buteo Synchronization Framework

LogMacros.h
1 /*
2 * This file is part of buteo-syncfw package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 *
6 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24
25 #ifndef LOGMACROS_H
26 #define LOGMACROS_H
27
28 #include <QString>
29 #include <QTime>
30 #include <QDebug>
31 #include <QDateTime>
32 #include <QScopedPointer>
33 #include "Logger.h"
34
36 #define LOG_MSG_L(level, msg) if(Buteo::Logger::instance()->enabled())(QDebug((QtMsgType)(level)) << __FILE__ << __LINE__ << ":" << msg)
37 #define LOG_MSG_L_PLAIN(level, msg) if(Buteo::Logger::instance()->enabled())(QDebug((QtMsgType)(level)) << msg)
38
41 #define LOG_FATAL(msg) qFatal(msg)
42 #define LOG_CRITICAL(msg) qCritical() << msg
43 #define LOG_WARNING(msg) qWarning() << msg
44
45 // use relevant logging level numbers from syslog.h where possible
46 # define LOG_PROTOCOL(msg) if (Buteo::Logger::instance()->getLogLevel() >= 6) qDebug() << msg
47 # define LOG_INFO(msg) if (Buteo::Logger::instance()->getLogLevel() >= 6) qDebug() << msg
48 # define LOG_DEBUG(msg) if (Buteo::Logger::instance()->getLogLevel() >= 7) qDebug() << msg
49 # define LOG_TRACE(msg) if (Buteo::Logger::instance()->getLogLevel() >= 8) qDebug() << msg
50 # define LOG_TRACE_PLAIN(msg) if (Buteo::Logger::instance()->getLogLevel() >= 8) qDebug() << msg
51
56 # define FUNCTION_CALL_TRACE QScopedPointer<Buteo::LogTimer> timerDebugVariable; \
57 if (Buteo::Logger::instance()->getLogLevel() >= 9) \
58 timerDebugVariable.reset(new Buteo::LogTimer(QString(__PRETTY_FUNCTION__)));
59
60 namespace Buteo {
61
65 class LogTimer
66 {
67 public:
73 LogTimer(const QString &aFunc) : iFunc(aFunc)
74 {
75 LOG_TRACE_PLAIN(iFunc << ":Entry");
76 iTimer.start();
77 }
78
83 ~LogTimer()
84 {
85 LOG_TRACE_PLAIN(iFunc << ":Exit, execution time:" << iTimer.elapsed()
86 << "ms");
87 }
88
89 private:
90 QTime iTimer;
91 QString iFunc;
92 };
93
94 }
95
96 #endif // LOGMACROS_H
97
Buteo::LogTimer
Helper class for timing function execution time.
Definition: LogMacros.h:66
Buteo::LogTimer::LogTimer
LogTimer(const QString &aFunc)
Constructor. Creates an entry message to the log.
Definition: LogMacros.h:73
Buteo::LogTimer::~LogTimer
~LogTimer()
Destructor. Creates an exit message to the log, including function execution time.
Definition: LogMacros.h:83