合并日志相关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);
}

View File

@@ -20,13 +20,13 @@ static void* s_tag;
static mk_events s_events = {0};
API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
if(events){
memcpy(&s_events,events, sizeof(s_events));
}else{
memset(&s_events,0,sizeof(s_events));
if (events) {
memcpy(&s_events, events, sizeof(s_events));
} else {
memset(&s_events, 0, sizeof(s_events));
}
static onceToken tokne([]{
static onceToken token([]{
NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastMediaChanged,[](BroadcastMediaChangedArgs){
if(s_events.on_mk_media_changed){
s_events.on_mk_media_changed(bRegist,
@@ -152,9 +152,10 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
}
});
NoticeCenter::Instance().addListener(&s_tag, Broadcast::kBroadcastLog,[](BroadcastLogArgs){
NoticeCenter::Instance().addListener(&s_tag, EventChannel::kBroadcastLogEvent,[](BroadcastLogEventArgs){
if (s_events.on_mk_log) {
s_events.on_mk_log((int)level, file, line, function, message);
auto log = ctx->str();
s_events.on_mk_log((int) ctx->_level, ctx->_file.data(), ctx->_line, ctx->_function.data(), log.data());
}
});
});