swarmapps
By: a guest | Nov 22nd, 2009 | Syntax:
C++ | Size: 1.22 KB | Hits: 85 | Expires: Never
// 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;
}