PECengine/CoreUtilsLib2/Src/PEngLogger.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Logger implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "PEngLogger.h"
       
    20 #include "PEngConfig.h"
       
    21 #include "PresenceDebugPrint.h"
       
    22 
       
    23 #include <E32Svr.h>
       
    24 #include <E32Std.h>
       
    25 #include <flogger.h>
       
    26 
       
    27 
       
    28 /**
       
    29  * Handler used by logger to truncate the string
       
    30  * rather than panic in case of buffer overflow.
       
    31  *
       
    32  * @since 3.0
       
    33  */
       
    34 NONSHARABLE_CLASS( TPEngOverflowTruncate ) : public TDes16Overflow
       
    35     {
       
    36 public:
       
    37     void Overflow( TDes16& /*aDes*/ ) {}
       
    38     };
       
    39 
       
    40 
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // PEngLogger::WriteLog()
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C void PEngLogger::WriteLog( TRefByValue<const TDesC> aFmt, ... )
       
    49     {
       
    50     //Suppress unused formal parameter warning
       
    51     ( void )aFmt;
       
    52 
       
    53 #ifdef PENG_ENABLE_DEBUG_PRINT
       
    54 
       
    55     //Format the log line
       
    56     TBuf< KPEngMaxLogLineLength > buffer;
       
    57     buffer.Append( _L( "[" ) );             // CSI: 78 #
       
    58     buffer.Append( RThread().Name() );
       
    59     buffer.Append( _L( "] " ) );            // CSI: 78 #
       
    60 
       
    61     TPEngOverflowTruncate overflow;
       
    62 
       
    63     VA_LIST list;
       
    64     VA_START( list, aFmt );
       
    65     buffer.AppendFormatList( aFmt, list, &overflow );
       
    66 
       
    67 
       
    68 #ifdef PENG_DEBUG_OUTPUT_TO_FILE
       
    69     //Log goes to file
       
    70     RFileLogger logger;
       
    71     if ( logger.Connect() == KErrNone )
       
    72         {
       
    73         logger.SetDateAndTime( EFalse, ETrue );
       
    74         logger.CreateLog( KPENGDebugOutputDir,
       
    75                           KPENGDebugOutputFileName,
       
    76                           EFileLoggingModeAppend );
       
    77 
       
    78         logger.Write( buffer );
       
    79         logger.CloseLog();
       
    80         logger.Close();
       
    81         }
       
    82 
       
    83 #else
       
    84 
       
    85     //Log goes to default debug output
       
    86     RDebug::Print( _L( "%S" ), &buffer );
       
    87 
       
    88 #endif  //PENG_DEBUG_OUTPUT_TO_FILE
       
    89 
       
    90 #endif //PENG_ENABLE_DEBUG_PRINT
       
    91     }
       
    92 
       
    93 
       
    94 // End of File
       
    95 
       
    96