ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Programmer Libs

JrDebugLogger - Sample

(1/1)

mouser:
Thought it might be useful to paste a complete sample of using JrDebugLogger in code.  I really don't use advanced functions so this is almost exactly what i use:


--- Code: C++ ---//---------------------------------------------------------------------------// System includes for std::cout usage below#include <iostream>//--------------------------------------------------------------------------- //---------------------------------------------------------------------------// Include the Debugging Library file (only our main should include this//  file, additional .cpp files should include "jrdebug.h"//  alternatively, you could add this cpp to your project or makefile.#include <jrdebug_main.cpp>//---------------------------------------------------------------------------  //---------------------------------------------------------------------------int main(int argc, char *argv[]){        // set our own commandline options as one big string, not using actual comline args        JrDebugParseCommandlineArgString("-dbo text;debugout.txt;info",NULL,NULL);         // a debug logging output line        debugout << "This is a debugging message (argc="<<argc<<")";         // return success        std::cout << "Program finished."<<std::endl;        return 0;}//---------------------------------------------------------------------------

So basically here is what we have:


* First, we include in the the jrdebug code with #include <jrdebug_main.cpp>.  Now actually the cleaner standard way is to add jrdebug_main.cpp to your project file, and then #include <jrdebug.h> in your files.  
* Second, we have an initialization function for JrDebugLogger, which simulates some commandline options; there are a few helper functions depending on whether argc+argv are how you want to pass in commandline options, if at all.  Don't get scared by this, it's basically a really simple way to both set options and/or let the user set debug options via commandline.  In this case, i'm just setting some options manually and ignoring any user specified commandline options: JrDebugParseCommandlineArgString("-dbo text;debugout.txt;info",NULL,NULL);
* This option string tells JrDebugLogger to log debug messages in text format, to the file debugout.txt, which will be in application directory if permissions allow, and display extra info about where the file was created.  If you also wanted to display debug messages to the console you could use "-dbo text;debugout.txt;stdout;info" instead.
* Lastly, we send a debug message using stream syntax: debugout << "This is a debugging message (argc="<<argc<<")"; there is also a printf style debug output function alternative.
The generated debugout.txt file contents look like this:
Sat Nov 13 20:11:31 2010 -> Message: This is a debugging message (argc=1)


Of course there are tons of advanced extra things you can do, but that's the basics.

And again, the absolutely *KEY* feature of JrDebugLogger, and what makes it special and a bit tricky under the hood, is that when you build in Release mode, by default all debug code is made to completely compile out and have 0 impact on size and cpu of application.

Navigation

[0] Message Index

Go to full version