Posted by swarmapps on Mon 23 Nov 03:46 (modification of post by view diff)
report abuse | download | new post
- // logger example
- // By: Michael R. Rich, 2009
- // swarmapps.wordpress.com
- // Demonstrates how to use the logger class in your program
- // This code is released into the public domain
- #include <iostream>
- #include <sstream>
- #include "logger.h"
- using namespace std;
- int main (int argc, char * const argv[]) {
- // Set these to turn various logs on or off dynamically
- NORMAL = true;
- DEBUG = false;
- VERBOSE = true;
- LOG(NORMAL) << "This will log\n";
- LOG(DEBUG) << "But this one won't\n";
- LLOG(VERBOSE) << "This one will log, but with the name of the logtype prepended to the message\n";
- // Now we redirect the log output to a custom location. This could be a file or any ostream
- stringstream newLog;
- logger::setOutstream(newLog);
- LOG(NORMAL) << "This will log\n";
- LOG(DEBUG) << "But this one won't\n";
- LLOG(VERBOSE) << "This one will log, but with the name of the logtype prepended to the message\n";
- string results = newLog.str();
- cout << "In the new log: \n" << results << "\n";
- // Always reset the logger to clog before the program exits or you will get a BAD_ACCESS error
- // I'm still trying to work out that problem, but this is an easy fix
- logger::setOutstream(clog);
- return 0;
- }
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.