/** \file LogManager.h
* Declares the LogManager class.
*
* @author Vovansim (aka Scorpion)
* @version Version 1.0
* @date September 13, 2003
*/
#ifndef PROJECT_AXIS_LOG_MANAGER
#define PROJECT_AXIS_LOG_MANAGER
#include
#include
#include
#include
/** Enumerates the possible types of messages that can be logged by
* the manager. Each different type will write the messages to its own
* separate file. That is true for all but the FatalError-type
* messages, which will be treated as urgent and redirected straight
* to the stderr stream.
*/
typedef enum tagLogEntryType {
LET_Application, /**< These would be the application messages. Not necessarily errors, but things pertinent to the application logic-related things. */
LET_Graphics, /**< These are the messages related to graphics and GUI. Failed to load an image? Not enough video memory? Too many tiles? Clicked on a bad button? It belongs here. */
LET_Warning, /**< These are miscellaneous warnings. Normally, everything should fit in the above categories, but what if I forgot something? Put it here. */
LET_Debug, /**< The good ol' debug messages... A pod cannot find his way around the map? Dump his info in here! */
LET_FatalError /**< If something's gone terribly wrong, and you aren't even sure you can still write to disk, stick and error in here. It will be redirected straight to the standard error output. */
} LogEntryType;
/**
* The LogManager class allows for easy manipulation of all kinds of
* application logging. The most basic functionality of the class
* resides in the overloaded Write method which allows the user to
* write messages to the specified log. This class is implemented as a
* singleton, thus the constructor and destructor are hidden from the
* user. To use the log manager, simply get its instance and call the
* write method on it. There is no need to do any kind of flushing or
* clean-up after the log is no longer necessary - it will be done
* automatically when the application quits.
*
* @note The log manager uses a system of predefined strings that can
* be used to write common log messages. Therefore, it requires a
* messages.txt file to be located in the same folder as the
* executable. If the text file is not present, pre-defined messages
* are not available, but logging can still be done by passing a
* custom value to the overloaded Write method.
*/
class LogManager {
public:
/** Returns a pointer to the instance of the log manager class */
inline static LogManager* GetInstance() { static LogManager manager; return &manager; }
/** Writes the message passed in into the appropriate log
* file. Note that this method supports parameter replacement,
* and thus can be used just like, say, printf: one can pass
* it a format string and some replacement arguments, which
* would result in correctly formatted string being written to
* the log file. */
void Write(LogEntryType messageType, const char *msg, ...);
/** Writes a pre-defined message into the appropriate log file. */
void Write(LogEntryType messageType, unsigned long msgID, ...);
protected:
LogManager();
~LogManager();
//////////////// Output streams for different message types ///////////////
std::ofstream applicationStream;
std::ofstream graphicsStream;
std::ofstream warningStream;
std::ofstream debugStream;
/** A vector of pre-defined message strings */
std::vector messageStrings;
/** Loads the pre-defined message string from a file on disk */
bool LoadStrings();
};
#endif//PROJECT_AXIS_LOG_MANAGER