controlpanel/src/inc/cplogger.h
changeset 32 20bd089f4aaa
parent 31 2c9d3aa5bea2
child 33 6263db170452
equal deleted inserted replaced
31:2c9d3aa5bea2 32:20bd089f4aaa
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 #ifndef CPLOGGER_H
       
    18 #define CPLOGGER_H
       
    19 
       
    20 #include <qdebug>
       
    21 #include <qfile>
       
    22 #include <qsettings>
       
    23 class QFile;
       
    24 
       
    25 class CpLogger 
       
    26 {
       
    27     enum { NoLog = 0, StdTraces, LogToFile };
       
    28 public:
       
    29     CpLogger() : mDebug(0), mLogFile(0)
       
    30     {
       
    31         QSettings settings;
       
    32         int logMethod = settings.value("Log/logmethod",NoLog).toInt();
       
    33         switch (logMethod)
       
    34         {
       
    35         default:
       
    36         case NoLog:
       
    37             break;
       
    38         case StdTraces:
       
    39             mDebug = new QDebug(QtDebugMsg);
       
    40             break;
       
    41         case LogToFile:
       
    42             //TBD: hardcode path will be replaced by some other form 
       
    43             mLogFile = new QFile("C:\\data\\logs\\controlpanel.log");
       
    44             mLogFile->open(QFile::WriteOnly | QFile::Append);
       
    45             mDebug = new QDebug(mLogFile);
       
    46             break;
       
    47         }
       
    48     }
       
    49 
       
    50     ~CpLogger()
       
    51     {
       
    52         delete mDebug;
       
    53         delete mLogFile;
       
    54     }
       
    55     
       
    56     template<typename T>
       
    57     inline CpLogger &operator << (const T &log) 
       
    58     {
       
    59         if (mDebug)  
       
    60         {
       
    61             (*mDebug) << log;
       
    62         }
       
    63         return *this;
       
    64     }
       
    65     
       
    66 private:
       
    67     Q_DISABLE_COPY(CpLogger)
       
    68     QDebug *mDebug;
       
    69     QFile  *mLogFile;
       
    70 };
       
    71 
       
    72 #endif /* CPLOGGER_H */