支持HAND_LOG2

This commit is contained in:
fengweihao
2020-09-28 16:59:41 +08:00
parent 05f5154bbc
commit 669783973c
5 changed files with 53 additions and 10 deletions

View File

@@ -30,18 +30,19 @@ void mesa_logging_print(int log_level, const char *module, const char *msg)
void * verify_syslog_init(const char *config)
{
char run_log_path[256] = {0};
MESA_load_profile_int_def(config, (const char *)"SYSTEM",(const char *)"DEBUG_SWITCH",
&logging_sc_lid.debug_switch, 1);
MESA_load_profile_int_def(config, (const char *)"SYSTEM",(const char *)"RUN_LOG_LEVEL",
&logging_sc_lid.run_log_level, 10);
MESA_load_profile_string_def(config, (const char *)"SYSTEM",(const char *)"RUN_LOG_PATH",
logging_sc_lid.run_log_path, 128, NULL);
logging_sc_lid.run_log_path, 128, "conf/zlog.conf");
snprintf(run_log_path, 255, "%s/%s", logging_sc_lid.run_log_path, "verify_policy.log");
if (0 != MESA_handle_runtime_log_creation(logging_sc_lid.run_log_path))
{
fprintf(stderr, "Create log runtime_log_handle error, init failed\n");
goto finish;
}
logging_sc_lid.run_log_handle = MESA_create_runtime_log_handle(run_log_path, logging_sc_lid.run_log_level);
logging_sc_lid.run_log_handle = MESA_create_runtime_log_handle("./logs", RLOG_LV_DEBUG);
if(logging_sc_lid.run_log_handle == NULL){
mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Create log runtime_log_handle error, init failed!");
goto finish;

View File

@@ -4,6 +4,13 @@ DEBUG_SWITCH = 1
#10:DEBUG, 20:INFO, 30:FATAL
RUN_LOG_LEVEL = 10
RUN_LOG_PATH = ./logs
disable_coredump=0
enable_breakpad=1
breakpad_minidump_dir="/tmp/verify-policy/crashreport"
enable_breakpad_upload=0
breakpad_upload_url="http://127.0.0.1/"
[CONFIG]
#Number of running threads
thread-nu = 4

11
conf/zlog.conf Normal file
View File

@@ -0,0 +1,11 @@
[global]
default format = "%d(%c), %V, %F, %U, %m%n"
[levels]
DEBUG=10
INFO=20
FATAL=30
[rules]
*.fatal "./logs/error.log.%d(%F)";
*.debug "./logs/verify_policy.log.%d(%F)"
!*.info "./logs/verify_policy.log.%d(%F)"

View File

@@ -11,7 +11,6 @@ target_link_libraries(verify-policy pthread dl
libevent-static
MESA_handle_logger
MESA_prof_load
gperftools-static
breakpad-client-static
cjson
${SYSTEMD_LIBRARIES})

View File

@@ -47,6 +47,8 @@ const char * version()
return git_ver;
}
static int signals[] = {SIGHUP, SIGPIPE, SIGUSR1};
extern int pangu_policy_init(struct verify_policy * verify, const char* profile_path);
static int verify_policy_init(struct verify_policy * verify, const char *profile)
@@ -824,6 +826,24 @@ struct breakpad_instance * breakpad_init(const char * profile)
return instance;
}
void __signal_handler_cb(int sig)
{
switch (sig)
{
case SIGHUP:
mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Reload log config");
MESA_handle_runtime_log_reconstruction(NULL);
break;
case SIGPIPE:
break;
case SIGUSR1:
case SIGINT:
break;
default:
break;
}
}
int main(int argc, char * argv[])
{
const char * main_profile = "./conf/verify_policy.conf";
@@ -870,6 +890,11 @@ int main(int argc, char * argv[])
g_verify_proxy->breakpad = breakpad_init(main_profile);
CHECK_OR_EXIT(g_verify_proxy->breakpad, "Failed at starting breakpad. Exit.");
for (size_t i = 0; i < (sizeof(signals) / sizeof(int)); i++)
{
signal(signals[i], __signal_handler_cb);
}
ret = pangu_policy_work_thread_run(g_verify_proxy);
return ret;