imgeditor_plat/image_editor_debug_utilities_api/inc/imageeditordebugutils.h
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     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 * Simple RFileLogger based set of log writer macros.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // Instructions:
       
    23 //
       
    24 // 1. Add the following line into your MMP file
       
    25 // LIBRARY flogger.lib
       
    26 //
       
    27 // 2. Add the following lines to a .cpp file to be debugged 
       
    28 //    (note that the #define must be before the #include)
       
    29 //
       
    30 // #define ENABLE_DEBUGLOG
       
    31 // #include "imageeditordebugutils.h"
       
    32 //
       
    33 // 3a. Call LOG_INIT 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\ImageEditor" 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 _FLOGGER_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 file */
       
    65 _LIT(KImageEditorLogFile,"ImageEditor.log");
       
    66 
       
    67 /**  Log directory */
       
    68 _LIT(KLogDir, "ImageEditor");
       
    69 
       
    70 /**  Log file names */
       
    71 _LIT(KJpegRotatorLogFile,"JpegRotator.log");
       
    72 _LIT(KJpegRotatorTimingLogFile,"JpegRotatorTiming.log");
       
    73 
       
    74 /**  Maximum length for a log line */
       
    75 const TInt KMaxLogLineLength = 256;
       
    76 
       
    77 /**
       
    78  *  Overflow handler. Too long lines are truncated.
       
    79  *
       
    80  *  @code
       
    81  *   ?good_class_usage_example(s)
       
    82  *  @endcode
       
    83  *
       
    84  *  @lib -
       
    85  *  @since S60 v5.0 
       
    86  */
       
    87 class TLogFileDes16OverflowHandler : public TDes16Overflow
       
    88 	{
       
    89 	virtual void Overflow(TDes16& /*aDes*/) 
       
    90 		{
       
    91 		// do nothing
       
    92 		}
       
    93 	};
       
    94 
       
    95 
       
    96 #ifdef ENABLE_DEBUGLOG
       
    97 
       
    98 #ifdef _FLOGGER_IMPLEMENTATION_
       
    99 
       
   100  
       
   101 // Initializes the log file, overwrites existing
       
   102 // Log files are always created in C:\Logs. The first argument to CreateLog() 
       
   103 // is a directory name relative to this C:\Logs directory.
       
   104 #define LOG_INIT(aLogFile) \
       
   105 	{\
       
   106 	RFileLogger logger;\
       
   107 	logger.Connect();\
       
   108 	logger.CreateLog(KLogDir,aLogFile,EFileLoggingModeOverwrite);\
       
   109 	logger.Write(KLogDir,aLogFile,EFileLoggingModeAppend,_L("*** Log file created ***"));\
       
   110 	logger.CloseLog();\
       
   111 	logger.Close();\
       
   112 	}
       
   113 
       
   114 // Logs a simple text, e.g.
       
   115 //   LOG(_L("logfile.txt"),"Something happens here")
       
   116 #define LOG(aLogFile,aText) \
       
   117 	{\
       
   118 	RFileLogger::Write(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText));\
       
   119 	RDebug::Print(_L(aText));\
       
   120 	}
       
   121 
       
   122 // Logs a Descriptor
       
   123 #define LOGDES(aLogFile,aDes) \
       
   124 	{\
       
   125 	RFileLogger::Write(KLogDir,aLogFile,EFileLoggingModeAppend,aDes);\
       
   126 	RDebug::Print(aDes);\
       
   127 	}
       
   128 
       
   129 // Logs a number with string format, e.g. 
       
   130 //	LOGFMT(KLogFile,"Result=%d",err)
       
   131 //	LOGFMT(KLogFile, "FileName: %S", &aFileName );
       
   132 #define LOGFMT(aLogFile,aText,aParam) \
       
   133 	{\
       
   134 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam);\
       
   135 	RDebug::Print(_L(aText), aParam);\
       
   136 	}
       
   137 
       
   138 // Logs text and two 2 parameters
       
   139 #define LOGFMT2(aLogFile,aText,aParam1,aParam2) \
       
   140 	{\
       
   141 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2);\
       
   142 	RDebug::Print(_L(aText), aParam1,aParam2);\
       
   143 	}
       
   144 
       
   145 // Logs text and two 3 parameters
       
   146 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3) \
       
   147 	{\
       
   148 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3);\
       
   149 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3);\
       
   150 	}
       
   151 
       
   152 // Logs text and two 4 parameters
       
   153 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4) \
       
   154 	{\
       
   155 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,_L(aText),aParam1,aParam2,aParam3,aParam4);\
       
   156 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4);\
       
   157 	}
       
   158 
       
   159 // Logs a hex dump
       
   160 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen) \
       
   161 	RFileLogger::HexDump(KLogDir,aLogFile, EFileLoggingModeAppend, _S(aHeader), _S(aMargin), aPtr, aLen);
       
   162 
       
   163 // Logs the memory allocated on the current thread's default heap
       
   164 #define LOG_HEAP_USAGE(aLogFile) \
       
   165 	{\
       
   166 	TInt allocSize;\
       
   167 	User::Heap().AllocSize(allocSize);\
       
   168 	_LIT(KText,"* Memory allocated on the thread's default heap: %d *");\
       
   169 	RFileLogger::WriteFormat(KLogDir,aLogFile,EFileLoggingModeAppend,KText,allocSize);\
       
   170 	RDebug::Print(KText,allocSize);\
       
   171 	}
       
   172 
       
   173 #else // _FLOGGER_IMPLEMENTATION_
       
   174 
       
   175 _LIT(KLogsFolder, "C:\\Logs\\");
       
   176 _LIT(KBackslash, "\\");
       
   177 
       
   178 #define LOG_INIT(aLogFile)\
       
   179 	{\
       
   180 	TFileName path(KLogsFolder);\
       
   181 	path.Append(KLogDir);\
       
   182 	path.Append(KBackslash);\
       
   183 	TFileName fileNameAndPath(path);\
       
   184 	fileNameAndPath.Append(aLogFile);\
       
   185 	RFs fs;\
       
   186 	fs.Connect();\
       
   187 	if(BaflUtils::FolderExists(fs,path))\
       
   188 		{\
       
   189 		RFile file;\
       
   190 		file.Replace(fs, fileNameAndPath, EFileShareAny|EFileWrite);\
       
   191 		file.Close();\
       
   192 		CLogFile::StaticLog(fileNameAndPath,_L("*** Log file created ***\n"));\
       
   193 		}\
       
   194 	fs.Close();\
       
   195 	}
       
   196 
       
   197 #define LOG(aLogFile,aText) \
       
   198 	{\
       
   199 	TFileName path(KLogsFolder);\
       
   200 	path.Append(KLogDir);\
       
   201 	path.Append(KBackslash);\
       
   202 	TFileName fileNameAndPath(path);\
       
   203 	fileNameAndPath.Append(aLogFile);\
       
   204 	RFs fs;\
       
   205 	fs.Connect();\
       
   206 	if(BaflUtils::FolderExists(fs,path))\
       
   207 		{\
       
   208 		CLogFile::StaticLog(fileNameAndPath,_L(aText));\
       
   209 		}\
       
   210 	fs.Close();\
       
   211 	RDebug::Print(_L(aText));\
       
   212 	}
       
   213 
       
   214 #define LOGDES(aLogFile,aDes) \
       
   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,aDes);\
       
   226 		}\
       
   227 	fs.Close();\
       
   228 	RDebug::Print(aDes);\
       
   229 	}
       
   230 
       
   231 #define LOGFMT(aLogFile,aText,aParam) \
       
   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 		_LIT(KText,aText);\
       
   243 		TLogFileDes16OverflowHandler ofh;\
       
   244 		TBuf<KMaxLogLineLength> buf;\
       
   245 		buf.AppendFormat(KText,&ofh,aParam);\
       
   246 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   247 		}\
       
   248 	fs.Close();\
       
   249 	RDebug::Print(_L(aText), aParam);\
       
   250 	}
       
   251 
       
   252 // With 2 parameters
       
   253 #define LOGFMT2(aLogFile,aText,aParam1,aParam2) \
       
   254 	{\
       
   255 	TFileName path(KLogsFolder);\
       
   256 	path.Append(KLogDir);\
       
   257 	path.Append(KBackslash);\
       
   258 	TFileName fileNameAndPath(path);\
       
   259 	fileNameAndPath.Append(aLogFile);\
       
   260 	RFs fs;\
       
   261 	fs.Connect();\
       
   262 	if(BaflUtils::FolderExists(fs,path))\
       
   263 		{\
       
   264 		_LIT(KText,aText);\
       
   265 		TLogFileDes16OverflowHandler ofh;\
       
   266 		TBuf<KMaxLogLineLength> buf;\
       
   267 		buf.AppendFormat(KText,&ofh,aParam1,aParam2);\
       
   268 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   269 		}\
       
   270 	fs.Close();\
       
   271 	RDebug::Print(_L(aText), aParam1,aParam2);\
       
   272 	}
       
   273 
       
   274 // With 3 parameters
       
   275 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3) \
       
   276 	{\
       
   277 	TFileName path(KLogsFolder);\
       
   278 	path.Append(KLogDir);\
       
   279 	path.Append(KBackslash);\
       
   280 	TFileName fileNameAndPath(path);\
       
   281 	fileNameAndPath.Append(aLogFile);\
       
   282 	RFs fs;\
       
   283 	fs.Connect();\
       
   284 	if(BaflUtils::FolderExists(fs,path))\
       
   285 		{\
       
   286 		_LIT(KText,aText);\
       
   287 		TLogFileDes16OverflowHandler ofh;\
       
   288 		TBuf<KMaxLogLineLength> buf;\
       
   289 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3);\
       
   290 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   291 		}\
       
   292 	fs.Close();\
       
   293 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3);\
       
   294 	}
       
   295 
       
   296 // With 4 parameters
       
   297 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4) \
       
   298 	{\
       
   299 	TFileName path(KLogsFolder);\
       
   300 	path.Append(KLogDir);\
       
   301 	path.Append(KBackslash);\
       
   302 	TFileName fileNameAndPath(path);\
       
   303 	fileNameAndPath.Append(aLogFile);\
       
   304 	RFs fs;\
       
   305 	fs.Connect();\
       
   306 	if(BaflUtils::FolderExists(fs,path))\
       
   307 		{\
       
   308 		_LIT(KText,aText);\
       
   309 		TLogFileDes16OverflowHandler ofh;\
       
   310 		TBuf<KMaxLogLineLength> buf;\
       
   311 		buf.AppendFormat(KText,&ofh,aParam1,aParam2,aParam3,aParam4);\
       
   312 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   313 		}\
       
   314 	fs.Close();\
       
   315 	RDebug::Print(_L(aText), aParam1,aParam2,aParam3,aParam4);\
       
   316 	}
       
   317 
       
   318 // Not implemented
       
   319 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen)
       
   320 
       
   321 // Log the memory allocated on the current thread's default heap
       
   322 #define LOG_HEAP_USAGE(aLogFile) \
       
   323 	{\
       
   324 	TFileName path(KLogsFolder);\
       
   325 	path.Append(KLogDir);\
       
   326 	path.Append(KBackslash);\
       
   327 	TFileName fileNameAndPath(path);\
       
   328 	fileNameAndPath.Append(aLogFile);\
       
   329 	RFs fs;\
       
   330 	fs.Connect();\
       
   331 	TInt allocSize;\
       
   332 	User::Heap().AllocSize(allocSize);\
       
   333 	_LIT(KText,"* Memory allocated on the thread's default heap: %d *");\
       
   334 	if(BaflUtils::FolderExists(fs,path))\
       
   335 		{\
       
   336 		TLogFileDes16OverflowHandler ofh;\
       
   337 		TBuf<KMaxLogLineLength> buf;\
       
   338 		buf.AppendFormat(KText,&ofh,allocSize);\
       
   339 		CLogFile::StaticLog(fileNameAndPath,buf);\
       
   340 		}\
       
   341 	fs.Close();\
       
   342 	RDebug::Print(KText, allocSize);\
       
   343 	}
       
   344 
       
   345 #endif // _FLOGGER_IMPLEMENTATION_
       
   346 
       
   347 #else // ENABLE_DEBUGLOG
       
   348 
       
   349 #define LOG_INIT(aLogFile)
       
   350 #define LOG(aLogFile,aText)
       
   351 #define LOGDES(aLogFile,aDes)
       
   352 #define LOGFMT(aLogFile,aText,aParam)
       
   353 #define LOGFMT2(aLogFile,aText,aParam1,aParam2)
       
   354 #define LOGFMT3(aLogFile,aText,aParam1,aParam2,aParam3)
       
   355 #define LOGFMT4(aLogFile,aText,aParam1,aParam2,aParam3,aParam4)
       
   356 #define LOGHEXDUMP(aLogFile,aHeader,aMargin,aPtr,aLen)
       
   357 
       
   358 #endif // ENABLE_DEBUGLOG
       
   359 
       
   360 #endif // __DEBUGUTILS_H__