// logger.h
// By: Michael R. Rich, 2009
// swarmapps.wordpress.com
// This code is released into the public domain
#ifndef __EASYLOGGER_H
#define __EASYLOGGER_H
#include <iostream>
// The following macro and class allow for a very quick, runtime-settable loging function
// Essentially if the value passed into the macro as "TYPE" is true, it will then log the given text.
/* code snippet example below
bool someLogType = true;
LOG(someLogType) << "someLogType.Log this please!\n"; // the text will be logged
*/
#define LOG(TYPE) (TYPE) && logger::outstream
#define LLOG(TYPE) LOG(TYPE) << #TYPE << ": "
// The LLOG Macro will produce results like:
// LLOG(MyLogType) << "A fancy log\n";
// output = MyLogType: A fancy log
// This works because the boolean && operator stops at the first false value in the expression.
// So, if the value TYPE is false, no further evaluation will occur and the rest of the line will be ignored
// Here are some standard logs I've used
#define VERBOSE logger::verboseLog
#define NORMAL logger::normalLog
#define DEBUG logger::debugLog
#define CONFIGTEST logger::configFileTest
// add your own log types here and in the cpp file!
// To use, simply include the logger.h header file in your program, add the logger.cpp file to your target and use the code snippet:
/*
NORMAL = true;
VERBOSE = false;
DEBUG = true;
LOG(NORMAL) << "I'll print\n";
LOG(VERBOSE) << "I won't\n";
LOG(DEBUG) << "But I will!";
*/
class logger {
public:
static bool verboseLog;
static bool normalLog;
static bool debugLog;
static bool configFileTest;
// Set up other log types here as necessary
static std::ostream& outstream;
static void setOutstream (std::ostream& newStream) {
outstream.rdbuf(newStream.rdbuf());
}
};
#endif