合并日志相关pr: #1077

This commit is contained in:
ziyue
2021-08-30 20:43:03 +08:00
parent 7d456a0513
commit 57e91054af
11 changed files with 43 additions and 73 deletions

View File

@@ -35,18 +35,19 @@ static std::shared_ptr<RtpServer> rtpServer;
#endif
//////////////////////////environment init///////////////////////////
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
assert(cfg);
mk_env_init2(cfg->thread_num,
mk_env_init1(cfg->thread_num,
cfg->log_level,
cfg->log_mask,
cfg->log_file_path,
cfg->log_file_days,
cfg->ini_is_path,
cfg->ini,
cfg->ssl_is_path,
cfg->ssl,
cfg->ssl_pwd,
cfg->disable_console_log);
cfg->ssl_pwd);
}
extern void stopAllTcpServer();
@@ -63,6 +64,7 @@ API_EXPORT void API_CALL mk_stop_all_server(){
API_EXPORT void API_CALL mk_env_init1(int thread_num,
int log_level,
int log_mask,
const char *log_file_path,
int log_file_days,
int ini_is_path,
@@ -70,42 +72,24 @@ API_EXPORT void API_CALL mk_env_init1(int thread_num,
int ssl_is_path,
const char *ssl,
const char *ssl_pwd) {
mk_env_init2(
thread_num,
log_level,
log_file_path,
log_file_days,
ini_is_path,
ini,
ssl_is_path,
ssl,
ssl_pwd,
0
);
}
API_EXPORT void API_CALL mk_env_init2(int thread_num,
int log_level,
const char *log_file_path,
int log_file_days,
int ini_is_path,
const char *ini,
int ssl_is_path,
const char *ssl,
const char *ssl_pwd,
int disable_console_log) {
//确保只初始化一次
static onceToken token([&]() {
if(disable_console_log) {
// 广播日志
Logger::Instance().add(std::make_shared<EventChannel>("EventChannel", (LogLevel) log_level));
} else {
if (log_mask & LOG_CONSOLE) {
//控制台日志
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel", (LogLevel) log_level));
}
if(log_file_path && log_file_days){
if (log_mask & LOG_CALLBACK) {
//广播日志
Logger::Instance().add(std::make_shared<EventChannel>("EventChannel", (LogLevel) log_level));
}
if (log_mask & LOG_FILE) {
//日志文件
auto channel = std::make_shared<FileChannel>("FileChannel", File::absolutePath(log_file_path, ""), (LogLevel) log_level);
auto channel = std::make_shared<FileChannel>("FileChannel",
log_file_path ? File::absolutePath(log_file_path, "") :
exeDir() + "log/", (LogLevel) log_level);
channel->setMaxDay(log_file_days ? log_file_days : 1);
Logger::Instance().add(channel);
}