[Feature][T106BUG-76] add log level control apis
Only Configure:No
Affected branch:master
Affected module:log
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: Yes
Change-Id: Ieec1d80443eb3772121fbc50e3bd68f1716337e2
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-log/include/liblog/liblog.h b/cap/zx297520v3/src/lynq/lib/liblynq-log/include/liblog/liblog.h
index 57c9c98..d1ca261 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-log/include/liblog/liblog.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-log/include/liblog/liblog.h
@@ -1,13 +1,16 @@
#ifndef __LIBLOG_H__
#define __LIBLOG_H__
+#include <unistd.h>
+
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
- LOG_VERBOSE = 0,
+ LOG_UNSET = -1,
+ LOG_VERBOSE = 0,
LOG_ERROR,
LOG_WARNING,
LOG_INFO,
@@ -18,6 +21,14 @@
void lynq_log_global_output(log_level_enum Level,const char *format,...);
void lynq_log_configuration_init(const char *log_name);
const char* lynq_read_log_version();
+
+//log level api
+int lynq_set_log_level(const char * module_name, log_level_enum level);
+int lynq_get_log_level(const char * module_name, log_level_enum *level);
+int lynq_set_special_log_level(const char * exe_name, const char * module_name, log_level_enum level);
+int lynq_get_special_log_level(const char * exe_name, const char * module_name, log_level_enum *level);
+int lynq_notify_recalc_log_level(pid_t pid);
+
#ifdef __cplusplus
}
#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-log/log-riltel/log.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-log/log-riltel/log.cpp
index 3b35553..581fee8 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-log/log-riltel/log.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-log/log-riltel/log.cpp
@@ -30,28 +30,28 @@
log_module_entry() // constuctor of struct
{
level = LOG_INFO; // default log level when no uci value
- special_level = LOG_LEVEL_MAX;
- lib_level = LOG_LEVEL_MAX;
- exe_level = LOG_LEVEL_MAX;
- global_level = LOG_LEVEL_MAX;
+ special_level = LOG_UNSET;
+ lib_level = LOG_UNSET;
+ exe_level = LOG_UNSET;
+ global_level = LOG_UNSET;
}
void calc_level() // to calc the current log level
{
level = LOG_INFO;
- if (special_level != LOG_LEVEL_MAX) // [exe]_[lib] level as the first consideration
+ if (special_level != LOG_UNSET) // [exe]_[lib] level as the first consideration
{
level = special_level;
}
- else if (exe_level != LOG_LEVEL_MAX) // when [exe] level is set
+ else if (exe_level != LOG_UNSET) // when [exe] level is set
{
level = exe_level;
}
- else if (lib_level != LOG_LEVEL_MAX) // when [lib] level is set
+ else if (lib_level != LOG_UNSET) // when [lib] level is set
{
level = lib_level;
}
- else if (global_level != LOG_LEVEL_MAX) // global log level is set
+ else if (global_level != LOG_UNSET) // global log level is set
{
level = global_level;
}
@@ -138,7 +138,7 @@
return (log_level_enum)level;
}
}
- return LOG_LEVEL_MAX;
+ return LOG_UNSET;
}
static log_level_enum get_uci_log_value(const char *key)
@@ -146,7 +146,7 @@
char level_buf[64] = {0};
if (key == NULL || key[0] == '\0')
{
- return LOG_LEVEL_MAX;
+ return LOG_UNSET;
}
if (0 == lynq_get_value((char*)LOG_UCI_FILE, (char*)LOG_UCI_MODULE, (char*)key, level_buf))
@@ -154,7 +154,7 @@
return convert_log_level_from_string(level_buf);
}
- return LOG_LEVEL_MAX;
+ return LOG_UNSET;
}
static void get_module_log_level(struct log_module_entry *entry) // calc module log level from uci
@@ -177,8 +177,8 @@
entry->exe_level = get_uci_log_value(uci_key);
if (main_module_flag == 1) // if this entry is main module no need to get the special level
{
- entry->lib_level = LOG_LEVEL_MAX;
- entry->special_level = LOG_LEVEL_MAX;
+ entry->lib_level = LOG_UNSET;
+ entry->special_level = LOG_UNSET;
}
else
{
@@ -467,6 +467,80 @@
}
#endif
+//log level api
+
+int lynq_set_log_level(const char * module_name, log_level_enum level)
+{
+ char level_buf[64] = {0};
+ if (module_name == NULL || module_name[0] == '\0')
+ {
+ __android_log_print(ANDROID_LOG_ERROR, "LYNQ_LOG", "lynq_set_log_level: bad module name");
+ return -1;
+ }
+
+ if (level > LOG_UNSET && level < LOG_LEVEL_MAX)
+ {
+ sprintf(level_buf, "%s", LogLevelNameInfoTable[level]);
+ }
+ else if (level != LOG_UNSET)
+ {
+ __android_log_print(ANDROID_LOG_ERROR, "LYNQ_LOG", "unkown level %d", level);
+ return -1;
+ }
+
+ return lynq_set_value((char*)LOG_UCI_MODULE, (char*)module_name, level_buf);
+}
+
+int lynq_get_log_level(const char * module_name, log_level_enum *level)
+{
+ char level_buf[64] = {0};
+ if (level == NULL || module_name == NULL || module_name[0] == '\0')
+ {
+ __android_log_print(ANDROID_LOG_ERROR, "LYNQ_LOG", "lynq_get_log_level: bad param");
+ return -1;
+ }
+
+ if (0 == lynq_get_value((char*)LOG_UCI_FILE, (char*)LOG_UCI_MODULE, (char*)module_name, level_buf))
+ {
+ *level = convert_log_level_from_string(level_buf);
+ return 0;
+ }
+
+ return -1;
+}
+
+int lynq_set_special_log_level(const char * exe_name, const char * module_name, log_level_enum level)
+{
+ char special_name[128] = {0};
+ if (exe_name == NULL || module_name == NULL || exe_name[0] == '\0' || module_name[0] == '\0')
+ {
+ __android_log_print(ANDROID_LOG_ERROR, "LYNQ_LOG", "lynq_set_special_log_level: bad param");
+ return -1;
+ }
+
+ sprintf(special_name, "%s__%s", exe_name, module_name);
+ return lynq_set_log_level(special_name, level);
+}
+
+int lynq_get_special_log_level(const char * exe_name, const char * module_name, log_level_enum *level)
+{
+ char special_name[128] = {0};
+ if (exe_name == NULL || module_name == NULL || exe_name[0] == '\0' || module_name[0] == '\0')
+ {
+ __android_log_print(ANDROID_LOG_ERROR, "LYNQ_LOG", "lynq_get_special_log_level: bad param");
+ return -1;
+ }
+
+ sprintf(special_name, "%s__%s", exe_name, module_name);
+ return lynq_get_log_level(special_name, level);
+}
+
+int lynq_notify_recalc_log_level(pid_t pid)
+{
+ char cmd_buf[64];
+ sprintf(cmd_buf, " [ -d /tmp/log_level/%d ] && kill -%d %d", pid, SIGUSR1, pid);
+ return system(cmd_buf);
+}
static void log_signal_handler(int signum) {
if (SIGUSR1 != signum)