Separate debug log with info config
[platform/core/connectivity/stc-manager.git] / src / stc-manager-util.c
old mode 100644 (file)
new mode 100755 (executable)
index 51dbd4f..1f25927
 
 #include "stc-manager-util.h"
 
-static int g_debuglog = -1;
+typedef struct {
+       int state;
+       char *key;
+} log_info_s;
+
+log_info_s g_log_info[] = {
+       {-1, INFO_DEBUG_LOG},
+       {-1, INFO_STAT_LOG},
+       {-1, INFO_RSTN_LOG},
+       {-1, INFO_FW_LOG},
+       {-1, INFO_PCAP_LOG},
+};
 
 static void __sync_file_to_disk(const char *path)
 {
@@ -128,31 +139,46 @@ int stc_util_get_config_int(char *key)
 }
 
 //LCOV_EXCL_START
-API void stc_util_set_debuglog(int debuglog)
+API void stc_util_update_log_state(void)
 {
-       g_debuglog = debuglog;
+       int i;
+
+       for (i = DEBUG_LOG_INFO; i < MAX_LOG_INFO; ++i)
+               g_log_info[i].state = stc_util_get_config_int(g_log_info[i].key);
+
+       STC_LOGD("log info [%d:%d:%d:%d:%d]",
+               g_log_info[DEBUG_LOG_INFO].state, g_log_info[STAT_LOG_INFO].state,
+               g_log_info[RSTN_LOG_INFO].state, g_log_info[FW_LOG_INFO].state,
+               g_log_info[PCAP_LOG_INFO].state);
+}
+
+API void stc_util_set_log_state(log_info_e info, int state)
+{
+       g_log_info[info].state = state;
 }
 //LCOV_EXCL_STOP
 
-API int stc_util_get_debuglog(void)
+API int stc_util_get_log_state(log_info_e info)
 {
-       if (g_debuglog == -1)
-               g_debuglog = stc_util_get_config_int(INFO_DEBUGLOG);
+       if (g_log_info[info].state == -1)
+               g_log_info[info].state = stc_util_get_config_int(g_log_info[info].key);
 
-       return g_debuglog;
+       return g_log_info[info].state;
 }
 
 void stc_util_initialize_config(void)
 {
        char path[MAX_PATH_LENGTH];
        GKeyFile *keyfile;
+       int i;
 
        snprintf(path, sizeof(path), "%s/%s", INFO_STORAGE_DIR, INFO_CONFIG);
 
        keyfile = __load_key_file(path);
        if (!keyfile) {
                keyfile = g_key_file_new(); //LCOV_EXCL_LINE
-               g_key_file_set_integer(keyfile, path, INFO_DEBUGLOG, 0);
+               for (i = DEBUG_LOG_INFO; i < MAX_LOG_INFO; ++i)
+                       g_key_file_set_integer(keyfile, path, g_log_info[i].key, 0);
        }
 
        __save_key_file(keyfile, path);