aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Utils/je_log.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-29 08:27:51 +0800
committerchai <chaifix@163.com>2018-10-29 08:27:51 +0800
commitaca962d7ce3d404671cace2a82b04ff937375009 (patch)
treeec315ef9df3dbd971bc914dae689e97cf9cf31ff /src/libjin/Utils/je_log.h
parent297c78319e6bd891f27f9546334feedc030fc0a7 (diff)
*修改代码结构
Diffstat (limited to 'src/libjin/Utils/je_log.h')
-rw-r--r--src/libjin/Utils/je_log.h103
1 files changed, 18 insertions, 85 deletions
diff --git a/src/libjin/Utils/je_log.h b/src/libjin/Utils/je_log.h
index 928a009..aeb54d9 100644
--- a/src/libjin/Utils/je_log.h
+++ b/src/libjin/Utils/je_log.h
@@ -6,6 +6,8 @@
#include <fstream>
#include <stdarg.h>
+#include "../core/je_configuration.h"
+
class Loghelper
{
public:
@@ -21,7 +23,7 @@ public:
{
LV_NONE = 0, // none
LV_ERROR = 1 << 1, // error
- LV_WARN = 1 << 2, // warn
+ LV_WARNING = 1 << 2, // warn
LV_INFO = 1 << 3, // info
LV_DEBUG = 1 << 4, // debug
LV_ALL = 0xffffffff
@@ -43,89 +45,20 @@ private:
static std::ofstream fs; // ļ
};
-typedef Loghelper::Level Loglevel;
-
-#ifdef LOGHELPER_IMPLEMENT
-
-#define hasbit(flag, bit) ((flag & bit) == bit)
-
-unsigned int Loghelper::dir = Loghelper::Direction::DIR_CERR;
-unsigned int Loghelper::levels = Loghelper::Level::LV_ALL;
-std::ofstream Loghelper::fs;
-
-void Loghelper::log(Level _level, const char* _fmt, ...)
-{
- if (!hasbit(levels, _level))
- return;
-#define FORMAT_MSG_BUFFER_SIZE (204800)
- const char* levelStr = nullptr;
- switch (_level)
- {
- case LV_ERROR:
- levelStr = "[Jin Error]:";
- break;
- case LV_WARN:
- levelStr = "[Jin Warn]:";
- break;
- case LV_INFO:
- levelStr = "[Jin Info]:";
- break;
- case LV_DEBUG:
- levelStr = "[Jin Debug]:";
- break;
- default:
- levelStr = "[Jin Unknown]:";
- break;
- }
- char buffer[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
- strcpy(buffer, levelStr);
- va_list args;
- va_start(args, _fmt);
- vsnprintf(buffer + strlen(buffer), FORMAT_MSG_BUFFER_SIZE, _fmt, args);
- va_end(args);
- if (hasbit(dir, DIR_CERR))
- {
- std::cerr << buffer << std::endl;
- }
- if (hasbit(dir, DIR_FILE))
- {
- fs << buffer << std::endl;
- }
-#undef FORMAT_MSG_BUFFER_SIZE
-}
-// ض
-void Loghelper::redirect(unsigned int _dir, char* _path)
-{
- dir = _dir;
- if (hasbit(dir, DIR_FILE))
- {
- try
- {
- fs.open(_path, std::ios_base::app);
- }
- catch (std::ios_base::failure& e) {
- dir = DIR_CERR;
- log(Level::LV_WARN, "ضlog· %s ʧ", _path);
- }
- }
-}
-
-// ɸѡȼ
-void Loghelper::restrict(unsigned int _levels)
-{
- levels = _levels;
-}
-
-void Loghelper::close()
-{
- if (!fs.fail())
- fs.close();
- fs.clear();
-}
-
-#undef hasbit
-
-#endif
+typedef Loghelper::Level Loglevel;
-#endif \ No newline at end of file
+#if defined(jin_debug)
+ #define jin_log_error(f, ...) Loghelper::log(Loghelper::LV_ERROR, f, __VA_ARGS__)
+ #define jin_log_info(f, ...) Loghelper::log(Loghelper::LV_INFO, f, __VA_ARGS__)
+ #define jin_log_warning(f, ...) Loghelper::log(Loghelper::LV_WARNING, f, __VA_ARGS__)
+ #define jin_log_debug(f, ...) Loghelper::log(Loghelper::LV_DEBUG, f, __VA_ARGS__)
+#else
+ #define jin_debug_log(level, fmt, ...)
+ #define jin_log_error(f, ...)
+ #define jin_log_info(f, ...)
+ #define jin_log_warning(f, ...)
+ #define jin_log_debug(f, ...)
+#endif
+
+#endif // __LOG_HELPER_H \ No newline at end of file