XDMEngine/src/XdmLogWriter.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     1 /*
       
     2 * Copyright (c) 2007 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:   XDM Engine log writer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <f32file.h>
       
    21 #include <flogger.h>
       
    22 #include <e32debug.h>
       
    23 #include "XdmLogWriter.h"
       
    24 #include "XdmStaticUtils.h"
       
    25 
       
    26 
       
    27 // ----------------------------------------------------------
       
    28 // XdmStaticUtils::CheckFileExistsL
       
    29 // 
       
    30 // ----------------------------------------------------------
       
    31 //
       
    32 CXdmLogWriter::CXdmLogWriter()
       
    33     {         
       
    34     }
       
    35 
       
    36 // ----------------------------------------------------------
       
    37 // CXdmLogWriter::NewL
       
    38 // 
       
    39 // ----------------------------------------------------------
       
    40 //      
       
    41 EXPORT_C CXdmLogWriter* CXdmLogWriter::NewL( const TDesC& aLogName )
       
    42     {
       
    43     CXdmLogWriter* self = new ( ELeave ) CXdmLogWriter();
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL( aLogName );
       
    46     CleanupStack::Pop();
       
    47     return self;        
       
    48     }
       
    49 
       
    50 // ----------------------------------------------------------
       
    51 // CXdmLogWriter::ConstructL
       
    52 // 
       
    53 // ----------------------------------------------------------
       
    54 //
       
    55 void CXdmLogWriter::ConstructL( const TDesC& aLogName )
       
    56     {
       
    57     RFs session;
       
    58     HBufC* full = NULL;
       
    59     User::LeaveIfError( session.Connect() );
       
    60     CleanupClosePushL( session );
       
    61     HBufC* concat = HBufC::NewLC( KXdmLogRoot().Length() + 
       
    62                                   KXdmLogDir().Length()  +
       
    63                                   aLogName.Length() + 1 );
       
    64     TPtr path( concat->Des() );
       
    65     path.Copy( KXdmLogRoot ); 
       
    66     path.Append( KXdmLogDir );
       
    67     path.Append( _L( "\\") );
       
    68     path.Append( aLogName );
       
    69     TRAPD( error, full = XdmStaticUtils::GenerateFileNameL( session, path, KXdmLogFileExt ) );
       
    70     if( full && error == KErrNone )
       
    71     	{
       
    72     	CleanupStack::PushL( full );
       
    73     	TPtrC fullDes( full->Des() );
       
    74     	iLogFileName = fullDes.Mid( fullDes.LocateReverse( 92 ) + 1 ).AllocL();
       
    75     	CleanupStack::PopAndDestroy();  //full
       
    76     	}
       
    77    	else iLogFileName = NULL;
       
    78     CleanupStack::PopAndDestroy( 2 );  //concat, session 
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------
       
    82 // CXdmLogWriter::~CXdmLogWriter
       
    83 // 
       
    84 // ----------------------------------------------------------
       
    85 //     
       
    86 CXdmLogWriter::~CXdmLogWriter()
       
    87     {
       
    88     delete iLogFileName;
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------
       
    92 // CXdmLogWriter::WriteToLog
       
    93 // 
       
    94 // ----------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CXdmLogWriter::WriteToLog( const TDesC& aLogLine ) const
       
    97     {
       
    98     if( iLogFileName )
       
    99     	{
       
   100     	RFileLogger::Write( KXdmLogDir, *iLogFileName, EFileLoggingModeAppend, aLogLine ); 
       
   101     	}
       
   102 	RDebug::Print( aLogLine );
       
   103     }
       
   104      
       
   105 // ----------------------------------------------------------
       
   106 // CXdmLogWriter::WriteToLog
       
   107 // 
       
   108 // ----------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CXdmLogWriter::WriteToLog( const TDesC8& aLogLine ) const
       
   111     {
       
   112     if( iLogFileName )
       
   113     	{
       
   114     	RFileLogger::Write( KXdmLogDir, *iLogFileName, EFileLoggingModeAppend, aLogLine );
       
   115     	}
       
   116 	RDebug::RawPrint( aLogLine );
       
   117     }
       
   118     
       
   119 // End of File
       
   120 
       
   121 
       
   122 
       
   123