cesky english
  Symbian   Travels
 
 
Symbian (Applications)

 PearlMania
 DictOrg
 NaCrosses
 The Wall
 
Symbian (Examples)

 HeadSetMon
 LogToPC
 LoggerEx
 
LoggerEx
 Logging on the device

Platform: Series 60 (Symbian)

LoggerEx.sis

source

Tested on: Siemens SX1, Nokia 3650

Should also work on: All Series60 devices.
(If you run this game on one of these phones please send me an email so I can mark this phone as supported.)

Description:

This is a really very simple example demonstrating the basic logging capability utilizing flogger.lib library. Our project needs to be linked against this library, so lets add this line to .mmp file.


LIBRARY	flogger.lib	

For logging we will use RFileLogger class with some help from a method with variable number of parameters using TRefByValue class. RFileLogger provides both static and non-static versions of access functions to the file logging system. We will use the static one.


void MyLogger::Print(TRefByValue<const TDesC> aFmt, ...)
	{

    VA_LIST ap;
    VA_START(ap, aFmt);

    RFileLogger::WriteFormat(KLoggerLogdir, 
                             KLoggerLogfile, 
                             EFileLoggingModeAppend, 
                             aFmt,
                             ap);

    VA_END(ap);

	}
	

Clearly in KLoggerLogdir and KLoggerLogfile we have names of the directory and file where we want to log to. The most interesting stuff in the example above is the approach used for being able to get unknown number of parameters to our method.


VA_LIST is typedeffed like this

typedef TInt8* VA_LIST[1];
	

and it defines a 'C' style array of pointers to TInt8 types

The first parameter in a function that takes a variable number of parameters must always take the first parameter as a value reference. Therefore our TRefByValue trick.

Usage look like this:


TBuf<64> bufLog;

Print(_L("message without params"));

bufLog.Format(_L("one param [%d]"),20);
Print(bufLog);

bufLog.Format(_L("ten params: %b, %c, %d, %o, %u, %x, %d, %d, %d, %d"),65,65,65,65,65,65,7,8,9,10);
Print(bufLog);
	

And here are the results in the logfile:


30/03/2004	9:47:23	message without params
30/03/2004	9:47:23	one param [20]
30/03/2004	9:47:23	ten params: 1000001, A, 65, 101, 65, 41, 7, 8, 9, 10
	

To make it more easy to use lets define set of macros that will be used by our application


#define __I_WANT_LOGS__

#ifdef __I_WANT_LOGS__
	#define LOG0(msg)MyLogger::Print(msg);
	#define LOG1(msg, p1)MyLogger::Print((msg), (p1));
	#define LOG2(msg, p1, p2)MyLogger::Print((msg), (p1), (p2));
	#define LOG3(msg, p1, p2, p3)MyLogger::Print((msg), (p1), (p2), (p3));
#else
	#define LOG0(msg)
	#define LOG1(msg, p1)
	#define LOG2(msg, p1, p2)
	#define LOG3(msg, p1, p2, p3)
#endif
	

Using these macros we can easily switch on/off logging in our application. If __I_WANT_LOGS__ is defined the static logging methods will be called when using LOGX() macros. If it is not defined, dummy macros will be called instead of it.

I'm well aware of some lack of this approach but it will do for small and simple projects. If you were just wondering how to log some information from your application when running on the real device this can be an easy and convenient way to do it.

 
 
design, programming: Tomas Kucera (2002)
e-mail: sopta (at) post.cz, icq: 33297193
last change: 2005/01/29