eventsui/eventsutils/src/evtenginedebug.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     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:  Debug File.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "evtdebug.h"
       
    22 #include <flogger.h>
       
    23 #include <e32svr.h>
       
    24 #include <f32file.h>
       
    25 #include <bautils.h>
       
    26 // CONSTANTS
       
    27 
       
    28 /// Folder where the log resides
       
    29 _LIT( KEvtLogFolder, "epos" );
       
    30 
       
    31 /// The name of the log file
       
    32 _LIT( KEvtLogFileName, "eventsui[%S].txt" );
       
    33 
       
    34 /// Events App Name
       
    35 _LIT( KEvtLogAppFileName, "evtmgmtui" );
       
    36 
       
    37 /// Handler App Name
       
    38 _LIT( KEvtLogHanlderFileName, "evthandler" );
       
    39 
       
    40 /// The format in which the time is formatted in log
       
    41 _LIT( KEvtLogTimeFormat, "%02d.%02d:%02d:%06d ");
       
    42 
       
    43 /// The length of the string produced by KLocLogTimeFormat
       
    44 const TInt KEvtLogTimeFormatLength = 16;
       
    45 
       
    46 /// How many characters a log line can contain
       
    47 const TInt KEvtLogLineLength = 256;
       
    48 
       
    49 /// Length of the Log file name.
       
    50 const TInt KEvtLogFileLength = 32;
       
    51 
       
    52 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
    53 
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // Debug
       
    58 // Generates a log file if c:\logs\epos\ folder exists
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C void Debug( TRefByValue<const TDesC> aText, ... )
       
    62     {    
       
    63     VA_LIST args;
       
    64     VA_START( args, aText );
       
    65     
       
    66     TBuf<KEvtLogLineLength> buf;
       
    67     buf.FormatList( aText, args );
       
    68 
       
    69     #ifdef _DEBUG
       
    70     RDebug::Print(buf);
       
    71     #endif
       
    72 
       
    73 	RProcess currentProcess;
       
    74 	TParse parser;
       
    75 	TBuf<KEvtLogFileLength> name;
       
    76 	
       
    77 	parser.Set( currentProcess.FileName(), NULL, NULL );
       
    78 	TPtrC filename( parser.Name() );
       
    79 	
       
    80 	if( !filename.Compare( KEvtLogAppFileName() ) )
       
    81 		name.Format(KEvtLogFileName(), &filename);
       
    82 	else
       
    83 		name.Format(KEvtLogFileName(), &KEvtLogHanlderFileName() );
       
    84 	
       
    85     RFileLogger logger;
       
    86     
       
    87     TInt ret=logger.Connect();
       
    88     if (ret==KErrNone)
       
    89         {
       
    90         logger.SetDateAndTime( EFalse,EFalse );
       
    91         logger.CreateLog( KEvtLogFolder, name, EFileLoggingModeAppend );       
       
    92         TBuf<KEvtLogTimeFormatLength> timeStamp;
       
    93         TTime now;
       
    94         now.HomeTime();
       
    95         TDateTime dateTime;
       
    96         dateTime = now.DateTime();
       
    97         timeStamp.Format( KEvtLogTimeFormat, 
       
    98             dateTime.Hour(), dateTime.Minute(),
       
    99             dateTime.Second(), dateTime.MicroSecond() );
       
   100         buf.Insert( 0, timeStamp );
       
   101 
       
   102         logger.Write(buf);
       
   103         }
       
   104 
       
   105     logger.Close();
       
   106 
       
   107     VA_END( args );
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // CreateDir
       
   112 // Create a log Directory
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C void CreateDir()
       
   116 	{
       
   117 	_LIT( KEvtLogFolderPath, "C:\\logs\\epos\\" );
       
   118     RFs fsSession;
       
   119 	TRAP_IGNORE(fsSession.Connect());
       
   120 	if(!BaflUtils::FolderExists(fsSession, KEvtLogFolderPath()))
       
   121 		{
       
   122 		fsSession.MkDir( KEvtLogFolderPath() );
       
   123 		}
       
   124     fsSession.Close();
       
   125 	}
       
   126 	
       
   127 //  End of File