testexecfw/stf/stffw/logger/STFLoggingServer/src/TxtLogger.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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     //Nothing to do.
       
   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, const TDesC& aTestFile,
       
   141         CStifLogger::TLoggerType aLoggerType, CStifLogger::TOutput aOutput,
       
   142         TBool aOverWrite, TBool aWithTimeStamp, TBool aWithLineBreak,
       
   143         TBool aWithEventRanking, TBool aThreadIdToLogFile,
       
   144         TBool aCreateLogDir, TInt aStaticBufferSize, TBool aUnicode, TInt aThreadId)
       
   145     {
       
   146     __TRACE( KInfo, ( _L( "STIFLOGGER: Creating txt logger" ) ) );
       
   147 
       
   148     // Create COutput object output
       
   149     COutput* output = COutput::NewL(aTestPath, aTestFile, aLoggerType,
       
   150             aOutput, aOverWrite, aWithTimeStamp, aWithLineBreak,
       
   151             aWithEventRanking, aThreadIdToLogFile, aCreateLogDir,
       
   152             aStaticBufferSize, aUnicode, aThreadId);
       
   153 
       
   154     CleanupStack::PushL(output);
       
   155     __ASSERT_ALWAYS( output != NULL, User::Leave( KErrNotFound ) );
       
   156     // Create CTxtLogger object txtLogger and bind to COutput
       
   157     CTxtLogger* txtLogger = new (ELeave) CTxtLogger(output);
       
   158     // TXT logger owns output object and it will be destroyed in STIFLogger
       
   159     // destructor.
       
   160     CleanupStack::Pop(output);
       
   161 
       
   162     CleanupStack::PushL(txtLogger);
       
   163     txtLogger->ConstructL();
       
   164     CleanupStack::Pop(txtLogger);
       
   165 
       
   166     return txtLogger;
       
   167 
       
   168     }
       
   169 
       
   170 /*
       
   171  -------------------------------------------------------------------------------
       
   172 
       
   173  Class: CTxtLogger
       
   174 
       
   175  Method: ~CTxtLogger
       
   176 
       
   177  Description: Destructor
       
   178 
       
   179  Parameters: None
       
   180 
       
   181  Return Values: None
       
   182 
       
   183  Errors/Exceptions: None
       
   184 
       
   185  Status: Approved
       
   186 
       
   187  -------------------------------------------------------------------------------
       
   188  */
       
   189 CTxtLogger::~CTxtLogger()
       
   190     {
       
   191     }
       
   192 
       
   193 /*
       
   194  -------------------------------------------------------------------------------
       
   195 
       
   196  Class: CTxtLogger
       
   197 
       
   198  Method: Send
       
   199 
       
   200  Description: Send style information and 16 bit data to the output module.
       
   201 
       
   202  Parameters: TInt TStyle: in: Text forming
       
   203  const TDesC& aData: in: Data to be logged
       
   204 
       
   205  Return Values: TInt: Symbian error code.
       
   206 
       
   207  Errors/Exceptions: None
       
   208 
       
   209  Status: Approved
       
   210 
       
   211  -------------------------------------------------------------------------------
       
   212  */
       
   213 TInt CTxtLogger::Send(TInt aStyle, const TDesC& aData)
       
   214     {
       
   215     // Time stamp indicator
       
   216     TBool timestamp(ETrue);
       
   217     // Event ranking indicator
       
   218     TBool eventranking(ETrue);
       
   219 
       
   220     // Only EError, EWarning and EImportant styles are supporter in txt logging
       
   221     if (0x00100 <= aStyle) // EError, 0x00100 => 256
       
   222         {
       
   223         iOutput->Write(timestamp, EFalse, eventranking, _L( "ERROR    " ));
       
   224         aStyle -= 0x00100;
       
   225         timestamp = EFalse; // Time stamp added no time stamp to the
       
   226         // forward operations
       
   227         eventranking = EFalse; // Event ranking added no event ranking to the
       
   228         // forward operations
       
   229         }
       
   230     if (0x00080 <= aStyle) // EWarning, 0x00080 => 128
       
   231         {
       
   232         iOutput->Write(timestamp, EFalse, eventranking, _L( "WARNING    " ));
       
   233         aStyle -= 0x00080;
       
   234         timestamp = EFalse; // Time stamp added no time stamp to the 
       
   235         // forward operations
       
   236         eventranking = EFalse; // Event ranking added no event ranking to the
       
   237         // forward operations
       
   238         }
       
   239     if (0x00040 <= aStyle) // EImportant, 0x00040 => 64
       
   240         {
       
   241         iOutput->Write(timestamp, EFalse, eventranking, _L( "IMPORTANT    " ));
       
   242         aStyle -= 0x00040;
       
   243         timestamp = EFalse; // Time stamp added no time stamp to the 
       
   244         // forward operations
       
   245         eventranking = EFalse; // Event ranking added no event ranking to the
       
   246         // forward operations
       
   247         }
       
   248 
       
   249     return iOutput->Write(timestamp, ETrue, eventranking, aData);
       
   250 
       
   251     }
       
   252 
       
   253 /*
       
   254  -------------------------------------------------------------------------------
       
   255 
       
   256  Class: CTxtLogger
       
   257 
       
   258  Method: Send
       
   259 
       
   260  Description: Send style information and 8 bit data to the output module.
       
   261 
       
   262  Parameters: TInt TStyle: in: Text forming
       
   263  const TDesC8& aData: in: Data to be logged
       
   264 
       
   265  Return Values: TInt: Symbian error code.
       
   266 
       
   267  Errors/Exceptions: None
       
   268 
       
   269  Status: Approved
       
   270 
       
   271  -------------------------------------------------------------------------------
       
   272  */
       
   273 TInt CTxtLogger::Send(TInt aStyle, const TDesC8& aData)
       
   274     {
       
   275     // Time stamp indicator
       
   276     TBool timestamp(ETrue);
       
   277     // Event ranking indicator
       
   278     TBool eventranking(ETrue);
       
   279 
       
   280     // Only EError, EWarning and EImportant styles are supporter in txt logging
       
   281     if (0x00100 <= aStyle) // EError, 0x00100 => 256
       
   282         {
       
   283         iOutput->Write(timestamp, EFalse, eventranking, _L8( "ERROR    " ));
       
   284         aStyle -= 0x00100;
       
   285         timestamp = EFalse; // Time stamp added no time stamp to the
       
   286         // forward operations
       
   287         eventranking = EFalse; // Event ranking added no event ranking to the
       
   288         // forward operations
       
   289         }
       
   290     if (0x00080 <= aStyle) // EWarning, 0x00080 => 128
       
   291         {
       
   292         iOutput->Write(timestamp, EFalse, eventranking, _L8( "WARNING    " ));
       
   293         aStyle -= 0x00080;
       
   294         timestamp = EFalse; // Time stamp added no time stamp to the 
       
   295         // forward operations
       
   296         eventranking = EFalse; // Event ranking added no event ranking to the
       
   297         // forward operations
       
   298         }
       
   299     if (0x00040 <= aStyle) // EImportant, 0x00040 => 64
       
   300         {
       
   301         iOutput->Write(timestamp, EFalse, eventranking, _L8( "IMPORTANT    " ));
       
   302         aStyle -= 0x00040;
       
   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 
       
   309     return iOutput->Write(timestamp, ETrue, eventranking, aData);
       
   310 
       
   311     }
       
   312 
       
   313 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   314 // None
       
   315 
       
   316 // End of File