mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
新增C API 广播日志到上层应用
This commit is contained in:
parent
d2f02c0a0c
commit
5bd169e6de
@ -48,6 +48,8 @@ typedef struct {
|
|||||||
const char *log_file_path;
|
const char *log_file_path;
|
||||||
//文件日志保存天数,设置为0关闭日志文件
|
//文件日志保存天数,设置为0关闭日志文件
|
||||||
int log_file_days;
|
int log_file_days;
|
||||||
|
// 是否关闭 控制台 日志
|
||||||
|
int disable_console_log;
|
||||||
|
|
||||||
// 配置文件是内容还是路径
|
// 配置文件是内容还是路径
|
||||||
int ini_is_path;
|
int ini_is_path;
|
||||||
@ -94,6 +96,29 @@ API_EXPORT void API_CALL mk_env_init1(int thread_num,
|
|||||||
int ssl_is_path,
|
int ssl_is_path,
|
||||||
const char *ssl,
|
const char *ssl,
|
||||||
const char *ssl_pwd);
|
const char *ssl_pwd);
|
||||||
|
/**
|
||||||
|
* 基础类型参数版本的mk_env_init,为了方便其他语言调用
|
||||||
|
* @param thread_num 线程数
|
||||||
|
* @param log_level 日志级别,支持0~4
|
||||||
|
* @param log_file_path 文件日志保存路径,路径可以不存在(内部可以创建文件夹),设置为NULL关闭日志输出至文件
|
||||||
|
* @param log_file_days 文件日志保存天数,设置为0关闭日志文件
|
||||||
|
* @param ini_is_path 配置文件是内容还是路径
|
||||||
|
* @param ini 配置文件内容或路径,可以为NULL,如果该文件不存在,那么将导出默认配置至该文件
|
||||||
|
* @param ssl_is_path ssl证书是内容还是路径
|
||||||
|
* @param ssl ssl证书内容或路径,可以为NULL
|
||||||
|
* @param ssl_pwd 证书密码,可以为NULL
|
||||||
|
* @param disable_console_log 是否关闭 控制台 日志
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置配置项
|
* 设置配置项
|
||||||
|
@ -152,6 +152,18 @@ typedef struct {
|
|||||||
size_t total_seconds,
|
size_t total_seconds,
|
||||||
int is_player,
|
int is_player,
|
||||||
const mk_sock_info sender);
|
const mk_sock_info sender);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志输出广播
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param file 源文件名
|
||||||
|
* @param line 源文件行
|
||||||
|
* @param function 源文件方法
|
||||||
|
* @param message 日志内容
|
||||||
|
*/
|
||||||
|
void (API_CALL *on_mk_log)(int level, const char* file, int line, const char *function, const char* message);
|
||||||
|
|
||||||
} mk_events;
|
} mk_events;
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ static std::shared_ptr<RtpServer> rtpServer;
|
|||||||
//////////////////////////environment init///////////////////////////
|
//////////////////////////environment init///////////////////////////
|
||||||
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
||||||
assert(cfg);
|
assert(cfg);
|
||||||
mk_env_init1(cfg->thread_num,
|
mk_env_init2(cfg->thread_num,
|
||||||
cfg->log_level,
|
cfg->log_level,
|
||||||
cfg->log_file_path,
|
cfg->log_file_path,
|
||||||
cfg->log_file_days,
|
cfg->log_file_days,
|
||||||
@ -45,7 +45,8 @@ API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
|||||||
cfg->ini,
|
cfg->ini,
|
||||||
cfg->ssl_is_path,
|
cfg->ssl_is_path,
|
||||||
cfg->ssl,
|
cfg->ssl,
|
||||||
cfg->ssl_pwd);
|
cfg->ssl_pwd,
|
||||||
|
cfg->disable_console_log);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void stopAllTcpServer();
|
extern void stopAllTcpServer();
|
||||||
@ -69,10 +70,39 @@ API_EXPORT void API_CALL mk_env_init1(int thread_num,
|
|||||||
int ssl_is_path,
|
int ssl_is_path,
|
||||||
const char *ssl,
|
const char *ssl,
|
||||||
const char *ssl_pwd) {
|
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([&]() {
|
static onceToken token([&]() {
|
||||||
//控制台日志
|
if(disable_console_log) {
|
||||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) log_level));
|
// 广播日志
|
||||||
|
Logger::Instance().add(std::make_shared<EventChannel>("EventChannel", (LogLevel) log_level));
|
||||||
|
} else {
|
||||||
|
//控制台日志
|
||||||
|
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel", (LogLevel) log_level));
|
||||||
|
}
|
||||||
if(log_file_path && log_file_days){
|
if(log_file_path && log_file_days){
|
||||||
//日志文件
|
//日志文件
|
||||||
auto channel = std::make_shared<FileChannel>("FileChannel", File::absolutePath(log_file_path, ""), (LogLevel) log_level);
|
auto channel = std::make_shared<FileChannel>("FileChannel", File::absolutePath(log_file_path, ""), (LogLevel) log_level);
|
||||||
|
@ -151,6 +151,12 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||||||
s_events.on_mk_media_no_reader((mk_media_source) &sender);
|
s_events.on_mk_media_no_reader((mk_media_source) &sender);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
NoticeCenter::Instance().addListener(&s_tag, Broadcast::kBroadcastLog,[](BroadcastLogArgs){
|
||||||
|
if (s_events.on_mk_log) {
|
||||||
|
s_events.on_mk_log((int)level, file, line, function, message);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ const string kBroadcastShellLogin = "kBroadcastShellLogin";
|
|||||||
const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
|
const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
|
||||||
const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader";
|
const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader";
|
||||||
const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess";
|
const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess";
|
||||||
|
const string kBroadcastLog = "kBroadcastEventLog";
|
||||||
} //namespace Broadcast
|
} //namespace Broadcast
|
||||||
|
|
||||||
//通用配置项目
|
//通用配置项目
|
||||||
|
@ -105,6 +105,10 @@ extern const string kBroadcastStreamNoneReader;
|
|||||||
extern const string kBroadcastReloadConfig;
|
extern const string kBroadcastReloadConfig;
|
||||||
#define BroadcastReloadConfigArgs void
|
#define BroadcastReloadConfigArgs void
|
||||||
|
|
||||||
|
//日志输出广播,目的是为了通过C API运行时,由上级程序打印日志
|
||||||
|
extern const string kBroadcastLog;
|
||||||
|
#define BroadcastLogArgs const LogLevel level, const char* file, int line, const char* function, const char* message
|
||||||
|
|
||||||
#define ReloadConfigTag ((void *)(0xFF))
|
#define ReloadConfigTag ((void *)(0xFF))
|
||||||
#define RELOAD_KEY(arg,key) \
|
#define RELOAD_KEY(arg,key) \
|
||||||
do { \
|
do { \
|
||||||
|
Loading…
Reference in New Issue
Block a user