Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Simple-to-use Symbian C++ macros for writing debug log files

From Wiki
Jump to: navigation, search
Article Metadata
Platform(s): S60 (All)
Created: User:Technical writer 1 (07 Oct 2008)
Last edited: hamishwillee (30 May 2013)


The RFileLogger class provides both static and non-static methods for file logging. By writing a few simple macros, file logging can be simplified even further.


The following header file must be included in each source file that needs to write to the log file. The KLogsDir constant must be customized to identify the directory under c:\logs\ that will contain the log file.

The log file will be created only if the directory specified by KLogsDir exists under c:\logs\. This way, logging can be turned on or off without having to recompile by simply removing the directory.

#ifndef __FILELOGGER_H__
#define __FILELOGGER_H__

#include <e32std.h>
#include <flogger.h>    // link against flogger.lib

_LIT( KLogsDir, "MYAPP");
_LIT( KLogFileName, "log.txt");

#define __LOGSTR_TOFILE(S)          { _LIT(KTmpStr, S); RFileLogger::WriteFormat(KLogsDir(), KLogFileName(), EFileLoggingModeAppend, KTmpStr()); }
#define __LOGSTR_TOFILE1(S, P0)     { _LIT(KTmpStr, S); RFileLogger::WriteFormat(KLogsDir(), KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(KTmpStr()),P0); }
#define __LOGSTR_TOFILE2(S, P0, P1) { _LIT(KTmpStr, S); RFileLogger::WriteFormat(KLogsDir(), KLogFileName(), EFileLoggingModeAppend, TRefByValue<const TDesC>(KTmpStr()),P0,P1); }

#endif /* __FILELOGGER_H__ */


Note that these these macros cannot be used with variable argument lists. Instead, the macro to be used is selected based on the number of arguments in the logged text string.

// Log a single line of text without arguments
__LOGSTR_TOFILE("Init complete.")

// Log a single integer value
__LOGSTR_TOFILE1("Magic number: %d", intValue)

// Log a string (descriptor) + integer value
__LOGSTR_TOFILE2("Message: \"%S\", self-destructs in %d sec", &msgDes, timeleft)

Macros taking more arguments can be created as needed.

This page was last modified on 30 May 2013, at 04:35.
74 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.