0ad/source/ps/CLogger.h
janwas 27b6ffe2d6 # housekeeping
sorry, update-workspaces + rebuild is necessary (moved boost/utility
into PCH)

- ps/ : committed additional documentation on behalf of Joe.
- lib/ : HAVE_C99 - replace with specific e.g. HAVE_NPRINTF; intended to
help with MacOSX compat (by no longer requiring us to lie about
STDC_VERSION)
- NO_COPY_CTOR -> boost::noncopyable

This was SVN commit r4825.
2007-02-01 01:34:17 +00:00

69 lines
1.7 KiB
C++

#ifndef _ps_CLogger_H
#define _ps_CLogger_H
#include <fstream>
#include <string>
#include <set>
class CLogger;
extern CLogger* g_Logger;
#define LOG (g_Logger->Log)
#define LOG_ONCE (g_Logger->LogOnce)
enum ELogMethod
{
NORMAL,
MESSAGE = NORMAL,
ERROR,
WARNING
};
class CLogger : boost::noncopyable
{
public:
// Default constructor - outputs to normal log files
CLogger();
// Special constructor (mostly for testing) - outputs to provided streams.
// Can take ownership of streams and delete them in the destructor.
CLogger(std::ostream* mainLog, std::ostream* interestingLog, bool takeOwnership);
~CLogger();
// Functions to write different message types
void WriteMessage(const char *message, int interestedness);
void WriteError (const char *message, int interestedness);
void WriteWarning(const char *message, int interestedness);
// Function to log stuff to file
void Log(ELogMethod method, const char* category, const char *fmt, ...);
// Similar to Log, but only outputs each message once no matter how many times it's called
void LogOnce(ELogMethod method, const char* category, const char *fmt, ...);
private:
void Init();
void LogUsingMethod(ELogMethod method, const char* category, const char* message);
// the output streams
std::ostream* m_MainLog;
std::ostream* m_InterestingLog;
bool m_OwnsStreams;
// vars to hold message counts
int m_NumberOfMessages;
int m_NumberOfErrors;
int m_NumberOfWarnings;
// Returns how interesting this category is to the user
// (0 = no messages, 1(default) = warnings/errors, 2 = all)
int Interestedness(const char* category);
// Used to remember LogOnce messages
std::set<std::string> m_LoggedOnce;
};
#endif