44 #define InfoLog(...) PV::InfoLog __VA_ARGS__(__FILE__, __LINE__) 45 #define WarnLog(...) PV::WarnLog __VA_ARGS__(__FILE__, __LINE__) 46 #define Fatal(...) PV::Fatal __VA_ARGS__(__FILE__, __LINE__) 47 #define ErrorLog(...) PV::ErrorLog __VA_ARGS__(__FILE__, __LINE__) 48 #define DebugLog(...) PV::DebugLog __VA_ARGS__(__FILE__, __LINE__) 49 #define StackTrace(...) PV::StackTrace __VA_ARGS__(__FILE__, __LINE__) 50 #define FatalIf(x, ...) \ 52 Fatal().printf(__VA_ARGS__); \ 72 std::ostream &getOutputStream();
79 std::ostream &getErrorStream();
84 std::wostream &getWOutputStream();
89 std::wostream &getWErrorStream();
97 static std::string prefix();
101 static bool output();
107 static bool flushOutputStream();
111 static bool prependPrefix();
114 static bool outputFileLine();
129 inline std::string InfoLogType::prefix() {
130 return std::string(
"INFO");
133 inline std::string WarnLogType::prefix() {
134 return std::string(
"WARN");
137 inline std::string FatalType::prefix() {
138 return std::string(
"ERROR");
141 inline std::string ErrorLogType::prefix() {
142 return std::string(
"ERROR");
145 inline std::string DebugLogType::prefix() {
146 return std::string(
"DEBUG");
149 inline std::string StackTraceType::prefix() {
150 return std::string(
"");
154 inline bool InfoLogType::output() {
158 inline bool WarnLogType::output() {
162 inline bool FatalType::output() {
166 inline bool ErrorLogType::output() {
170 inline bool StackTraceType::output() {
174 inline bool DebugLogType::output() {
175 #if defined(NDEBUG) || defined(PV_DEBUG_OUTPUT) 179 #endif // defined(NDEBUG) || defined(PV_DEBUG_OUTPUT) 183 inline bool InfoLogType::flushOutputStream() {
187 inline bool WarnLogType::flushOutputStream() {
191 inline bool FatalType::flushOutputStream() {
195 inline bool ErrorLogType::flushOutputStream() {
199 inline bool StackTraceType::flushOutputStream() {
203 inline bool DebugLogType::flushOutputStream() {
208 inline bool InfoLogType::prependPrefix() {
212 inline bool WarnLogType::prependPrefix() {
216 inline bool FatalType::prependPrefix() {
220 inline bool ErrorLogType::prependPrefix() {
224 inline bool StackTraceType::prependPrefix() {
228 inline bool DebugLogType::prependPrefix() {
233 inline bool InfoLogType::outputFileLine() {
237 inline bool WarnLogType::outputFileLine() {
241 inline bool FatalType::outputFileLine() {
245 inline bool ErrorLogType::outputFileLine() {
249 inline bool StackTraceType::outputFileLine() {
253 inline bool DebugLogType::outputFileLine() {
258 inline void InfoLogType::exit() {}
260 inline void WarnLogType::exit() {}
262 inline void FatalType::exit() {
263 ::exit(EXIT_FAILURE);
266 inline void ErrorLogType::exit() {}
268 inline void StackTraceType::exit() {}
270 inline void DebugLogType::exit() {}
273 template <
typename C,
typename LT,
typename T = std::
char_traits<C>>
275 typedef T char_traits;
278 typedef std::basic_ostream<C, T> &(*StrFunc)(std::basic_ostream<C, T> &);
279 static std::basic_ostream<C, T> &stream();
284 return getOutputStream();
288 return getWOutputStream();
292 return getErrorStream();
296 return getWErrorStream();
300 return getErrorStream();
304 return getWErrorStream();
308 return getErrorStream();
312 return getWErrorStream();
316 return getOutputStream();
320 return getWOutputStream();
324 return getErrorStream();
328 return getWErrorStream();
331 template <
typename C,
typename LT,
typename T = std::
char_traits<C>>
333 typedef std::basic_ostream<C, T> basic_ostream;
337 Log(
const char *file = __FILE__,
int line = __LINE__) : _stream(LogStreamType::stream()) {
338 outputPrefix(file, line);
341 Log(basic_ostream &s,
const char *file = __FILE__,
int line = __LINE__) : _stream(s) {
342 outputPrefix(file, line);
346 if (LogType::flushOutputStream()) {
352 void outputPrefix(
const char *file,
int line) {
354 if (LogType::output()) {
355 if (LogType::flushOutputStream()) {
356 getOutputStream().flush();
358 if (LogType::prependPrefix()) {
359 _stream << LogType::prefix() <<
" ";
361 if (LogType::outputFileLine()) {
362 _stream <<
"<" << basename((
char *)file) <<
":" << line <<
">: ";
367 template <
typename V>
368 Log &operator<<(V
const &value) {
369 if (LogType::output()) {
375 Log &operator<<(
typename LogStreamType::StrFunc func) {
376 if (LogType::output()) {
383 if (LogType::output()) {
400 if (LogType::output()) {
401 va_list args1, args2;
402 va_start(args1, fmt);
403 va_copy(args2, args1);
405 int chars_needed = vsnprintf(&c, 1, fmt, args1);
407 char output_string[chars_needed];
408 chars_printed = vsnprintf(output_string, chars_needed, fmt, args2);
409 _stream << output_string;
417 return chars_printed;
421 std::basic_ostream<C, T> &_stream;
459 void setLogFile(std::string
const &logFile, std::ios_base::openmode mode = std::ios_base::out);
460 void setLogFile(
char const *logFile, std::ios_base::openmode mode = std::ios_base::out);
461 void setWLogFile(std::wstring
const &logFile, std::ios_base::openmode mode = std::ios_base::out);
462 void setWLogFile(
char const *logFile, std::ios_base::openmode mode = std::ios_base::out);
int printf(char const *fmt,...)