19 #ifndef OPENXCOM_LOGGER_H
20 #define OPENXCOM_LOGGER_H
26 #define WIN32_LEAN_AND_MEAN
31 #ifndef LOCALE_INVARIANT
32 #define LOCALE_INVARIANT 0x007f
41 inline std::string now();
70 static std::string& logFile();
73 std::ostringstream os;
79 inline Logger::Logger()
85 os <<
"[" << toString(level) <<
"]" <<
"\t";
89 inline Logger::~Logger()
94 fprintf(stderr,
"%s", os.str().c_str());
97 std::ostringstream ss;
98 ss <<
"[" << now() <<
"]" <<
"\t" << os.str();
99 FILE *file = fopen(logFile().c_str(),
"a");
100 fprintf(file,
"%s", ss.str().c_str());
108 return reportingLevel;
111 inline std::string& Logger::logFile()
113 static std::string logFile =
"openxcom.log";
119 static const char*
const buffer[] = {
"FATAL",
"ERROR",
"WARN",
"INFO",
"DEBUG"};
120 return buffer[level];
124 if (level > Logger::reportingLevel()) ; \
125 else Logger().get(level)
127 inline std::string now()
129 const int MAX_LEN = 25, MAX_RESULT = 80;
131 char date[MAX_LEN], time[MAX_LEN];
132 if (GetDateFormatA(LOCALE_INVARIANT, 0, 0,
133 "dd'-'MM'-'yyyy", date, MAX_LEN) == 0)
134 return "Error in Now()";
135 if (GetTimeFormatA(LOCALE_INVARIANT, TIME_FORCE24HOURFORMAT, 0,
136 "HH':'mm':'ss", time, MAX_LEN) == 0)
137 return "Error in Now()";
139 char result[MAX_RESULT] = {0};
140 sprintf(result,
"%s %s", date, time);
142 char buffer[MAX_LEN];
146 timeinfo = localtime(&rawtime);
147 strftime(buffer, MAX_LEN,
"%d-%m-%Y %H:%M:%S", timeinfo);
148 char result[MAX_RESULT] = {0};
149 sprintf(result,
"%s", buffer);
SeverityLevel
Defines the various severity levels of information logged by the game.
Definition: Logger.h:47
Something horrible has happened and the game is going to die!
Definition: Logger.h:49
Something weird happened, nothing special but it's good to know.
Definition: Logger.h:51
Something bad happened but we can still move on.
Definition: Logger.h:50
A basic logging and debugging class, prints output to stdout/files and can capture stack traces of fa...
Definition: Logger.h:62
Purely test stuff to help developers implement, not really relevant to users.
Definition: Logger.h:53
Useful information for users/developers to help debug and figure stuff out.
Definition: Logger.h:52