Logging.
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
|
||||
inline std::string basedir(const std::string &path)
|
||||
{
|
||||
int idx1 = path.rfind("/");
|
||||
int idx2 = path.rfind("\\");
|
||||
int idx1 = static_cast<int>(path.rfind("/"));
|
||||
int idx2 = static_cast<int>(path.rfind("\\"));
|
||||
std::string r;
|
||||
if (idx1 == std::string::npos && idx2 == std::string::npos) {
|
||||
r = "";
|
||||
@@ -26,4 +26,33 @@ inline std::string basedir(const std::string &path)
|
||||
return r;
|
||||
}
|
||||
|
||||
int logLevel();
|
||||
void setLogLevel(int l);
|
||||
const char *logIndicator(int l);
|
||||
|
||||
#define LOG_ERROR 1
|
||||
#define LOG_WARNING 2
|
||||
#define LOG_INFO 3
|
||||
#define LOG_DEBUG 4
|
||||
|
||||
#define MKLOGSTMT(level, code) if (logLevel() >= level) { fprintf(stderr, "%s: ", logIndicator(level));code;fflush(stderr); }
|
||||
#define MKL0(level, msg) MKLOGSTMT(level, fprintf(stderr, msg))
|
||||
#define MKL1(level, msg, a) MKLOGSTMT(level, fprintf(stderr, msg, a))
|
||||
#define MKL2(level, msg, a, b) MKLOGSTMT(level, fprintf(stderr, msg, a, b))
|
||||
|
||||
#define ERROR0(msg) MKL0(LOG_ERROR, msg)
|
||||
#define WARN0(msg) MKL0(LOG_WARNING, msg)
|
||||
#define INFO0(msg) MKL0(LOG_INFO, msg)
|
||||
#define DEBUG0(msg) MKL0(LOG_DEBUG, msg)
|
||||
|
||||
#define ERROR1(msg, a) MKL1(LOG_ERROR, msg, a)
|
||||
#define WARN1(msg, a) MKL1(LOG_WARNING, msg, a)
|
||||
#define INFO1(msg, a) MKL1(LOG_INFO, msg, a)
|
||||
#define DEBUG1(msg, a) MKL1(LOG_DEBUG, msg, a)
|
||||
|
||||
#define ERROR2(msg, a, b) MKL2(LOG_ERROR, msg, a, b)
|
||||
#define WARN2(msg, a, b) MKL2(LOG_WARNING, msg, a, b)
|
||||
#define INFO2(msg, a, b) MKL2(LOG_INFO, msg, a, b)
|
||||
#define DEBUG2(msg, a, b) MKL2(LOG_DEBUG, msg, a, b)
|
||||
|
||||
#endif // UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user