Need to debug some code on a mobile or track the execution flow ? The RFileLogger may help you. As a matter of fact this class is really powerful and easy to use.
The first step is to declare a connection to the file logger server and create the log file:
// Open a connection to the File logger server
RFileLogger iLog;
iLog.Connect();
iLog.CreateLog(_L("MyLoggingDirectory"),_L("MyLogFile"),EFileLoggingModeOverwrite);
...
// Close the log file and the connection to the server.
iLog.CloseLog();
iLog.Close();
The CreateLog function takes three parameter:
the base name of the log directory (relative to C:\Logs and without trailing '/')
the name of the log file
the logging mode (EFileLoggingModeOverwrite or EFileLoggingModeAppend)
In the exemple code above, the full path to my log file (on the phone file system) would be C:/Logs/MyLoggingDirectory/MyLogFile.
As far as I am concerned, I like to put the opening code in the ConstructL() method of the class I want to trace, and the closing code in the destructor. Also note that in real production code, you would better check that Connect() and CreateLog() does return KErrNone.
Once you have done this, you can output text and data to the log file. The basic primitives are:
| Primitive | Output in the log file |
| iLog.Write(_L("Hello World")) | 11/07/2003 4:00:13 Hello World |
| iLog.WriteFormat(_L("Result=%d"),err) | 11/07/2003 4:00:13 Result=0 |
| iLog.HexDump(aHeader,aHeader,myPtr,4) | 11/07/2003 4:00:13 myBuf:0000: 41 42 00 44 AB.D |
If you don't want to have date or time logged, you can turn it off by using:
iLog.SetDateAndTime(TBool aUseDate, TBool aUseTime).
Don't forget to add the flogger.lib in your MMP file and to include the flogger.h file, and that's it. You can compile, execute and get your log file.
No ? The log file was not created! You're right. This is not (yet) an issue with your code. But another specificity of how Symbian handles log file: nothing will be logged unless you manually create the C:/Logs/MyLoggingDirectory by yourself. No need to recompile anything to enable/disable the log feature. Just create or not logging directory [1]. I like this (but it has a cost in term of code size).
[1] If you don'y know how to do this, just check any file explorer application like FExplorer. You will need this kind of app to read or send the log file back to your PC
Hi, I tried to generate log file in the following folder c:\\System\\Apps on the board. But this is not happening.
This the code,
TInt treturn; RFileLogger iLog; treturn = iLog.Connect(); if(treturn != KErrNone) return;
iLog.CreateLog(_L("c:\\System\\Apps\\CASINO"),_L("FirstLog"),EFileLoggingModeAppend);
iLog.Write(_L("My log is")); iLog.CloseLog();
iLog.Close();
Do I need to create a separate folder for logging or can I use the folders which are already available on the board.
I am confused.
Regards Raj
Logs file are always created in C:\Logs. The first argument to CreateLog() is a directory name relative to this C:\Logs directory.
The tutorial has been updated to state this more clearly.
Hi.
I tryed to use RFileLogger.
The application compile well for WINS, but when I try to compile for thum I got the following error:
-f "\Symbian\8.0a\S60_2nd_FP2\EPOC32\BUILD\MISDOCUMENTOS\DESARROLLOS\SYMBIAN\AUDIODAEMON\GROUP\THUMB.make" TARGET CFG=UREL VERBOSE=-s make[1]: *** No rule to make target `\SYMBIAN\8.0A\S60_2ND_FP2\EPOC32\INCLUDE\FLOGGER.H \SYMBIAN\8.0A\S60_2ND_FP2\EPOC32\INCLUDE\FLOGGER.INL', needed by `..\..\..\..\..\SYMBIAN\8.0A\S60_2ND_FP2\EPOC32\BUILD\MISDOCUMENTOS\DESARROLLOS\SYMBIAN\AUDIODAEMON\GROUP\AUDIODAEMON\THUMB\UREL\AUDIODAEMON.o'. Stop. make: *** [TARGETAUDIODAEMON] Error 2
Some body know what's happening?. RFileLogger must be used only in wins.
Thanks.
Diego (dacosta51@yahoo.com)
can i use this class (resp. flogger library) also in release mode or is this only in debug mode enabled?
thx,
master2003
You can use in both.
It is the presence of your log directory in C:\Logs that will enable/disable logging
what is the folder to create the \Logs\MyLogDirectory\ folder on the phone HW?
THANKS@!
Hello, i tried to use this logger stuff exactly as you have described it above. unfortunately i get an linker error which says something like "unresolved external symbol". I have not forgotten to add the line "LIBRARY Flogger.lib" to the *.mmp file of my project. Any ideas?
tom
Hello, I followed every step in this guide, still no luck.
I have manually created
Logs
and my own directory
Mobeel
My Code iLog.Connect(); iLog.CreateLog(_L("Mobeel"),_L("GPRS.txt"),EFileLoggingModeOverwrite); iLog.Write(_L("1111111111111111111111111111111111111111")); iLog.CloseLog(); iLog.Close();
And when I check the directory c:/Logs/Mobeel/ there are no files there..
And ofcourse I have compiled and run the app including the flogger.lib and .h file..
And I have checked that the Connect() and CreateLog does return KErrNone
I tried out your code and it works. The code I compiled was:#include <flogger.h>
_LIT(KTag1,"Mobeel");
_LIT(KTag2,"GPRS.txt");
_LIT(KTestString,"1111111111111111111111111111111111111111");
GLDEF_C TInt E32Main()
{
__UHEAP_MARK;
RFileLogger iLog; //TODO: include all these in macros, and check return codes
iLog.Connect();
iLog.CreateLog(KTag1,KTag2,EFileLoggingModeOverwrite);
iLog.Write(KTestString);
iLog.CloseLog();
iLog.Close();
__UHEAP_MARKEND;
return KErrNone;
}
and I created this directory:
S:\epoc32\wins\c\logs\Mobeel
to see the GPRS.txt file
Steve
Hi,
My application involved multiple views, so I have to run the application using
return EikStart::RunApplication( NewApplication );
If I use iLog as below, I can only get the log file for Write functionality only.
GLDEF_C TInt E32Main()
{
__UHEAP_MARK;
RFileLogger iLog; //TODO: include all these in macros, and check return codes
iLog.Connect();
iLog.CreateLog(KTag1,KTag2,EFileLoggingModeOverwrite);
iLog.Write(KTestString);
iLog.CloseLog();
iLog.Close();
__UHEAP_MARKEND;
return EikStart::RunApplication( NewApplication );
}
How can I take the log file for an entire application.
Do I need to write those 5 lines in every function?
It will be complex...right ?
Whats the correct procedure ?
Can anybody help me out....
"Also note that in real production code, you would better check that Connect() and CreateLog() does return KErrNone."
I would hope in production code you would not log at all! Consider using macros for each call to RFileLogger so that it is not used in urel builds that are distributed, which also means there is no ROM trade-off in the final build. Also, it is debatable whether to check for KErrNone - what action will you take if it fails? Logging is only a best-effort process.
logging only helps if you have a panic that happens on device and you don't know why. In a small app you shouldnt need to lgo at all. and remember not to leave logging in production code. if it runs then they users memory will get chewed up and they wont know why. they will take your phone back and itll all be because of your silly little app and the fact you cant code to save your life.
Kent E.