Game Development Reference
In-Depth Information
bool m_enabled;
public:
ErrorMessenger(void);
void Show(const std::string& errorMessage, bool isFatal,
const char* funcName, const char* sourceFile,
unsigned int lineNum);
};
// construction; must be called at the beginning and end of the program
void Init(const char* loggingConfigFilename);
void Destroy(void);
// logging functions
void Log(const std::string& tag, const std::string& message,
const char* funcName, const char* sourceFile,
unsigned int lineNum);
void SetDisplayFlags(const std::string& tag, unsigned char flags);
}
Namespace > Class with Static Functions
Notice the namespace above and how it
s essentially acting like a class. In fact,
this could have been written as a class with all static members, but using a
namespace allows for several advantages. First, you have the ability to break
up the namespace among multiple different files, similar to partial classes in C#
and other languages. Second, since you can alias one namespace to another,
you can set up conditionally compiled classes in a cleaner manner.
'
This namespace acts as the public interface for the logging system. Under the covers,
there is another class called LogMgr that handles all the internals of actually logging.
This class lives in Dev\Source\GCC4\Debugging\Logger.cpp and is not accessed outside
this system. You can think of it as a private class. We
ll examine this class a little later.
To start using this system, you must call the Logger::Init() function. This instanti-
ates the internal LogMgr singleton class and initializes it. Logger::Destroy() must
be called before the program exits to ensure this internal class is destroyed.
There are two basic ways to display a log with this system. The first is to instantiate a
Logger::ErrorMessenger object and call the Show() function. This is used for
error logs and will display the error message in the dialog box you saw in Figure
23.3. If the user presses the Ignore button, it will automatically set the m_enabled
variable to false , and further calls to Show() will not do anything. Here
'
'
s an exam-
ple of how that might work:
if (somethingBadHappened)
{
 
Search WWH ::




Custom Search