2019-08-31 18:54:22 +00:00
|
|
|
|
#ifndef __EX_LOG_H__
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#define __EX_LOG_H__
|
|
|
|
|
|
|
|
|
|
#include "ex_types.h"
|
2017-01-08 15:53:37 +00:00
|
|
|
|
#include "ex_thread.h"
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
#define EX_LOG_LEVEL_DEBUG 0
|
|
|
|
|
#define EX_LOG_LEVEL_VERBOSE 1
|
|
|
|
|
#define EX_LOG_LEVEL_INFO 2
|
|
|
|
|
#define EX_LOG_LEVEL_WARN 3
|
|
|
|
|
#define EX_LOG_LEVEL_ERROR 4
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
#define EX_LOG_FILE_MAX_SIZE 1024*1024*10
|
|
|
|
|
#define EX_LOG_FILE_MAX_COUNT 10
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2017-01-08 15:53:37 +00:00
|
|
|
|
class ExLogger
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-11-01 18:50:49 +00:00
|
|
|
|
ExLogger();
|
|
|
|
|
~ExLogger();
|
2017-01-08 15:53:37 +00:00
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
bool set_log_file(const ex_wstr &log_path, const ex_wstr &log_name, ex_u32 max_filesize, ex_u8 max_count);
|
|
|
|
|
void log_a(int level, const char *fmt, va_list valist);
|
|
|
|
|
void log_w(int level, const wchar_t *fmt, va_list valist);
|
|
|
|
|
bool write_a(const char *buf);
|
|
|
|
|
bool write_w(const wchar_t *buf);
|
2017-01-08 15:53:37 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2020-11-01 18:50:49 +00:00
|
|
|
|
bool _open_file();
|
|
|
|
|
|
|
|
|
|
// 将现有日志文件改名备份,然后新开一个日志文件
|
|
|
|
|
bool _rotate_file();
|
2017-01-08 15:53:37 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2020-11-01 18:50:49 +00:00
|
|
|
|
ExThreadLock lock;
|
|
|
|
|
int min_level;
|
|
|
|
|
bool debug_mode;
|
|
|
|
|
bool to_console;
|
2017-01-08 15:53:37 +00:00
|
|
|
|
|
|
|
|
|
#ifdef EX_OS_WIN32
|
2020-11-01 18:50:49 +00:00
|
|
|
|
HANDLE console_handle;
|
2017-01-08 15:53:37 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-11-01 18:50:49 +00:00
|
|
|
|
ex_u32 m_filesize;
|
|
|
|
|
ex_u32 m_max_filesize;
|
|
|
|
|
ex_u8 m_max_count;
|
|
|
|
|
ex_wstr m_path;
|
|
|
|
|
ex_wstr m_filename;
|
|
|
|
|
ex_wstr m_fullname;
|
2017-01-08 15:53:37 +00:00
|
|
|
|
|
|
|
|
|
#ifdef EX_OS_WIN32
|
2020-11-01 18:50:49 +00:00
|
|
|
|
HANDLE m_file;
|
2017-01-08 15:53:37 +00:00
|
|
|
|
#else
|
2020-11-01 18:50:49 +00:00
|
|
|
|
FILE *m_file;
|
2017-01-08 15:53:37 +00:00
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
void EXLOG_USE_LOGGER(ExLogger *logger);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
|
|
|
|
void EXLOG_LEVEL(int min_level);
|
2017-04-09 16:36:38 +00:00
|
|
|
|
void EXLOG_DEBUG(bool debug_mode);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2019-08-31 18:54:22 +00:00
|
|
|
|
// 设定日志文件名及路径,如未指定路径,则为可执行程序所在目录下的log目录。
|
2020-11-01 18:50:49 +00:00
|
|
|
|
void EXLOG_FILE(const wchar_t *log_file, const wchar_t *log_path = nullptr, ex_u32 max_filesize = EX_LOG_FILE_MAX_SIZE, ex_u8 max_filecount = EX_LOG_FILE_MAX_COUNT);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
|
|
|
|
void EXLOG_CONSOLE(bool output_to_console);
|
|
|
|
|
|
2021-03-03 17:25:23 +00:00
|
|
|
|
#define EXLOGD ex_printf_d
|
2016-12-14 15:34:44 +00:00
|
|
|
|
#define EXLOGV ex_printf_v
|
|
|
|
|
#define EXLOGI ex_printf_i
|
|
|
|
|
#define EXLOGW ex_printf_w
|
|
|
|
|
#define EXLOGE ex_printf_e
|
|
|
|
|
#define EXLOG_BIN ex_printf_bin
|
|
|
|
|
|
|
|
|
|
#ifdef EX_OS_WIN32
|
|
|
|
|
#define EXLOGE_WIN ex_printf_e_lasterror
|
|
|
|
|
void ex_printf_e_lasterror(const char* fmt, ...);
|
|
|
|
|
void ex_printf_e_lasterror(const wchar_t* fmt, ...);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
void ex_printf_d(const char *fmt, ...);
|
|
|
|
|
void ex_printf_v(const char *fmt, ...);
|
|
|
|
|
void ex_printf_i(const char *fmt, ...);
|
|
|
|
|
void ex_printf_w(const char *fmt, ...);
|
|
|
|
|
void ex_printf_e(const char *fmt, ...);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
void ex_printf_d(const wchar_t *fmt, ...);
|
|
|
|
|
void ex_printf_v(const wchar_t *fmt, ...);
|
|
|
|
|
void ex_printf_i(const wchar_t *fmt, ...);
|
|
|
|
|
void ex_printf_w(const wchar_t *fmt, ...);
|
|
|
|
|
void ex_printf_e(const wchar_t *fmt, ...);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2020-11-01 18:50:49 +00:00
|
|
|
|
void ex_printf_bin(const ex_u8 *bin_data, size_t bin_size, const char *fmt, ...);
|
|
|
|
|
void ex_printf_bin(const ex_u8 *bin_data, size_t bin_size, const wchar_t *fmt, ...);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __EX_LOG_H__
|