• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

logging.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008, 2009 Nokia Corporation.
00003  *
00004  * Contact: Marius Vollmer <marius.vollmer@nokia.com>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * version 2.1 as published by the Free Software Foundation.
00009  *
00010  * This library is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  * 02110-1301 USA
00019  *
00020  */
00021 
00022 #ifndef LOGGING_H
00023 #define LOGGING_H
00024 
00025 #include <QIODevice>
00026 #include <QString>
00027 #include <QStringList>
00028 #include <QTextStream>
00029 #include <QBuffer>
00030 #include <QDebug>
00031 
00032 #define CONTEXT_LOG_MSG_TYPE_TEST       1
00033 #define CONTEXT_LOG_MSG_TYPE_DEBUG      2
00034 #define CONTEXT_LOG_MSG_TYPE_WARNING    3
00035 #define CONTEXT_LOG_MSG_TYPE_CRITICAL   4
00036 
00037 #ifndef CONTEXT_LOG_MODULE_NAME
00038 #define CONTEXT_LOG_MODULE_NAME "unknown"
00039 #endif
00040 
00041 class ContextFeature
00042 {
00043 public:
00044     ContextFeature(QString name);
00045     QString getName() const;
00046 
00047 private:
00048     QString featureName;
00049 };
00050 
00051 class ContextRealLogger : public QTextStream
00052 {
00053 public:
00054     ContextRealLogger(int msgType, const char *module, const char *func, const char *file, int line);
00055     ~ContextRealLogger();
00056 
00057     static bool showTest; 
00058     static bool showDebug; 
00059     static bool showWarning; 
00060     static bool showCritical; 
00061     static bool initialized; 
00062     static bool hideTimestamps; 
00063     static bool useColor; 
00064     static char *showModule; 
00065     static char *hideModule; 
00066     static bool vanilla; 
00067 
00068     static void initialize();
00069 
00070     ContextRealLogger &operator<< (const ContextFeature&);
00071 
00072 //    ContextRealLogger &operator<< (const char *str);
00073 
00074     template <typename T> ContextRealLogger &operator<< (const T& qSomething)
00075         {
00076             QString out;
00077             QDebug(&out) << qSomething;
00078             QTextStream::operator<<(out);
00079             return *this;
00080         }
00081 
00082 private:
00083 
00084     bool shouldPrint();
00085     void appendFeatures();
00086 
00087     int msgType; 
00088     const char* moduleName; 
00089     QString data; 
00090     QStringList features;
00091 };
00092 
00104 class ContextZeroLogger
00105 {
00106 public:
00108     inline ContextZeroLogger() {}
00109 
00110     /* Stubby ops */
00111     template <typename T> inline ContextZeroLogger &operator<< (const T&) { return *this;} 
00112 };
00113 
00114 /* Macro defs */
00115 
00116 #define contextFeature(name) (ContextFeature(name))
00117 
00118 #ifdef CONTEXT_LOG_HIDE_TEST
00119 #define contextTest() (ContextZeroLogger())
00120 #else
00121 #define contextTest() (ContextRealLogger(CONTEXT_LOG_MSG_TYPE_TEST, CONTEXT_LOG_MODULE_NAME, __PRETTY_FUNCTION__, __FILE__, __LINE__))
00122 #endif
00123 
00124 #ifdef CONTEXT_LOG_HIDE_DEBUG
00125 #define contextDebug() (ContextZeroLogger())
00126 #else
00127 #define contextDebug() (ContextRealLogger(CONTEXT_LOG_MSG_TYPE_DEBUG, CONTEXT_LOG_MODULE_NAME, __PRETTY_FUNCTION__, __FILE__, __LINE__))
00128 #endif
00129 
00130 #ifdef CONTEXT_LOG_HIDE_WARNING
00131 #define contextWarning() (ContextZeroLogger())
00132 #else
00133 #define contextWarning() (ContextRealLogger(CONTEXT_LOG_MSG_TYPE_WARNING, CONTEXT_LOG_MODULE_NAME, __PRETTY_FUNCTION__, __FILE__, __LINE__))
00134 #endif
00135 
00136 #ifdef CONTEXT_LOG_HIDE_CRITICAL
00137 #define contextCritical() (ContextZeroLogger())
00138 #else
00139 #define contextCritical() (ContextRealLogger(CONTEXT_LOG_MSG_TYPE_CRITICAL, CONTEXT_LOG_MODULE_NAME, __PRETTY_FUNCTION__, __FILE__, __LINE__))
00140 #endif
00141 
00142 #endif // LOGGING_H

Generated on Sun Jun 1 2014 17:31:06 for libcontextprovider by  doxygen 1.7.1