|
|
|
@ -7,75 +7,118 @@
|
|
|
|
|
|
|
|
|
|
#include <cstring> // for strrchr()
|
|
|
|
|
|
|
|
|
|
namespace webcc {
|
|
|
|
|
#define WEBCC_VERB 0
|
|
|
|
|
#define WEBCC_INFO 1
|
|
|
|
|
#define WEBCC_WARN 2
|
|
|
|
|
#define WEBCC_ERRO 3
|
|
|
|
|
#define WEBCC_FATA 4
|
|
|
|
|
|
|
|
|
|
enum LogLevel {
|
|
|
|
|
VERB = 0,
|
|
|
|
|
INFO,
|
|
|
|
|
WARN,
|
|
|
|
|
ERRO,
|
|
|
|
|
FATA,
|
|
|
|
|
};
|
|
|
|
|
// Default log level.
|
|
|
|
|
#ifndef WEBCC_LOG_LEVEL
|
|
|
|
|
#define WEBCC_LOG_LEVEL WEBCC_WARN
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace webcc {
|
|
|
|
|
|
|
|
|
|
enum LogMode {
|
|
|
|
|
FLUSH = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void LogInit(int level, int modes);
|
|
|
|
|
void LogInit(int modes);
|
|
|
|
|
|
|
|
|
|
void LogWrite(int level, const char* file, int line, const char* format, ...);
|
|
|
|
|
|
|
|
|
|
} // namespace webcc
|
|
|
|
|
|
|
|
|
|
// Initialize the logger with a level.
|
|
|
|
|
// E.g., LOG_INIT(ERRO, FLUSH)
|
|
|
|
|
#define LOG_INIT(level, modes) webcc::LogInit(level, modes);
|
|
|
|
|
// E.g., LOG_INIT(FLUSH)
|
|
|
|
|
#define LOG_INIT(modes) webcc::LogInit(modes);
|
|
|
|
|
|
|
|
|
|
#if (defined(WIN32) || defined(_WIN64))
|
|
|
|
|
|
|
|
|
|
// See: https://stackoverflow.com/a/8488201
|
|
|
|
|
#define __FILENAME__ std::strrchr("\\" __FILE__, '\\') + 1
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_VERB
|
|
|
|
|
#define LOG_VERB(format, ...) \
|
|
|
|
|
webcc::LogWrite(webcc::VERB, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
webcc::LogWrite(WEBCC_VERB, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_VERB(format, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_INFO
|
|
|
|
|
#define LOG_INFO(format, ...) \
|
|
|
|
|
webcc::LogWrite(webcc::INFO, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
webcc::LogWrite(WEBCC_INFO, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_INFO(format, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_WARN
|
|
|
|
|
#define LOG_WARN(format, ...) \
|
|
|
|
|
webcc::LogWrite(webcc::WARN, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
webcc::LogWrite(WEBCC_WARN, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_WARN(format, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_ERRO
|
|
|
|
|
#define LOG_ERRO(format, ...) \
|
|
|
|
|
webcc::LogWrite(webcc::ERRO, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
webcc::LogWrite(WEBCC_ERRO, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_ERRO(format, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_FATA
|
|
|
|
|
#define LOG_FATA(format, ...) \
|
|
|
|
|
webcc::LogWrite(webcc::FATA, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
webcc::LogWrite(WEBCC_FATA, __FILENAME__, __LINE__, format, ##__VA_ARGS__);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_FATA(format, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// See: https://stackoverflow.com/a/8488201
|
|
|
|
|
#define __FILENAME__ std::strrchr("/" __FILE__, '/') + 1
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_VERB
|
|
|
|
|
#define LOG_VERB(format, args...) \
|
|
|
|
|
webcc::LogWrite(webcc::VERB, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
webcc::LogWrite(WEBCC_VERB, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_VERB(format, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_INFO
|
|
|
|
|
#define LOG_INFO(format, args...) \
|
|
|
|
|
webcc::LogWrite(webcc::INFO, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
webcc::LogWrite(WEBCC_INFO, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_INFO(format, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_WARN
|
|
|
|
|
#define LOG_WARN(format, args...) \
|
|
|
|
|
webcc::LogWrite(webcc::WARN, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
webcc::LogWrite(WEBCC_WARN, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_WARN(format, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_ERRO
|
|
|
|
|
#define LOG_ERRO(format, args...) \
|
|
|
|
|
webcc::LogWrite(webcc::ERRO, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
webcc::LogWrite(WEBCC_ERRO, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_ERRO(format, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if WEBCC_LOG_LEVEL <= WEBCC_FATA
|
|
|
|
|
#define LOG_FATA(format, args...) \
|
|
|
|
|
webcc::LogWrite(webcc::FATA, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
webcc::LogWrite(WEBCC_FATA, __FILENAME__, __LINE__, format, ##args);
|
|
|
|
|
#else
|
|
|
|
|
#define LOG_FATA(format, args...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // defined(WIN32) || defined(_WIN64)
|
|
|
|
|
|
|
|
|
|
#else // WEBCC_ENABLE_LOG == 0
|
|
|
|
|
|
|
|
|
|
#define LOG_INIT(level, modes)
|
|
|
|
|
#define LOG_INIT(modes)
|
|
|
|
|
|
|
|
|
|
#if (defined(WIN32) || defined(_WIN64))
|
|
|
|
|
#define LOG_VERB(format, ...)
|
|
|
|
|