videditor/VideoEditorCommon/inc/logfile.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __LOGFILE_H__
       
    22 #define __LOGFILE_H__
       
    23 
       
    24 #include <eikapp.h>
       
    25 #include <e32base.h>
       
    26 #include <coemain.h>
       
    27 
       
    28 // Link with the following libraries: EFSRV.LIB HAL.LIB CHARCONV.LIB           
       
    29 
       
    30 #define LOG_INIT(name) CLogFile *log = CLogFile::NewL(_L(name), ETrue);
       
    31 
       
    32 #define LOG_INIT2(name) CLogFile *log = CLogFile::NewL(_L(name), EFalse);
       
    33 
       
    34 #define LOGL(event) \
       
    35 	log->Log(_L(event));\
       
    36 	log->LogNewline();
       
    37 
       
    38 #define LOGNLN(event) \
       
    39 	log->Log(_L(event));\
       
    40 
       
    41 #define LOGS(event) \
       
    42 	log->Log(event);\
       
    43 	log->LogNewline();
       
    44 
       
    45 #define LOGN(num) \
       
    46 	TBuf<64> log_num;\
       
    47 	log_num.AppendNum(num); \
       
    48 	log->Log(log_num);\
       
    49 	log->LogNewline();
       
    50 
       
    51 #define LOGF(numf) \
       
    52 	TBuf<16> log_float;\
       
    53 	log_float.AppendNum(numf, TRealFormat());\
       
    54 	log->Log(log_float);\
       
    55 	log->LogNewline();
       
    56 
       
    57 #define LOGN2(text, num) \
       
    58 	TBuf<64> log_num;\
       
    59 	log_num.AppendNum(num);\
       
    60 	log->Log(_L(text));\
       
    61 	log->Log(log_num);\
       
    62 	log->LogNewline();
       
    63 
       
    64 #define LOGF2(text, numf) \
       
    65 	TBuf<16> log_float;\
       
    66 	log_float.AppendNum(numf, TRealFormat());\
       
    67 	log->Log(_L(text));\
       
    68 	log->Log(log_float);\
       
    69 	log->LogNewline();
       
    70 
       
    71 #define LOG_END \
       
    72 	delete log;\
       
    73 	log = 0;
       
    74 
       
    75 
       
    76 
       
    77 /*! 
       
    78   @class CLogFile
       
    79   
       
    80   @discussion Class to generate a text file containing logging information
       
    81   */
       
    82 NONSHARABLE_CLASS( CLogFile ) : public CBase
       
    83     {
       
    84 public:
       
    85 /*!
       
    86   @function NewL
       
    87    
       
    88   @discussion Create a CLogFile object
       
    89   @param aFileName the name of the file to create
       
    90   @param aInitialiseLog if true, and the log file already exists, previous
       
    91   contents will be deleted. If false, append to any existing contents
       
    92   @result a pointer to the created instance of CLogFile
       
    93   */
       
    94     IMPORT_C static CLogFile* NewL(const TDesC& aFileName, TBool aInitialiseLog);
       
    95 
       
    96 /*!
       
    97   @function NewLC
       
    98    
       
    99   @discussion Create a CLogFile object
       
   100   @param aFileName the name of the file to create
       
   101   @param aInitialiseLog if true, and the log file already exists, previous
       
   102   contents will be deleted. If false, append to any existing contents
       
   103   @result a pointer to the created instance of CLogFile
       
   104   */
       
   105     IMPORT_C static CLogFile* NewLC(const TDesC& aFileName, TBool aInitialiseLog);
       
   106 
       
   107 /*!
       
   108   @function ~CLogFile
       
   109   
       
   110   @discussion Destroy the object and release all memory objects
       
   111   */
       
   112     IMPORT_C ~CLogFile();
       
   113 
       
   114 /*!
       
   115   @function Log
       
   116   
       
   117   @discussion Append the byte to the log file (if not a printable char, it will be logged as ascii-hex)
       
   118   @param aByte the byte to log
       
   119   */
       
   120     IMPORT_C void Log(TUint8 aByte);
       
   121 
       
   122 /*!
       
   123   @function Log
       
   124   
       
   125   @discussion Append the integer to the log file (logged as ascii-hex)
       
   126   @param aNumber the integer to log
       
   127   */
       
   128     IMPORT_C void Log(TUint aNumber);
       
   129 
       
   130 /*!
       
   131   @function Log
       
   132   
       
   133   @discussion Append text to the log file
       
   134   @param aText the text to log
       
   135   */
       
   136     IMPORT_C void Log(const TDesC8& aText);
       
   137 
       
   138 /*!
       
   139   @function Log
       
   140   
       
   141   @discussion Append text to the log file
       
   142   @param aText the text to log
       
   143   */
       
   144     IMPORT_C void Log(const TDesC& aText);
       
   145 
       
   146 /*!
       
   147   @function LogTime
       
   148   
       
   149   @discussion Append a timestamp to the log file.
       
   150   Timestamps are in seconds with three decimal places (but resolution is limited to system timer tick period)
       
   151   */
       
   152     IMPORT_C void LogTime();
       
   153 
       
   154 /*!
       
   155   @function LogBytes
       
   156 
       
   157   @discussion Append the bytes to the log file (non-printable bytes will be logged as ascii-hex)
       
   158   @param aBuffer the bytes to log
       
   159   */
       
   160     IMPORT_C void LogBytes(const TDesC8& aBuffer);
       
   161 
       
   162 /*!
       
   163   @function LogNewline
       
   164 
       
   165   @discussion Start a newline in the log file
       
   166   */
       
   167     IMPORT_C void LogNewline();
       
   168 
       
   169 /*!
       
   170   @function SetAutoFlush
       
   171 
       
   172   @discussion Turn AutoFlush on or off. AutoFlush will automatically flush the log file after each write
       
   173   @param aOn if true turns AutoFlush on
       
   174   */
       
   175     IMPORT_C void SetAutoFlush(TBool aOn);
       
   176 
       
   177 /*!
       
   178   @function SetAutoTimeStamp
       
   179 
       
   180   @discussion Turn AutoTimeStamp on or off. AutoTimeStamp will add a timestamp to the start of each new line in the log
       
   181   @param aOn if true turn AutoTimeStamp on
       
   182   */
       
   183     IMPORT_C void SetAutoTimeStamp(TBool aOn);
       
   184 
       
   185 /*!
       
   186   @function SetAutoNewline
       
   187 
       
   188   @discussion Turn AutoNewline on or off. AutoNewline starts a new line after each log operation
       
   189   @param aOn if true turn AutoNewline on
       
   190   */
       
   191     IMPORT_C void SetAutoNewline(TBool aOn);
       
   192 
       
   193 /*!
       
   194   @function StaticLogL
       
   195 
       
   196   @discussion Static option to append text to the log file (leaving version)
       
   197   @param aFileName the file to append to
       
   198   @param aText the text to append
       
   199   */
       
   200     IMPORT_C static void StaticLogL(const TDesC& aFileName, const TDesC8& aText);
       
   201 
       
   202 /*!
       
   203   @function StaticLogL
       
   204 
       
   205   @discussion Static option to append text to the log file (leaving version)
       
   206   @param aFileName the file to append to
       
   207   @param aText the text to append
       
   208   */
       
   209     IMPORT_C static void StaticLogL(const TDesC& aFileName, const TDesC& aText);
       
   210 
       
   211 /*!
       
   212   @function StaticLog
       
   213 
       
   214   @discussion Static option to append text to the log file (non-leaving version)
       
   215   @param aFileName the file to append to
       
   216   @param aText the text to append
       
   217   */
       
   218     IMPORT_C static void StaticLog(const TDesC& aFileName, const TDesC8& aText);
       
   219 
       
   220 /*!
       
   221   @function StaticLog
       
   222 
       
   223   @discussion Static option to append text to the log file (non-leaving version)
       
   224   @param aFileName the file to append to
       
   225   @param aText the text to append
       
   226   */
       
   227     IMPORT_C static void StaticLog(const TDesC& aFileName, const TDesC& aText);
       
   228 
       
   229 /*!
       
   230   @function FileName
       
   231 
       
   232   @discussion Get the file name and path of the file we are writing to
       
   233   @param aFileName
       
   234   */
       
   235     void GetFileName( TDes& aFileName ) const;
       
   236 
       
   237 private:
       
   238 /*!
       
   239   @function CLogFile
       
   240   
       
   241   @discussion Perform the first phase of two phase construction 
       
   242   */
       
   243     CLogFile();
       
   244 /*!
       
   245   @function ConstructL
       
   246   
       
   247   @discussion  Perform the second phase construction of a CLogFile object
       
   248   @param aFileName the file to open
       
   249   @param aInitialiseLog if true, and the log file already exists, previous
       
   250   contents will be deleted. If false, append to any existing contents
       
   251   */
       
   252     void ConstructL(const TDesC& aFileName, TBool aInitialiseLog);
       
   253 /*!
       
   254   @function LogTimeInternal
       
   255 
       
   256   @discussion Internal function to log time
       
   257   */
       
   258     void LogTimeInternal();
       
   259 /*!
       
   260   @function LogTextInternal
       
   261 
       
   262   @discussion Internal function to log text
       
   263   @param aText the text to log
       
   264   */
       
   265     void LogTextInternal(const TDesC8& aText);
       
   266 /*!
       
   267   @function LogByteInternal
       
   268 
       
   269   @discussion internal function to log a byte
       
   270   @param aByte the byte to log
       
   271   */
       
   272     void LogByteInternal(TUint8 aByte);
       
   273 /*!
       
   274   @function LogIntInternal
       
   275 
       
   276   @discussion Internal function to log an integer
       
   277   @param aNumber the integer to log
       
   278   */
       
   279     void LogIntInternal(TUint aNumber);
       
   280 /*!
       
   281   @function StartWrite
       
   282 
       
   283   @discussion Perform any initial operation before the main log operation
       
   284   */
       
   285     void StartWrite();
       
   286 
       
   287 /*!
       
   288   @function EndWrite
       
   289 
       
   290   @discussion Perform any tidying up operations after the main log operation
       
   291   */
       
   292     void EndWrite();
       
   293 
       
   294 /*!
       
   295   @function Write
       
   296 
       
   297   @discussion Do the actual writing, and associated error checking
       
   298   @param aText the text to write
       
   299   */
       
   300     void Write(const TDesC8& aText);
       
   301 
       
   302 /*!
       
   303   @function DoLogTextL
       
   304 
       
   305   @discussion Leaving functions from void Log(const TDesC& aText)
       
   306   */
       
   307     void DoLogTextL(const TDesC& aText);
       
   308 
       
   309 private:
       
   310 /*!
       
   311   @var iLogFile handle to the log file
       
   312   */
       
   313     RFile       iLogFile;
       
   314 
       
   315 /*!
       
   316   @var iSession file server session
       
   317   */
       
   318     RFs         iSession;
       
   319 
       
   320 /*!
       
   321   @var iLogMillisecsPerTick number of millisecs per system timer tick
       
   322   */
       
   323     TInt        iLogMillisecsPerTick;
       
   324 
       
   325 /*!
       
   326   @var iAutoFlush flag - AutoFlush on
       
   327   */
       
   328     TBool       iAutoFlush;
       
   329 
       
   330 /*!
       
   331   @var iAutoTimestamp flag - AutoTimeStamp on
       
   332   */
       
   333     TBool       iAutoTimestamp;
       
   334 
       
   335 /*!
       
   336   @var iAutoNewline flag - AutoNewline on
       
   337   */
       
   338     TBool       iAutoNewline;
       
   339 
       
   340 /*!
       
   341   @var iCheckNestDepth internal to check StartWrite and EndWrite have been called correctly
       
   342   */
       
   343     TInt        iCheckNestDepth;
       
   344 
       
   345     };
       
   346 
       
   347 #endif // __LOGFILE_H__