OpenGTA/util/log.h

76 lines
1.9 KiB
C
Raw Permalink Normal View History

2015-12-03 00:37:02 +00:00
#ifndef LOG_FUNCS_H
#define LOG_FUNCS_H
#include <iostream>
#ifdef WIN32
#undef ERROR
#endif
#define INFO Util::Log::info(__FILE__, __LINE__)
#define WARN Util::Log::warn(__FILE__, __LINE__)
#define ERROR Util::Log::error(__FILE__, __LINE__)
#define ERROR_AND_EXIT(ec) error_code = ec; exit(ec);
#define GL_CHECKERROR { int _err = glGetError(); if (_err != GL_NO_ERROR) \
Util::Log::error(__FILE__, __LINE__) << "GL error: " << _err << " = " << Util::Log::glErrorName(_err) << std::endl; }
2015-12-03 00:38:22 +00:00
#define ANSI_COLOR_OFF "\033[0m"
#define ANSI_COLOR_INFO "\033[32mInfo ("
#define ANSI_COLOR_WARN "\033[33mWarning ("
#define ANSI_COLOR_ERR "\033[31mError ("
2015-12-03 00:37:02 +00:00
namespace Util {
class Log {
public:
inline static std::ostream & info(const char* f, int l) {
2015-12-03 00:38:22 +00:00
if (level) return emptyStream;
#ifdef LOG_USE_ANSI_COLORS
std::cout << ANSI_COLOR_INFO <<
#else
std::cout << "Info (" <<
#endif
f << ":" << l << "): "
#ifdef LOG_USE_ANSI_COLORS
<< ANSI_COLOR_OFF;
#else
;
#endif
return std::cout;
2015-12-03 00:37:02 +00:00
}
inline static std::ostream & warn(const char* f, int l) {
2015-12-03 00:38:22 +00:00
if (level > 1) return emptyStream;
#ifdef LOG_USE_ANSI_COLORS
std::cerr << ANSI_COLOR_WARN <<
#else
std::cerr << "Warning (" <<
#endif
f << ":" << l << "): "
#ifdef LOG_USE_ANSI_COLORS
<< ANSI_COLOR_OFF;
#else
;
#endif
return std::cerr;
2015-12-03 00:37:02 +00:00
}
inline static std::ostream & error(const char* f, int l) {
2015-12-03 00:38:22 +00:00
#ifdef LOG_USE_ANSI_COLORS
std::cerr << ANSI_COLOR_ERR <<
#else
std::cerr << "Error (" <<
#endif
f << ":" << l << "): "
#ifdef LOG_USE_ANSI_COLORS
<< ANSI_COLOR_OFF;
#else
;
#endif
return std::cerr;
2015-12-03 00:37:02 +00:00
}
static void setOutputLevel(unsigned int newLevel);
static const char* glErrorName(int k);
private:
static unsigned int level;
static std::ostream emptyStream;
};
}
#endif