messagingappbase/smartmessaging/gmsmodel/src/GmsLog.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Class offers static utility functions for GmsModel.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "GmsLog.h"
       
    24 
       
    25 #ifdef GMSMODEL_ENABLE_LOGGING
       
    26 #include <flogger.h>
       
    27 
       
    28 /// Folder where the log resides
       
    29 _LIT( KLogFolder, "GmsModel" );
       
    30 
       
    31 /// The name of the log file
       
    32 _LIT( KLogFileName, "GmsModel" );
       
    33 
       
    34 /// The format in which the time is formatted in log
       
    35 _LIT( KLogTimeFormat, "%02d.%02d:%02d:%06d ");
       
    36 
       
    37 /// The length of the string produced by KLogTimeFormat
       
    38 const TInt KLogTimeFormatLength = 16;
       
    39 
       
    40 /// How many characters a log line can contain
       
    41 const TInt KLogLineLength = 256;
       
    42 
       
    43 #endif // GMSMODEL_ENABLE_LOGGING       
       
    44 
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 #ifdef GMSMODEL_ENABLE_LOGGING
       
    48 // ---------------------------------------------------------
       
    49 // Log() 
       
    50 //
       
    51 // ---------------------------------------------------------
       
    52 void GmsLog::Log( TRefByValue<const TDesC> aText, ... )
       
    53     {
       
    54     VA_LIST args;
       
    55     VA_START( args, aText );
       
    56 
       
    57     TBuf<256> buf;
       
    58     buf.FormatList( aText, args );
       
    59 
       
    60 #ifdef GMSMODEL_LOG_TO_FILE
       
    61 	RFileLogger logger;
       
    62 	TInt ret = logger.Connect();
       
    63 	if (ret==KErrNone)
       
    64 		{
       
    65 		logger.SetDateAndTime( EFalse,EFalse );
       
    66 		logger.CreateLog( KLogFolder, KLogFileName, EFileLoggingModeAppend );		
       
    67 		TBuf<KLogTimeFormatLength> timeStamp;
       
    68 		TTime now;
       
    69 		now.HomeTime();
       
    70 		TDateTime dateTime;
       
    71 		dateTime = now.DateTime();
       
    72 		timeStamp.Format( KLogTimeFormat, 
       
    73             dateTime.Hour(), dateTime.Minute(),
       
    74             dateTime.Second(), dateTime.MicroSecond() );
       
    75 		buf.Insert( 0, timeStamp );
       
    76 
       
    77 		logger.Write(buf);
       
    78 		}
       
    79 
       
    80 	logger.Close();
       
    81 
       
    82 #else
       
    83     RDebug::Print( buf );
       
    84 #endif // GMSMODEL_LOG_TO_FILE
       
    85 
       
    86     VA_END( args );
       
    87     }
       
    88 
       
    89 #endif // GMSMODEL_ENABLE_LOGGING
       
    90 
       
    91 // End of file