aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/utils/je_log.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/utils/je_log.h')
-rw-r--r--src/libjin/utils/je_log.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/libjin/utils/je_log.h b/src/libjin/utils/je_log.h
new file mode 100644
index 0000000..f81bbae
--- /dev/null
+++ b/src/libjin/utils/je_log.h
@@ -0,0 +1,63 @@
+#ifndef __LOG_H__ELPER_H__
+#define __LOG_H__ELPER_H__
+
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <stdarg.h>
+
+#include "../core/je_configuration.h"
+
+class Loghelper
+{
+public:
+ // logĿ
+ enum Direction
+ {
+ DIR_CERR = 1 << 1, // ׼
+ DIR_FILE = 1 << 2, // logļ
+ };
+
+ // ȼ
+ enum Level
+ {
+ LV_NONE = 0, // none
+ LV_ERROR = 1 << 1, // error
+ LV_WARNING = 1 << 2, // warn
+ LV_INFO = 1 << 3, // info
+ LV_DEBUG = 1 << 4, // debug
+ LV_ALL = 0xffffffff
+ };
+
+ static void log(Level _level, const char* _fmt, ...);
+
+ // ض
+ static void redirect(unsigned int _dir, char* _path = nullptr);
+
+ // ɸѡȼ
+ static void restrict(unsigned int levels);
+
+ static void close();
+
+private:
+ static unsigned int dir; // Ŀ
+ static unsigned int levels; // ȼ
+ static std::ofstream fs; // ļ
+};
+
+
+typedef Loghelper::Level Loglevel;
+
+#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_log_error(f, ...)
+ #define jin_log_info(f, ...)
+ #define jin_log_warning(f, ...)
+ #define jin_log_debug(f, ...)
+#endif
+
+#endif // __LOG_H__ELPER_H__ \ No newline at end of file