Sometime while developing your next Windows application, you might want to add some simple logger or trace support into the
_DEBUG version of the app. The standard Microsoft TRACE tool is just too inconvenient and weird. All you want is just printout some useful information from your code into text files, or maybe to the VS IDE output window. That is exactly what
MyTrace does. Include one single header file into your project, and you are ready to go.
First of all, you need to include the mytrace.h header into your project. Then before you start logging any messages, you need to initialize
MyTrace like this:
or if you want all really "bad bugs" to be reported into a separate file, then like this:
Corresponding text files will be created in your application working folder. Optionally, you can set the minimal severity level for the messages you want to see in the logs (the default level is
And you can add trace messages like this:
"\t\t\t MyApp v.%d.%d.%d started \n\n", 1, 0, 0);
"Wrong parameter: %s", wrongStringParameter);
And just before your application is about to close, do not forget to de-initialize
MyTrace by a simple call like this:
You can choose one from the following severity levels for the trace message:
If you initialize
MYTRACE_INIT_EX then all messages with
LEVEL_WARNING levels will also be reported into separate error log text files for debugging convenience.
You can change some settings for
MyTrace by commenting/un-commenting
#defines on the top of the file.
#define MT_USE_ATLTRACE turns on/off the forwarding of messages to the standard Microsoft
ATLTRACE macros. It enables you to see trace messages in the “output” window in the VS IDE. This is enabled by default.
#define MT_KEEP_ATLTRACE_LEVELS indicates if
MyTrace severity levels should be treated as
ATLTRACE levels also. By default, all messages forwarded to
ATLTRACE with level
#define MT_REDIRECT_STDOUT redirects global
stdout into the
MyTrace log file. You might want to do that if you want to grab all the output from the
printf class functions, but that could interfere with your application behavior; so by default, this option is disabled.
This is an example of how the log records look like:
INFO d:\projects\MyApp\MyAppMain.cpp(105) 02/20/06 09:00:41:
DEBUG d:\projects\MyApp\MyAppMain.cpp(322) 02/20/06 09:00:42:
WARNING d:\projects\MyApp\MyAppMain.cpp(408) 02/20/06 09:00:43:
Runtime Excepton 1234
INFO d:\projects\MyApp\MyAppMain.cpp(512) 02/20/06 09:00:44: