pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ pastebin - collaborative debugging tool View Help


Posted by swarmapps on Mon 23 Nov 03:46 (modification of post by view diff)
report abuse | download | new post

  1. // logger example
  2. // By: Michael R. Rich, 2009
  3. // swarmapps.wordpress.com
  4. // Demonstrates how to use the logger class in your program
  5. // This code is released into the public domain
  6.  
  7. #include <iostream>
  8. #include <sstream>
  9. #include "logger.h"
  10.  
  11. using namespace std;   
  12.  
  13. int main (int argc, char * const argv[]) {
  14.         // Set these to turn various logs on or off dynamically
  15.         NORMAL = true;
  16.         DEBUG = false;
  17.         VERBOSE = true;
  18.        
  19.         LOG(NORMAL) << "This will log\n";
  20.         LOG(DEBUG) << "But this one won't\n";
  21.         LLOG(VERBOSE) << "This one will log, but with the name of the logtype prepended to the message\n";
  22.        
  23.         // Now we redirect the log output to a custom location.  This could be a file or any ostream
  24.         stringstream newLog;
  25.         logger::setOutstream(newLog);
  26.        
  27.         LOG(NORMAL) << "This will log\n";
  28.         LOG(DEBUG) << "But this one won't\n";
  29.         LLOG(VERBOSE) << "This one will log, but with the name of the logtype prepended to the message\n";
  30.        
  31.         string results = newLog.str();
  32.         cout << "In the new log: \n" << results << "\n";
  33.        
  34.         // Always reset the logger to clog before the program exits or you will get a BAD_ACCESS error
  35.         // I'm still trying to work out that problem, but this is an easy fix
  36.         logger::setOutstream(clog);
  37.         return 0;
  38.        
  39. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post