0ad/source/ps/CLogger.h
Ykkrosh 2fac02f40a # Actor Viewer tool: added controls to toggle shadows, ground and polygon counts.
Elsewhere:
Disabled stack-trace test because it gives me assertion failures.
Fixed some uses of snprintf (which doesn't always add a \0 to the end of
the string), then got bored so there are still lots of broken ones.
Probably should replace snprintf with something more like snprintf_s
(but non-fatal) or something.
Made CLogger output valid HTML (except for the potentially dodgy
doctype). Removed its memory-logger, since we never use it and MICROLOG
can be used instead for quick execution-tracing.
Added tests to make sure CLogger handles long strings properly (which it
didn't). Made CLogger not a singleton, so it can be tested sensibly.

This was SVN commit r4424.
2006-09-28 20:41:12 +00:00

70 lines
1.6 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
{
public:
// Default constructor - outputs to normal log files
CLogger();
// Special constructor (mostly for testing) - outputs to provided streams.
// Takes ownership of streams and will delete them in the destructor.
CLogger(std::ostream* mainLog, std::ostream* interestingLog);
~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;
//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;
NO_COPY_CTOR(CLogger);
};
#endif