stif/Logger/src/TxtLogger.cpp
changeset 0 a03f92240627
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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: This module contains implementation of CTxtLogger 
       
    15 * class member functions
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include "TxtLogger.h"
       
    22 #include "Output.h"
       
    23 #include "LoggerTracing.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 // None
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 // None
       
    30 
       
    31 // CONSTANTS
       
    32 // None
       
    33 
       
    34 // MACROS
       
    35 // None
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 // None
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 // None
       
    42 
       
    43 // LOCAL FUNCTION PROTOTYPES
       
    44 // None
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 // None
       
    48 
       
    49 // ==================== LOCAL FUNCTIONS =======================================
       
    50 // None
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =========================================
       
    53 
       
    54 /*
       
    55 -------------------------------------------------------------------------------
       
    56 
       
    57     Class: CTxtLogger
       
    58 
       
    59     Method: CTxtLogger
       
    60 
       
    61     Description: Default constructor
       
    62 
       
    63     C++ default constructor can NOT contain any code, that
       
    64     might leave.
       
    65 
       
    66     Parameters: COutput* output: in: Output source
       
    67 
       
    68     Return Values: None
       
    69 
       
    70     Errors/Exceptions: None
       
    71 
       
    72     Status: Approved
       
    73 
       
    74 -------------------------------------------------------------------------------
       
    75 */
       
    76 CTxtLogger::CTxtLogger( COutput* output )
       
    77     {
       
    78     
       
    79     iOutput = output;
       
    80 
       
    81     }
       
    82 
       
    83 /*
       
    84 -------------------------------------------------------------------------------
       
    85 
       
    86     Class: CTxtLogger
       
    87 
       
    88     Method: ConstructL
       
    89 
       
    90     Description: Symbian OS second phase constructor
       
    91 
       
    92     Symbian OS default constructor can leave.
       
    93 
       
    94     Parameters: None
       
    95 
       
    96     Return Values: None
       
    97 
       
    98     Errors/Exceptions: None
       
    99 
       
   100     Status: Approved
       
   101 
       
   102 -------------------------------------------------------------------------------
       
   103 */
       
   104 void CTxtLogger::ConstructL()
       
   105     {
       
   106 
       
   107     }
       
   108 
       
   109 /*
       
   110 -------------------------------------------------------------------------------
       
   111 
       
   112     Class: CTxtLogger
       
   113 
       
   114     Method: NewL
       
   115 
       
   116     Description: Two-phased constructor.
       
   117 
       
   118     Parameters: const TDesC& aTestPath: in: Log path
       
   119                 const TDesC& aTestFile: in: Log filename
       
   120                 TLoggerType aLoggerType: in: File type
       
   121                 TOutput aOutput: in: Output source
       
   122                 TBool aOverWrite: in: For file overwrite
       
   123                 TBool aWithTimeStamp: in: For timestamp
       
   124                 TBool aWithLineBreak: in: For line break
       
   125                 TBool aWithEventRanking: in: For events ranking to file
       
   126                 TBool aThreadIdToLogFile: in: Indicator to thread id adding to
       
   127                                               end of the log file
       
   128                 TBool aCreateLogDir: in: Indicator to directory creation
       
   129                 TInt  aStaticBufferSize
       
   130                 TBool aUnicode: in: Indicator if file has to be in unicode format
       
   131 
       
   132     Return Values: CTxtLogger*: pointer to CTxtLogger object
       
   133 
       
   134     Errors/Exceptions: Leaves if called COutput::NewL method fails
       
   135 
       
   136     Status: Proposal
       
   137 
       
   138 -------------------------------------------------------------------------------
       
   139 */
       
   140 CTxtLogger* CTxtLogger::NewL( const TDesC& aTestPath, 
       
   141                                 const TDesC& aTestFile,
       
   142                                 TLoggerType aLoggerType,
       
   143                                 TOutput aOutput,
       
   144                                 TBool aOverWrite,
       
   145                                 TBool aWithTimeStamp,
       
   146                                 TBool aWithLineBreak,
       
   147                                 TBool aWithEventRanking,
       
   148                                 TBool aThreadIdToLogFile,
       
   149                                 TBool aCreateLogDir,
       
   150                                 TInt aStaticBufferSize,
       
   151                                 TBool aUnicode )
       
   152     {
       
   153     __TRACE( KInfo, ( _L( "STIFLOGGER: Creating txt logger" ) ) );
       
   154 
       
   155     // Create COutput object output
       
   156     COutput* output = COutput::NewL( aTestPath,
       
   157                                         aTestFile,
       
   158                                         aLoggerType,
       
   159                                         aOutput,
       
   160                                         aOverWrite,
       
   161                                         aWithTimeStamp,
       
   162                                         aWithLineBreak,
       
   163                                         aWithEventRanking,
       
   164                                         aThreadIdToLogFile,
       
   165                                         aCreateLogDir,
       
   166                                         aStaticBufferSize,
       
   167                                         aUnicode );
       
   168 
       
   169     CleanupStack::PushL( output );
       
   170     __ASSERT_ALWAYS( output != NULL, User::Leave( KErrNotFound ) );
       
   171     // Create CTxtLogger object txtLogger and bind to COutput
       
   172     CTxtLogger* txtLogger = new (ELeave) CTxtLogger( output );
       
   173     // TXT logger owns output object and it will be destroyed in STIFLogger
       
   174     // destructor.
       
   175     CleanupStack::Pop( output );
       
   176     
       
   177     CleanupStack::PushL( txtLogger );
       
   178     txtLogger->ConstructL();
       
   179     CleanupStack::Pop( txtLogger );
       
   180     
       
   181     
       
   182     return txtLogger;
       
   183 
       
   184     }
       
   185 
       
   186 /*
       
   187 -------------------------------------------------------------------------------
       
   188 
       
   189     Class: CTxtLogger
       
   190 
       
   191     Method: ~CTxtLogger
       
   192 
       
   193     Description: Destructor
       
   194 
       
   195     Parameters: None
       
   196 
       
   197     Return Values: None
       
   198 
       
   199     Errors/Exceptions: None
       
   200 
       
   201     Status: Approved
       
   202 
       
   203 -------------------------------------------------------------------------------
       
   204 */
       
   205 CTxtLogger::~CTxtLogger()
       
   206     {
       
   207     }
       
   208 
       
   209 /*
       
   210 -------------------------------------------------------------------------------
       
   211 
       
   212     Class: CTxtLogger
       
   213 
       
   214     Method: Send
       
   215 
       
   216     Description: Send style information and 16 bit data to the output module.
       
   217 
       
   218     Parameters: TInt TStyle: in: Text forming
       
   219                 const TDesC& aData: in: Data to be logged
       
   220 
       
   221     Return Values: TInt: Symbian error code.
       
   222 
       
   223     Errors/Exceptions: None
       
   224 
       
   225     Status: Approved
       
   226 
       
   227 -------------------------------------------------------------------------------
       
   228 */
       
   229 TInt CTxtLogger::Send( TInt aStyle, const TDesC& aData )
       
   230     {
       
   231     // Time stamp indicator
       
   232     TBool timestamp( ETrue );
       
   233     // Event ranking indicator
       
   234     TBool eventranking( ETrue );
       
   235 
       
   236     // Only EError, EWarning and EImportant styles are supporter in txt logging
       
   237     if ( 0x00100 <= aStyle )    // EError, 0x00100 => 256
       
   238         {
       
   239         iOutput->Write( timestamp, EFalse, eventranking, _L( "ERROR    " ) );
       
   240         aStyle -= 0x00100;
       
   241         timestamp = EFalse;     // Time stamp added no time stamp to the
       
   242                                 // forward operations
       
   243         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   244                                 // forward operations
       
   245         }
       
   246     if ( 0x00080 <= aStyle )    // EWarning, 0x00080 => 128
       
   247         {
       
   248         iOutput->Write( timestamp, EFalse, eventranking,
       
   249                                                     _L( "WARNING    " ) );
       
   250         aStyle -= 0x00080;
       
   251         timestamp = EFalse;     // Time stamp added no time stamp to the 
       
   252                                 // forward operations
       
   253         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   254                                 // forward operations
       
   255         }
       
   256     if ( 0x00040 <= aStyle )    // EImportant, 0x00040 => 64
       
   257         {
       
   258         iOutput->Write( timestamp, EFalse, eventranking,
       
   259                                                     _L( "IMPORTANT    " ) );
       
   260         aStyle -= 0x00040;
       
   261         timestamp = EFalse;     // Time stamp added no time stamp to the 
       
   262                                 // forward operations
       
   263         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   264                                 // forward operations
       
   265         }
       
   266 
       
   267     return iOutput->Write( timestamp, ETrue, eventranking, aData );
       
   268 
       
   269     }
       
   270 
       
   271 /*
       
   272 -------------------------------------------------------------------------------
       
   273 
       
   274     Class: CTxtLogger
       
   275 
       
   276     Method: Send
       
   277 
       
   278     Description: Send style information and 8 bit data to the output module.
       
   279 
       
   280     Parameters: TInt TStyle: in: Text forming
       
   281                 const TDesC8& aData: in: Data to be logged
       
   282 
       
   283     Return Values: TInt: Symbian error code.
       
   284 
       
   285     Errors/Exceptions: None
       
   286 
       
   287     Status: Approved
       
   288 
       
   289 -------------------------------------------------------------------------------
       
   290 */
       
   291 TInt CTxtLogger::Send( TInt aStyle, const TDesC8& aData )
       
   292     {
       
   293     // Time stamp indicator
       
   294     TBool timestamp( ETrue );
       
   295     // Event ranking indicator
       
   296     TBool eventranking( ETrue );
       
   297 
       
   298     // Only EError, EWarning and EImportant styles are supporter in txt logging
       
   299     if ( 0x00100 <= aStyle )    // EError, 0x00100 => 256
       
   300         {
       
   301         iOutput->Write( timestamp, EFalse, eventranking, _L8( "ERROR    " ) );
       
   302         aStyle -= 0x00100;
       
   303         timestamp = EFalse;     // Time stamp added no time stamp to the
       
   304                                 // forward operations
       
   305         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   306                                 // forward operations
       
   307         }
       
   308     if ( 0x00080 <= aStyle )    // EWarning, 0x00080 => 128
       
   309         {
       
   310         iOutput->Write( timestamp, EFalse, eventranking,
       
   311                                                     _L8( "WARNING    " ) );
       
   312         aStyle -= 0x00080;
       
   313         timestamp = EFalse;     // Time stamp added no time stamp to the 
       
   314                                 // forward operations
       
   315         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   316                                 // forward operations
       
   317         }
       
   318     if ( 0x00040 <= aStyle )    // EImportant, 0x00040 => 64
       
   319         {
       
   320         iOutput->Write( timestamp, EFalse, eventranking,
       
   321                                                     _L8( "IMPORTANT    " ) );
       
   322         aStyle -= 0x00040;
       
   323         timestamp = EFalse;     // Time stamp added no time stamp to the 
       
   324                                 // forward operations
       
   325         eventranking = EFalse;  // Event ranking added no event ranking to the
       
   326                                 // forward operations
       
   327         }
       
   328 
       
   329     return iOutput->Write( timestamp, ETrue, eventranking, aData );
       
   330 
       
   331     }
       
   332 
       
   333 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   334 // None
       
   335 
       
   336 // End of File