qthighway/inc/xqservicelog.h
changeset 1 2b40d63a9c3d
child 26 3d09643def13
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #ifndef XQSERVICELOG_H
       
    23 #define XQSERVICELOG_H
       
    24 
       
    25 //#define XQSERVICE_DEBUG
       
    26 //#define XQSERVICE_DEBUG_FILE
       
    27 
       
    28 #include <qglobal.h>
       
    29 
       
    30 #ifdef XQSERVICE_DEBUG
       
    31 #include <e32std.h>
       
    32 #include <e32debug.h>
       
    33 #ifdef XQSERVICE_DEBUG_FILE
       
    34 #include <f32file.h>
       
    35 #include <flogger.h>
       
    36 #endif //XQSERVICE_DEBUG_FILE
       
    37 #endif //XQSERVICE_DEBUG
       
    38 
       
    39 #ifdef XQSERVICE_DEBUG
       
    40 #define XQSERVICE_DEBUG_PRINT(args...) qDebug(args);
       
    41 #define XQSERVICE_WARNING_PRINT(args...) qWarning(args);
       
    42 #define XQSERVICE_CRITICAL_PRINT(args...) qCritical(args);
       
    43 #define XQSERVICE_FATAL_PRINT(args...) qFatal(args);
       
    44 #define XQSERVICEMESSAGEHANDLER XqServiceMessageHandler::xqServiceMessageHandler
       
    45 #else //XQSERVICE_DEBUG not defined
       
    46 #define XQSERVICE_DEBUG_PRINT(args...)
       
    47 #define XQSERVICE_WARNING_PRINT(args...)
       
    48 #define XQSERVICE_CRITICAL_PRINT(args...)
       
    49 #define XQSERVICE_FATAL_PRINT(args...)
       
    50 #define XQSERVICEMESSAGEHANDLER 0
       
    51 #endif //XQSERVICE_DEBUG
       
    52 
       
    53 #ifdef XQSERVICE_DEBUG
       
    54 
       
    55 class XqServiceMessageHandler
       
    56     {
       
    57     
       
    58     public:
       
    59     
       
    60         static void xqServiceMessageHandler(QtMsgType /*type*/, const char *msg)
       
    61         {
       
    62         	_LIT(format, "[Qt Message] %S");
       
    63         	const TPtrC8 ptr(reinterpret_cast<const TUint8*>(msg));
       
    64 #ifndef XQSERVICE_DEBUG_FILE
       
    65             // RDebug::Print has a cap of 256 characters so break it up
       
    66             const int maxBlockSize = 256 - ((const TDesC &)format).Length();
       
    67             HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length())));
       
    68             for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) {
       
    69                 hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i)));
       
    70                 RDebug::Print(format, hbuffer);
       
    71             }
       
    72             delete hbuffer;
       
    73 #else //XQSERVICE_DEBUG_FILE defined
       
    74             _LIT(KLogDir, "qt");
       
    75             _LIT(KLogFile, "xqservice.log");
       
    76             _LIT(KLogStarting, "*** Starting XQService application ***");
       
    77             static bool logStarted;
       
    78             if ( !logStarted ){
       
    79                 RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, KLogStarting);        
       
    80                 logStarted = true; 
       
    81             }
       
    82             RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, ptr);
       
    83 #endif //XQSERVICE_DEBUG_FILE
       
    84         }
       
    85     
       
    86     };
       
    87 
       
    88 #endif //XQSERVICE_DEBUG
       
    89 
       
    90 #endif //XQSERVICELOG_H