JrDebugLogger - Sample - DonationCoder.com
Welcome Guest.   Make a donation to an author on the site August 03, 2015, 08:24:29 PM  *

Please login or register.
Or did you miss your validation email?

Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.

You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
The N.A.N.Y. Challenge 2010! Download 24 custom programs!
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: JrDebugLogger - Sample  (Read 1617 times)
First Author
Posts: 34,839

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: November 14, 2010, 10:46:53 AM »

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:

Formatted for C++ with the GeSHI Syntax Highlighter [copy or print]
  1. //---------------------------------------------------------------------------
  2. // System includes for std::cout usage below
  3. #include <iostream>
  4. //---------------------------------------------------------------------------
  6. //---------------------------------------------------------------------------
  7. // Include the Debugging Library file (only our main should include this
  8. //  file, additional .cpp files should include "jrdebug.h"
  9. //  alternatively, you could add this cpp to your project or makefile.
  10. #include <jrdebug_main.cpp>
  11. //---------------------------------------------------------------------------
  14. //---------------------------------------------------------------------------
  15. int main(int argc, char *argv[])
  16. {
  17. // set our own commandline options as one big string, not using actual comline args
  18. JrDebugParseCommandlineArgString("-dbo text;debugout.txt;info",NULL,NULL);
  20. // a debug logging output line
  21. debugout << "This is a debugging message (argc="<<argc<<")";
  23. // return success
  24. std::cout << "Program finished."<<std::endl;
  25. return 0;
  26. }
  27. //---------------------------------------------------------------------------

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.
« Last Edit: November 14, 2010, 10:57:03 AM by mouser » Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.047s | Server load: 0.04 ]

Share on Facebook
submit to reddit