videditor/VideoEditorCommon/inc/VideoEditorDebugUtils.h
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     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 // Simple RFileLogger based set of log writer macros.
       
    21 //
       
    22 // Instructions:
       
    23 //
       
    24 // 1. Put the following line into you MMP file
       
    25 // LIBRARY flogger.lib
       
    26 //
       
    27 // 2. Define DEBUG_ON to enable logs in UDEB builds.
       
    28 //    Alternatively, define DEBUG_ON_ALWAYS to enable logs 
       
    29 //    always (NOTE: do not use in productions code)
       
    30 //    - in mmp file: macro DEBUG_ON
       
    31 //    - in cpp file: #define DEBUG_ON
       
    32 // 
       
    33 // 3a. Call LOG_RESET to create the log file, overwriting possibly
       
    34 //    existing old log file.
       
    35 //
       
    36 // 3b. Alternatively, you can skip the step 3a, in which case the 
       
    37 //    the output is appended to the possibly existing old file.
       
    38 //
       
    39 // 4. Use the macros to write to the log file. For example
       
    40 //    LOG("Started processing")
       
    41 // 
       
    42 // 5. To enable the logs, manually create the logging 
       
    43 //    directory "C:\Logs\VideoEditor" on the device.
       
    44 //
       
    45 
       
    46 #ifndef __DEBUGUTILS_H__
       
    47 #define __DEBUGUTILS_H__
       
    48 
       
    49 // Two alternative implementations:
       
    50 // - using RFileLogger (system component)
       
    51 // - using ClogFile (implemented in this project)
       
    52 //#define _FLOGGER_IMPLEMENTATION_
       
    53 #define _CLOGFILE_IMPLEMENTATION_
       
    54 
       
    55 #ifdef _FLOGGER_IMPLEMENTATION_
       
    56 #include <flogger.h>
       
    57 #else
       
    58 #include "logfile.h"
       
    59 #include <bautils.h>
       
    60 #include <f32file.h>
       
    61 #endif
       
    62 #include <e32svr.h>
       
    63 
       
    64 // Default log files
       
    65 _LIT(KVideoEditorLogFile,"VideoEditor.log");
       
    66 _LIT(KVideoProviderLogFile,"VideoProvider.log");
       
    67 
       
    68 // Log directory
       
    69 _LIT(KLogDir, "VideoEditor");
       
    70 
       
    71 // Maximum length for a log line. 
       
    72 const TInt KMaxLogLineLength = 256;
       
    73 
       
    74 // Overflow handler. Too log lines are truncated. 
       
    75 class TLogFileDes16OverflowHandler : public TDes16Overflow
       
    76 	{
       
    77 	virtual void Overflow(TDes16& /*aDes*/) 
       
    78 		{
       
    79 		// do nothing
       
    80 		}
       
    81 	};
       
    82 
       
    83 _LIT(KLogsFolder, "C:\\Logs\\");
       
    84 _LIT(KBackslash, "\\");
       
    85 
       
    86 
       
    87 // The log is enabled in debug builds only, unless
       
    88 // DEBUG_ON_ALWAYS is defined to always enable it.
       
    89 #ifdef _DEBUG
       
    90 	#ifdef DEBUG_ON
       
    91 	#define _ENABLED_
       
    92 	#endif
       
    93 #else
       
    94 	#ifdef DEBUG_ON_ALWAYS
       
    95 	#define _ENABLED_
       
    96 	#endif
       
    97 #endif
       
    98 
       
    99 #ifdef _ENABLED_
       
   100 
       
   101 #define DEBUGLOG_ARG(x) x
       
   102 
       
   103 #ifdef _FLOGGER_IMPLEMENTATION_ 
       
   104 
       
   105 // Initialize the log file, overwrite existing
       
   106 // Logs file are always created in C:\Logs. The first argument to CreateLog() 
       
   107 // is a directory name relative to this C:\Logs directory.
       
   108 #define LOG_RESET(aLogFile) \
       
   109 	{\
       
   110 	RFileLogger logger;\
       
   111 	logger.Connect();\
       
   112 	logger.CreateLog(KLogDir,aLogFile,EFileLoggingModeOverwrite);\
       
   113 	logger.Write(KLogDir,aLogFile,EFileLoggingModeAppend,_L("*** Log file created ***"));\
       
   114 	logger.CloseLog();\
       
   115 	logger.Close();\
       
   116 	}
       
   117 
       
   118 // Log a simple text, e.g.
       
   119 //   LOG(_L("logfile.txt"),"Something happens here")
       
   120 #define LOG(aLogFile,aText) \
       
   121 	{\
       
   122 	RFileLogger::Write(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText));\
       
   123 	RDebug::Print(_L(aText));\
       
   124 	}
       
   125 
       
   126 // Log a Descriptor
       
   127 #define LOGDES(aLogFile,aDes) \
       
   128 	{\
       
   129 	RFileLogger::Write(KLogDir,aLogFile,EFileLoggingModeAppend,aDes);\
       
   130 	RDebug::Print(aDes);\
       
   131 	}
       
   132 
       
   133 // Log a number with string format, e.g. 
       
   134 //	LOGFMT(KLogFile,"Result=%d",err)
       
   135 //	LOGFMT(KLogFile, "FileName: %S", &aFileName );
       
   136 #define LOGFMT(aLogFile,aText,aParam) \
       
   137 	{\
       
   138 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam);\
       
   139 	RDebug::Print(_L(aText), aParam);\
       
   140 	}
       
   141 
       
   142 // With 2 parameters
       
   143 #define LOGFMT2(aLogFile,aText,aParam1,aParam2) \
       
   144 	{\
       
   145 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2);\
       
   146 	RDebug::Print(_L(aText), aParam1,aParam2);\
       
   147 	}
       
   148 
       
   149 // With 3 parameters
       
   150 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3) \
       
   151 	{\
       
   152 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3);\
       
   153 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3);\
       
   154 	}
       
   155 
       
   156 // With 4 parameters
       
   157 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4) \
       
   158 	{\
       
   159 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3,aParam4);\
       
   160 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4);\
       
   161 	}
       
   162 
       
   163 // With 6 parameters
       
   164 #define LOGFMT6(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6) \
       
   165 	{\
       
   166 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3,aParam4,aParam5,aParam6);\
       
   167 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4,aParam5,aParam6);\
       
   168 	}
       
   169 
       
   170 // With 12 parameters
       
   171 #define LOGFMT12(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12) \
       
   172 	{\
       
   173 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3,aParam4);\
       
   174 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4,,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12);\
       
   175 	}
       
   176 
       
   177 // Log hex dump
       
   178 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen) \
       
   179 	RFileLogger::HexDump(KLogDir,aLogFile, EFileLoggingModeAppend, _S(aHeader), _S(aMargin), aPtr, aLen);
       
   180 
       
   181 // Log the memory allocated on the current thread's default heap
       
   182 #define LOG_HEAP_USAGE(aLogFile) \
       
   183 	{\
       
   184 	TInt allocSize;\
       
   185 	User::Heap().AllocSize(allocSize);\
       
   186 	_LIT(KText,"* Memory allocated on the thread's default heap: %d *");\
       
   187 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,KText,allocSize);\
       
   188 	RDebug::Print(KText,allocSize);\
       
   189 	}
       
   190 
       
   191 #endif // _FLOGGER_IMPLEMENTATION_
       
   192 
       
   193 #ifdef _CLOGFILE_IMPLEMENTATION_
       
   194 
       
   195 #define LOG_RESET(aLogFile) \
       
   196 	{\
       
   197 	TFileName path(KLogsFolder);\
       
   198 	path.Append(KLogDir);\
       
   199 	path.Append(KBackslash);\
       
   200 	TFileName fileNameAndPath(path);\
       
   201 	fileNameAndPath.Append(aLogFile);\
       
   202 	RFs fs;\
       
   203 	fs.Connect();\
       
   204 	if(BaflUtils::FolderExists(fs,path))\
       
   205 		{\
       
   206 		RFile file;\
       
   207 		file.Replace(fs, fileNameAndPath, EFileShareAny|EFileWrite);\
       
   208 		file.Close();\
       
   209 		CLogFile::StaticLog(fileNameAndPath,_L("*** Log file created ***\n"));\
       
   210 		}\
       
   211 	fs.Close();\
       
   212 	}
       
   213 
       
   214 #define LOG(aLogFile,aText) \
       
   215 	{\
       
   216 	TFileName path(KLogsFolder);\
       
   217 	path.Append(KLogDir);\
       
   218 	path.Append(KBackslash);\
       
   219 	TFileName fileNameAndPath(path);\
       
   220 	fileNameAndPath.Append(aLogFile);\
       
   221 	RFs fs;\
       
   222 	fs.Connect();\
       
   223 	if(BaflUtils::FolderExists(fs,path))\
       
   224 		{\
       
   225 		CLogFile::StaticLog(fileNameAndPath,_L(aText));\
       
   226 		}\
       
   227 	fs.Close();\
       
   228 	RDebug::Print(_L(aText));\
       
   229 	}
       
   230 
       
   231 #define LOGDES(aLogFile,aDes) \
       
   232 	{\
       
   233 	TFileName path(KLogsFolder);\
       
   234 	path.Append(KLogDir);\
       
   235 	path.Append(KBackslash);\
       
   236 	TFileName fileNameAndPath(path);\
       
   237 	fileNameAndPath.Append(aLogFile);\
       
   238 	RFs fs;\
       
   239 	fs.Connect();\
       
   240 	if(BaflUtils::FolderExists(fs,path))\
       
   241 		{\
       
   242 		CLogFile::StaticLog(fileNameAndPath,aDes);\
       
   243 		}\
       
   244 	fs.Close();\
       
   245 	RDebug::Print(aDes);\
       
   246 	}
       
   247 
       
   248 #define LOGFMT(aLogFile,aText,aParam) \
       
   249 	{\
       
   250 	TFileName path(KLogsFolder);\
       
   251 	path.Append(KLogDir);\
       
   252 	path.Append(KBackslash);\
       
   253 	TFileName fileNameAndPath(path);\
       
   254 	fileNameAndPath.Append(aLogFile);\
       
   255 	RFs fs;\
       
   256 	fs.Connect();\
       
   257 	if(BaflUtils::FolderExists(fs,path))\
       
   258 		{\
       
   259 		_LIT(KText,aText);\
       
   260 		TLogFileDes16OverflowHandler ofh;\
       
   261 		TBuf<KMaxLogLineLength> buf;\
       
   262 		buf.AppendFormat(KText,&ofh,aParam);\
       
   263 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   264 		}\
       
   265 	fs.Close();\
       
   266 	RDebug::Print(_L(aText), aParam);\
       
   267 	}
       
   268 
       
   269 // With 2 parameters
       
   270 #define LOGFMT2(aLogFile,aText,aParam1,aParam2) \
       
   271 	{\
       
   272 	TFileName path(KLogsFolder);\
       
   273 	path.Append(KLogDir);\
       
   274 	path.Append(KBackslash);\
       
   275 	TFileName fileNameAndPath(path);\
       
   276 	fileNameAndPath.Append(aLogFile);\
       
   277 	RFs fs;\
       
   278 	fs.Connect();\
       
   279 	if(BaflUtils::FolderExists(fs,path))\
       
   280 		{\
       
   281 		_LIT(KText,aText);\
       
   282 		TLogFileDes16OverflowHandler ofh;\
       
   283 		TBuf<KMaxLogLineLength> buf;\
       
   284 		buf.AppendFormat(KText,&ofh,aParam1,aParam2);\
       
   285 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   286 		}\
       
   287 	fs.Close();\
       
   288 	RDebug::Print(_L(aText), aParam1,aParam2);\
       
   289 	}
       
   290 
       
   291 // With 3 parameters
       
   292 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3) \
       
   293 	{\
       
   294 	TFileName path(KLogsFolder);\
       
   295 	path.Append(KLogDir);\
       
   296 	path.Append(KBackslash);\
       
   297 	TFileName fileNameAndPath(path);\
       
   298 	fileNameAndPath.Append(aLogFile);\
       
   299 	RFs fs;\
       
   300 	fs.Connect();\
       
   301 	if(BaflUtils::FolderExists(fs,path))\
       
   302 		{\
       
   303 		_LIT(KText,aText);\
       
   304 		TLogFileDes16OverflowHandler ofh;\
       
   305 		TBuf<KMaxLogLineLength> buf;\
       
   306 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3);\
       
   307 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   308 		}\
       
   309 	fs.Close();\
       
   310 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3);\
       
   311 	}
       
   312 
       
   313 // With 4 parameters
       
   314 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4) \
       
   315 	{\
       
   316 	TFileName path(KLogsFolder);\
       
   317 	path.Append(KLogDir);\
       
   318 	path.Append(KBackslash);\
       
   319 	TFileName fileNameAndPath(path);\
       
   320 	fileNameAndPath.Append(aLogFile);\
       
   321 	RFs fs;\
       
   322 	fs.Connect();\
       
   323 	if(BaflUtils::FolderExists(fs,path))\
       
   324 		{\
       
   325 		_LIT(KText,aText);\
       
   326 		TLogFileDes16OverflowHandler ofh;\
       
   327 		TBuf<KMaxLogLineLength> buf;\
       
   328 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3,aParam4);\
       
   329 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   330 		}\
       
   331 	fs.Close();\
       
   332 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4);\
       
   333 	}
       
   334 
       
   335 // With 6 parameters
       
   336 #define LOGFMT6(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6) \
       
   337 	{\
       
   338 	TFileName path(KLogsFolder);\
       
   339 	path.Append(KLogDir);\
       
   340 	path.Append(KBackslash);\
       
   341 	TFileName fileNameAndPath(path);\
       
   342 	fileNameAndPath.Append(aLogFile);\
       
   343 	RFs fs;\
       
   344 	fs.Connect();\
       
   345 	if(BaflUtils::FolderExists(fs,path))\
       
   346 		{\
       
   347 		_LIT(KText,aText);\
       
   348 		TLogFileDes16OverflowHandler ofh;\
       
   349 		TBuf<KMaxLogLineLength> buf;\
       
   350 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6);\
       
   351 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   352 		}\
       
   353 	fs.Close();\
       
   354 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4,aParam5,aParam6);\
       
   355 	}
       
   356 
       
   357 // With 12 parameters
       
   358 #define LOGFMT12(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12) \
       
   359 	{\
       
   360 	TFileName path(KLogsFolder);\
       
   361 	path.Append(KLogDir);\
       
   362 	path.Append(KBackslash);\
       
   363 	TFileName fileNameAndPath(path);\
       
   364 	fileNameAndPath.Append(aLogFile);\
       
   365 	RFs fs;\
       
   366 	fs.Connect();\
       
   367 	if(BaflUtils::FolderExists(fs,path))\
       
   368 		{\
       
   369 		_LIT(KText,aText);\
       
   370 		TLogFileDes16OverflowHandler ofh;\
       
   371 		TBuf<KMaxLogLineLength> buf;\
       
   372 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12);\
       
   373 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   374 		}\
       
   375 	fs.Close();\
       
   376 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12);\
       
   377 	}
       
   378 
       
   379 // Not implemented
       
   380 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen)
       
   381 
       
   382 // Log the memory allocated on the current thread's default heap
       
   383 #define LOG_HEAP_USAGE(aLogFile) \
       
   384 	{\
       
   385 	TFileName path(KLogsFolder);\
       
   386 	path.Append(KLogDir);\
       
   387 	path.Append(KBackslash);\
       
   388 	TFileName fileNameAndPath(path);\
       
   389 	fileNameAndPath.Append(aLogFile);\
       
   390 	RFs fs;\
       
   391 	fs.Connect();\
       
   392 	TInt allocSize;\
       
   393 	User::Heap().AllocSize(allocSize);\
       
   394 	_LIT(KText,"* Memory allocated on the thread's default heap: %d *");\
       
   395 	if(BaflUtils::FolderExists(fs,path))\
       
   396 		{\
       
   397 		TLogFileDes16OverflowHandler ofh;\
       
   398 		TBuf<KMaxLogLineLength> buf;\
       
   399 		buf.AppendFormat(KText,&ofh,allocSize);\
       
   400 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   401 		}\
       
   402 	fs.Close();\
       
   403 	RDebug::Print(KText, allocSize);\
       
   404 	}
       
   405 
       
   406 #endif // _CLOGFILE_IMPLEMENTATION_
       
   407 
       
   408 #else // _ENABLED_
       
   409 
       
   410 #define DEBUGLOG_ARG(x)
       
   411 
       
   412 #define LOG_RESET(aLogFile)
       
   413 #define LOG(aLogFile,aText)
       
   414 #define LOGDES(aLogFile,aDes)
       
   415 #define LOGFMT(aLogFile,aText,aParam)
       
   416 #define LOGFMT2(aLogFile,aText,aParam1,aParam2)
       
   417 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3)
       
   418 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4)
       
   419 #define LOGFMT6(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6)
       
   420 #define LOGFMT12(aLogFile,aText,aParam1,aParam2,aParam3,aParam4,aParam5,aParam6,aParam7,aParam8,aParam9,aParam10,aParam11,aParam12)
       
   421 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen)
       
   422 #define LOG_HEAP_USAGE(aLogFile)
       
   423 
       
   424 #endif // _ENABLED_
       
   425 
       
   426 #endif // __DEBUGUTILS_H__