radioapp/radioenginewrapper/src/radiologger.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 26 6bcf277166c1
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
     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 
       
    18 // System includes
       
    19 #include <QDebug>
       
    20 
       
    21 // User includes
       
    22 #include "radiologger.h"
       
    23 
       
    24 /*!
       
    25  *
       
    26  */
       
    27 void RadioLogger::initCombinedLogger()
       
    28 {
       
    29 #if defined LOGGING_ENABLED && defined COMBINE_WITH_ENGINE_LOGGER && !defined BUILD_WIN32
       
    30     TRAP_IGNORE( RadioEngineUtils::InitializeL() );
       
    31     if ( !MRadioEngineLogger::Logger() ) {
       
    32         qDebug() << "FMRadioUi: Cannot combine logs with engine. Engine logger not active";
       
    33     }
       
    34 #endif // LOGGING_ENABLED
       
    35 }
       
    36 
       
    37 /*!
       
    38  *
       
    39  */
       
    40 void RadioLogger::releaseCombinedLogger()
       
    41 {
       
    42 #if defined LOGGING_ENABLED && defined COMBINE_WITH_ENGINE_LOGGER && !defined BUILD_WIN32
       
    43     RadioEngineUtils::Release();
       
    44 #endif // LOGGING_ENABLED
       
    45 }
       
    46 
       
    47 /*!
       
    48  *    enum Mode { Normal, MethodEnter, MethodExit, DecIndent };
       
    49  */
       
    50 void RadioLogger::logMsg( const char* msg, Mode mode )
       
    51 {
       
    52     Q_UNUSED( msg );
       
    53     Q_UNUSED( mode );
       
    54 #if defined LOGGING_ENABLED && defined COMBINE_WITH_ENGINE_LOGGER && !defined BUILD_WIN32
       
    55     MRadioEngineLogger* logger = MRadioEngineLogger::Logger();
       
    56     if ( logger ) {
       
    57         if ( mode == RadioLogger::Normal ) {
       
    58             logger->AddIndent(KMarkerUi()).Add( msg ).Commit();
       
    59         } else if ( mode == RadioLogger::MethodEnter ) {
       
    60             logger->AddIndentClear( KMarkerUi() ).Add( msg ).Commit();
       
    61             logger->IncIndent();
       
    62         } else if ( mode == RadioLogger::MethodExit ) {
       
    63             logger->DecIndent();
       
    64             logger->AddIndentClear( KMarkerUi() ).Add( msg ).Commit();
       
    65         } else if ( mode == RadioLogger::DecIndent ) {
       
    66             logger->DecIndent();
       
    67         } else {}
       
    68     }
       
    69 #endif // LOGGING_ENABLED
       
    70 }
       
    71 
       
    72 
       
    73 #ifdef LOGGING_ENABLED
       
    74 
       
    75 #include <QString>
       
    76 #include <QFile>
       
    77 #include <QTextStream>
       
    78 #include <QDateTime>
       
    79 
       
    80 #ifdef TRACE_TO_FILE
       
    81     QFile mDebugFile;
       
    82     bool mFilterByLogMarker = false;
       
    83 #endif
       
    84 
       
    85 const char* KLogEnter = "\\ %s";
       
    86 const char* KLogExit = "/ %s";
       
    87 const char* KLogExitRet = "/ %s, Returning %s";
       
    88 const char* KLogExitException = "/ %s, Exception raised";
       
    89 const char* KLogLine = "| ";
       
    90 
       
    91 /*!
       
    92  *
       
    93  */
       
    94 static QString formatString( const char* format, long val )
       
    95 {
       
    96     if ( strcmp( format, "" ) == 0 ) {
       
    97         return "";
       
    98     }
       
    99     QString string;
       
   100     string.sprintf( format, val );
       
   101     return string;
       
   102 }
       
   103 
       
   104 /*!
       
   105  *
       
   106  */
       
   107 MethodLogger::MethodLogger( const char* function, const char* format ) :
       
   108     mFunction( function ),
       
   109     mFormat( format )
       
   110 {
       
   111     QString msg;
       
   112     msg.sprintf( KLogEnter, mFunction );
       
   113     WRITELOG_METHOD_ENTER( msg );
       
   114 }
       
   115 
       
   116 /*!
       
   117  *
       
   118  */
       
   119 MethodLogger::~MethodLogger()
       
   120 {
       
   121     if ( std::uncaught_exception() ) {
       
   122         QString msg;
       
   123         msg.sprintf( KLogExitException, mFunction );
       
   124         WRITELOG_METHOD_EXIT( msg );
       
   125     } else {
       
   126         QString msg;
       
   127         if ( strlen( mFormat ) > 0 ) {
       
   128             #if defined(__WINS__)
       
   129 
       
   130                 long retVal = 0;
       
   131                 _asm( mov retVal, ebx );
       
   132                 msg.sprintf( KLogExitRet, mFunction, formatString( mFormat, retVal ) );
       
   133                 WRITELOG_METHOD_EXIT( msg );
       
   134 
       
   135             #else
       
   136                 msg.sprintf( KLogExit, mFunction );
       
   137                 WRITELOG_METHOD_EXIT( msg );
       
   138             #endif
       
   139         } else {
       
   140             msg.sprintf( KLogExit, mFunction );
       
   141             WRITELOG_METHOD_EXIT( msg );
       
   142         }
       
   143     }
       
   144 }
       
   145 #else
       
   146 
       
   147 MethodLogger::MethodLogger( const char*, const char* )
       
   148 {
       
   149 }
       
   150         
       
   151 MethodLogger::~MethodLogger()
       
   152 {
       
   153 }
       
   154 
       
   155 #endif // LOGGING_ENABLED
       
   156 
       
   157 
       
   158 #ifdef TRACE_TO_FILE
       
   159 
       
   160 /*!
       
   161  *
       
   162  */
       
   163 void FileLogger::installMessageHandler( const QString& fileName, bool filterByMarker )
       
   164 {
       
   165     mDebugFile.setFileName( fileName );
       
   166     mFilterByLogMarker = filterByMarker;
       
   167 
       
   168     mDebugFile.open( QIODevice::Text | QIODevice::WriteOnly );
       
   169 
       
   170     if ( mDebugFile.isOpen() ) {
       
   171         qInstallMsgHandler( FileLogger::handleMessage );
       
   172     }
       
   173 }
       
   174 
       
   175 /*!
       
   176  *
       
   177  */
       
   178 void FileLogger::uninstallMessageHandler()
       
   179 {
       
   180     if ( mDebugFile.isOpen() ) {
       
   181         qInstallMsgHandler( 0 );
       
   182         mDebugFile.close();
       
   183     }
       
   184 }
       
   185 
       
   186 /*!
       
   187  *
       
   188  */
       
   189 void FileLogger::handleMessage( QtMsgType type, const char* msg )
       
   190 {
       
   191     QTextStream debugStream( &mDebugFile );
       
   192     QDateTime dateTime( QDateTime::currentDateTime() );
       
   193 
       
   194     if ( type == QtDebugMsg ) {
       
   195         QString message( msg );
       
   196         if ( mFilterByLogMarker && message.contains( QString( LOGMARKER ) ) )
       
   197         {
       
   198             debugStream << dateTime.toString("yyyy-MM-dd hh:mm:ss.zzz") << " : " << message << endl;
       
   199         }
       
   200     }
       
   201 }
       
   202 #endif // TRACE_TO_FILE