src/messaging/win32wce/qmaillog.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QMAILLOG_H
       
    43 #define QMAILLOG_H
       
    44 
       
    45 #include "qmailglobal.h"
       
    46 #include <QtDebug>
       
    47 
       
    48 #ifdef QMAIL_SYSLOG
       
    49 
       
    50 #include <QTextStream>
       
    51 
       
    52 class QTOPIAMAIL_EXPORT SysLog
       
    53 {
       
    54 public:
       
    55     SysLog();
       
    56     virtual ~SysLog();
       
    57     template<typename T> SysLog& operator<<(const T&);
       
    58     template<typename T> SysLog& operator<<(const QList<T> &list);
       
    59     template<typename T> SysLog& operator<<(const QSet<T> &set);
       
    60 
       
    61 private:
       
    62     void write(const QString& message);
       
    63 
       
    64 private:
       
    65     QString buffer;
       
    66 };
       
    67 
       
    68 template <class T>
       
    69 inline SysLog& SysLog::operator<<(const QList<T> &list)
       
    70 {
       
    71     operator<<("(");
       
    72     for (Q_TYPENAME QList<T>::size_type i = 0; i < list.count(); ++i) {
       
    73         if (i)
       
    74             operator<<(", ");
       
    75         operator<<(list.at(i));
       
    76     }
       
    77     operator<<(")");
       
    78     return *this;
       
    79 }
       
    80 
       
    81 template <class T>
       
    82 inline SysLog& SysLog::operator<<(const QSet<T> &set)
       
    83 {
       
    84     operator<<("QSET");
       
    85     operator<<(set.toList());
       
    86     return *this;
       
    87 }
       
    88 
       
    89 template<typename T>
       
    90 SysLog& SysLog::operator<<(const T& item)
       
    91 {
       
    92     QTextStream stream(&buffer);
       
    93     stream << item;
       
    94     return *this;
       
    95 }
       
    96 #endif //QMAIL_SYSLOG
       
    97 
       
    98 class QTOPIAMAIL_EXPORT QLogBase {
       
    99 public:
       
   100 #ifdef QMAIL_SYSLOG
       
   101     static SysLog log(const char*);
       
   102 #else
       
   103     static QDebug log(const char*);
       
   104 #endif
       
   105 };
       
   106 
       
   107 #define QLOG_DISABLE(dbgcat) \
       
   108     class dbgcat##_QLog : public QLogBase { \
       
   109     public: \
       
   110         static inline bool enabled() { return 0; }\
       
   111     };
       
   112 #define QLOG_ENABLE(dbgcat) \
       
   113     class dbgcat##_QLog : public QLogBase { \
       
   114     public: \
       
   115         static inline bool enabled() { return 1; }\
       
   116     };
       
   117 
       
   118 #define qMailLog(dbgcat) if(!dbgcat##_QLog::enabled()); else dbgcat##_QLog::log(#dbgcat)
       
   119 
       
   120 #ifdef QMF_ENABLE_LOGGING
       
   121 QLOG_ENABLE(Messaging)
       
   122 QLOG_ENABLE(IMAP)
       
   123 QLOG_ENABLE(SMTP)
       
   124 QLOG_ENABLE(POP)
       
   125 QLOG_DISABLE(ImapData)
       
   126 QLOG_DISABLE(MessagingState)
       
   127 #else
       
   128 QLOG_DISABLE(Messaging)
       
   129 QLOG_DISABLE(IMAP)
       
   130 QLOG_DISABLE(SMTP)
       
   131 QLOG_DISABLE(POP)
       
   132 QLOG_DISABLE(ImapData)
       
   133 QLOG_DISABLE(MessagingState)
       
   134 #endif
       
   135 
       
   136 #endif //QMAILLOG_H