Guest
Public paste!

swarmapps

By: a guest | Nov 22nd, 2009 | Syntax: C++ | Size: 1.22 KB | Hits: 85 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  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. }