12
12
#endif
13
13
14
14
// 调试日志
15
- #define LOG4CPLUSPLUS_DEBUG (...)\
15
+ #define LOG4CPLUSPLUS_DEBUG (pLog4CPlusPlus, ...)\
16
16
{\
17
- GetLog4CPlusPlusInstance ()->WriteLog (log4cplus::LogDebugLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
17
+ if (pLog4CPlusPlus)\
18
+ {\
19
+ pLog4CPlusPlus->WriteLog (log4cplus::LogDebugLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
20
+ }\
18
21
}
19
22
20
23
// 普通日志
21
- #define LOG4CPLUSPLUS_INFO (...)\
24
+ #define LOG4CPLUSPLUS_INFO (pLog4CPlusPlus, ...)\
22
25
{\
23
- GetLog4CPlusPlusInstance ()->WriteLog (log4cplus::LogInfoLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
26
+ if (pLog4CPlusPlus)\
27
+ {\
28
+ pLog4CPlusPlus->WriteLog (log4cplus::LogInfoLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
29
+ }\
24
30
}
25
31
26
32
// 警告日志
27
- #define LOG4CPLUSPLUS_WARN (...)\
33
+ #define LOG4CPLUSPLUS_WARN (pLog4CPlusPlus, ...)\
28
34
{\
29
- GetLog4CPlusPlusInstance ()->WriteLog (log4cplus::LogWarnLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
35
+ if (pLog4CPlusPlus)\
36
+ {\
37
+ pLog4CPlusPlus->WriteLog (log4cplus::LogWarnLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
38
+ }\
30
39
}
31
40
32
41
// 错误日志
33
- #define LOG4CPLUSPLUS_ERROR (...)\
42
+ #define LOG4CPLUSPLUS_ERROR (pLog4CPlusPlus, ...)\
34
43
{\
35
- GetLog4CPlusPlusInstance ()->WriteLog (log4cplus::LogErrorLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
44
+ if (pLog4CPlusPlus)\
45
+ {\
46
+ pLog4CPlusPlus->WriteLog (log4cplus::LogErrorLevel, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);\
47
+ }\
36
48
}
37
49
38
- #define DEFALT_LOG_FILE_NAME L" log.log"
50
+ #define DEFALT_LOG_FILE_PATH L" " // 默认日志文件路径
51
+ #define DEFALT_LOG_FILE_NAME L" log.log" // 默认日志文件名
52
+ #define DEFALT_MAX_FILE_SIZE 10 * 1024 * 1024 // 默认最大文件大小
53
+ #define DEFALT_MAX_FILE_COUNT 100 // 默认最大文件备份数量
54
+ #define DEFALT_IS_ASYNC true // 默认异步
55
+ #define DEFALT_MAX_DAYS_COUNT 15 // 默认最多保留日志天数
39
56
40
57
namespace log4cplus
41
58
{
@@ -50,30 +67,45 @@ namespace log4cplus
50
67
class Log4CPlusPlus
51
68
{
52
69
public:
70
+ Log4CPlusPlus () {}
53
71
virtual ~Log4CPlusPlus () {}
54
72
55
73
public:
56
74
/*
57
- 初始化日志
75
+ 释放日志资源
76
+ */
77
+ virtual void Release () = 0;
78
+
79
+ /*
80
+ 添加文件附加器
58
81
* file_path 日志基础文件路径,如传入 D:\\code,最终生成 D:\\code\\log\2020円-6-4\\
59
82
* file_name 日志文件名,如 log.log
83
+ * max_file_size 最大文件大小
84
+ * max_file_count 最大文件数
85
+ * is_async 是否异步
60
86
*/
61
- virtual void Init (const wchar_t *file_path = L" " , const wchar_t *file_name = DEFALT_LOG_FILE_NAME) = 0;
62
-
87
+ virtual void AddFileAppender (
88
+ const wchar_t *file_path = DEFALT_LOG_FILE_PATH,
89
+ const wchar_t *file_name = DEFALT_LOG_FILE_NAME,
90
+ unsigned long max_file_size = DEFALT_MAX_FILE_SIZE,
91
+ unsigned long max_file_count = DEFALT_MAX_FILE_COUNT,
92
+ bool is_async = DEFALT_IS_ASYNC
93
+ ) = 0;
94
+
63
95
/*
64
- 反初始化日志
96
+ 启用调试器附加器,如 VS调试窗口
65
97
*/
66
- virtual void UnInit ( ) = 0;
98
+ virtual void EnableDebuggerAppender ( bool enable ) = 0;
67
99
68
100
/*
69
- 日志同时输出到调试器 ,如 VS调试窗口
101
+ 启用控制台附加器 ,如 cmd
70
102
*/
71
- virtual void EnableDebuggerOutput (bool enable) = 0;
103
+ virtual void EnableConsoleAppender (bool enable) = 0;
72
104
73
105
/*
74
- 日志同时输出到控制台,如 cmd
106
+ 获取日志的路径
75
107
*/
76
- virtual void EnableConsoleOutput ( bool enable ) = 0;
108
+ virtual const wchar_t * GetLogPath ( ) = 0;
77
109
78
110
/*
79
111
打印日志,支持格式化字符串
@@ -83,18 +115,16 @@ namespace log4cplus
83
115
* function 打印日志代码所在的类及方法
84
116
* format, ... 格式化字符串,如 L"Hello %s %d", L"World", 123
85
117
*/
86
- virtual void WriteLog (Log4CPlusPlusLevel logLevel, const char * file, int line, const char * function, const wchar_t *format, ...) = 0;
87
-
88
- protected:
89
- Log4CPlusPlus () {}
90
-
91
- private:
92
- Log4CPlusPlus (const Log4CPlusPlus&) = delete ;
93
- Log4CPlusPlus& operator = (const Log4CPlusPlus&) = delete ;
118
+ virtual void WriteLog (
119
+ Log4CPlusPlusLevel logLevel,
120
+ const char * file,
121
+ int line,
122
+ const char * function,
123
+ const wchar_t *format, ...) = 0;
94
124
95
125
};
96
126
}
97
127
98
- extern " C" LOG4CPLUSPLUS_API log4cplus::Log4CPlusPlus* __cdecl GetLog4CPlusPlusInstance ();
128
+ extern " C" LOG4CPLUSPLUS_API log4cplus::Log4CPlusPlus* __cdecl CreateLog4CPlusPlus ();
99
129
100
- #endif // _LOG4CPLUSPLUS_H_
130
+ #endif // _LOG4CPLUSPLUS_H_
0 commit comments