[84929][85032][85034]fix syslog set/get log level, default file count and size
Change-Id: I56929b9b4a403c15650656fcaa8eab428e4d33bf
diff --git a/mbtk/include/lynq/liblog.h b/mbtk/include/lynq/liblog.h
index 31ab385..7d13802 100755
--- a/mbtk/include/lynq/liblog.h
+++ b/mbtk/include/lynq/liblog.h
@@ -33,143 +33,6 @@
#ifdef __cplusplus
}
#endif
-#define lynq_log_verbose(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-#define lynq_log_error(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-#define lynq_log_warning(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define lynq_log_info(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define lynq_log_debug(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt "\n", ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define LYVERBLOG(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define LYERRLOG(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define LYWARNLOG(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define LYINFLOG(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
- } while(0)
-
-#define LYDBGLOG(fmt, args...) \
- do{ \
- char *file_ptr_1001 = __FILE__; \
- char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
- char line_1001[10] = {0}; \
- sprintf(line_1001, "%d", __LINE__); \
- while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
- if(*ptr_1001 == '/') \
- break; \
- ptr_1001--; \
- } \
- mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt "\n", ptr_1001 + 1, line_1001, ##args); \
- } while(0)
#endif //__LOG_H__
diff --git a/mbtk/include/lynq/lynq_deflog.h b/mbtk/include/lynq/lynq_deflog.h
index 3fecfc7..fd45185 100755
--- a/mbtk/include/lynq/lynq_deflog.h
+++ b/mbtk/include/lynq/lynq_deflog.h
@@ -18,42 +18,180 @@
#ifdef __cplusplus
}
#endif
+#define lynq_log_verbose(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#define lynq_log_verbose(...) do { lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
-#define lynq_log_error(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
-#define lynq_log_warning(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while (0)
-#define lynq_log_info(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
-#define lynq_log_debug(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
+#define lynq_log_error(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#define LYVERBLOG(...) do {lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
-#define LYERRLOG(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
-#define LYWARNLOG(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while(0)
-#define LYINFLOG(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
-#define LYDBGLOG(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
+#define lynq_log_warning(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-// just for comcompatibility, do nothing
-#define LYLOGSET(a) do{;}while(0)
-#define LYLOGEINIT(Y) do{;}while(0)
+#define lynq_log_info(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#ifndef ALOGV
-#define ALOGV(...) do {lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
-#endif
+#define lynq_log_debug(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt "\n", ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#ifndef ALOGE
-#define ALOGE(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
-#endif
+#define LYVERBLOG(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#ifndef ALOGW
-#define ALOGW(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while (0)
-#endif
+#define LYERRLOG(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_ERR_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#ifndef ALOGI
-#define ALOGI(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
-#endif
+#define LYWARNLOG(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_WARN_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
-#ifndef ALOGD
-#define ALOGD(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
-#endif
+#define LYINFLOG(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_INFO_LEVEL, "%s#%s: " fmt, ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
+
+#define LYDBGLOG(fmt, args...) \
+ do{ \
+ char *file_ptr_1001 = __FILE__; \
+ char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
+ char line_1001[10] = {0}; \
+ sprintf(line_1001, "%d", __LINE__); \
+ while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
+ if(*ptr_1001 == '/') \
+ break; \
+ ptr_1001--; \
+ } \
+ mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: " fmt "\n", ptr_1001 + 1, line_1001, ##args); \
+ } while(0)
+// #define lynq_log_verbose(...) do { lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
+// #define lynq_log_error(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
+// #define lynq_log_warning(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while (0)
+// #define lynq_log_info(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
+// #define lynq_log_debug(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
+
+// #define LYVERBLOG(...) do {lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
+// #define LYERRLOG(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
+// #define LYWARNLOG(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while(0)
+// #define LYINFLOG(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
+// #define LYDBGLOG(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
+
+// // just for comcompatibility, do nothing
+// #define LYLOGSET(a) do{;}while(0)
+// #define LYLOGEINIT(Y) do{;}while(0)
+
+// #ifndef ALOGV
+// #define ALOGV(...) do {lynq_write_log(LOG_VERBOSE,__VA_ARGS__);} while (0)
+// #endif
+
+// #ifndef ALOGE
+// #define ALOGE(...) do {lynq_write_log(LOG_ERROR,__VA_ARGS__);} while (0)
+// #endif
+
+// #ifndef ALOGW
+// #define ALOGW(...) do {lynq_write_log(LOG_WARNING,__VA_ARGS__);} while (0)
+// #endif
+
+// #ifndef ALOGI
+// #define ALOGI(...) do {lynq_write_log(LOG_INFO,__VA_ARGS__);} while (0)
+// #endif
+
+// #ifndef ALOGD
+// #define ALOGD(...) do {lynq_write_log(LOG_DEBUG,__VA_ARGS__);} while (0)
+// #endif
#define DEFINE_LYNQ_LIB_LOG(tag) \
LYNQ_WRITE_LOG_PTR __attribute__ ((visibility ("hidden"))) lynq_write_log = NULL; \
diff --git a/mbtk/lynq_lib/src/lynq_log.c b/mbtk/lynq_lib/src/lynq_log.c
index 670e5c9..6e3885a 100755
--- a/mbtk/lynq_lib/src/lynq_log.c
+++ b/mbtk/lynq_lib/src/lynq_log.c
@@ -39,7 +39,7 @@
{
value = 100;
}
-// value = value*1024;
+ value = value*1024;
jsonobj = json_object_from_file(LOG_CONFIG_PATH);
if (NULL == jsonobj) {
@@ -122,8 +122,8 @@
/***释放json对象***/
json_object_put(jsonobj);
-// return tmp_int/1024;
- return tmp_int;
+ return tmp_int/1024;
+// return tmp_int;
}
int lynq_syslog_set_file_rotate(int value)
@@ -226,20 +226,192 @@
return tmp_int;
}
+log_level_enum filter_char_to_pri(char c)
+{
+ switch (c) {
+ case 'v':
+ return LOG_VERBOSE;
+ case 'd':
+ return LOG_DEBUG;
+ case 'i':
+ return LOG_INFO;
+ case 'w':
+ return LOG_WARNING;
+ case 'e':
+ return LOG_ERROR;
+ case '*':
+ default:
+ return LOG_LEVEL_MAX;
+ }
+}
+
+char filter_pri_to_char(log_level_enum level)
+{
+ char char_level;
+ switch (level) {
+ case LOG_VERBOSE:
+ char_level = 'v';
+ break;
+ case LOG_DEBUG:
+ char_level = 'd';
+ break;
+ case LOG_INFO:
+ char_level = 'i';
+ break;
+ case LOG_WARNING:
+ char_level = 'w';
+ break;
+ case LOG_ERROR:
+ char_level = 'e';
+ break;
+ case LOG_LEVEL_MAX:
+ default:
+ char_level = '*';
+ break;
+ }
+ return char_level;
+}
+
int lynq_set_log_level(const char * module_name, log_level_enum level)
{
- UNUSED(module_name);
- UNUSED(level);
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+ json_object* fileterjson = NULL;
+ json_object* fileter_listjson = NULL;
+ json_object* new_fileter = NULL;
+ int n = 0, array_length = 0;
+ char* tmp_string = NULL;
+ char level_string[5] = {'\0'};
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "filter_list", &listjson);
+ if (NULL == listjson) {
+ printf("%s %d: object failure!\n", __FUNCTION__, __LINE__);
+ json_object_put(listjson);
+ return -1;
+ }
+ array_length = json_object_array_length(listjson);
+ for (n = 0; n <= array_length; n++) {
+ fileterjson = json_object_array_get_idx(listjson, n);
+ if (NULL == fileterjson) {
+ new_fileter = json_object_new_object();
+ sprintf(level_string, "%c", filter_pri_to_char(level));
+ json_object_object_add(new_fileter, "priority", json_object_new_string(level_string));
+ json_object_object_add(new_fileter, "tag", json_object_new_string(module_name));
+ json_object_array_add(listjson, new_fileter);
+ break;
+ }
+
+ json_object_object_get_ex(fileterjson, "tag", &fileter_listjson);
+ char *str = json_object_get_string(fileter_listjson);
+ if (str) {
+ tmp_string = strdup(str);
+ if(strcmp(module_name, tmp_string) == 0)
+ {
+ sprintf(level_string, "%c", filter_pri_to_char(level));
+ json_object_object_add(fileterjson, "priority", json_object_new_string(level_string));
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return 0;
+ }
+ }
+ else
+ {
+ continue;
+ }
+ }
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
return 0;
}
int lynq_get_log_level(const char * module_name, log_level_enum *level)
{
- UNUSED(module_name);
- UNUSED(level);
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+ json_object* fileterjson = NULL;
+ json_object* fileter_listjson = NULL;
+ int n;
+ char* tmp_string = NULL;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "filter_list", &listjson);
+ if (NULL == listjson) {
+ printf("%s %d: object failure!\n", __FUNCTION__, __LINE__);
+ json_object_put(listjson);
+ return -1;
+ }
+
+ for (n = 0 ; n < 5; n++) {
+ fileterjson = json_object_array_get_idx(listjson, n);
+ if (NULL == fileterjson) {
+ printf("the fileterjson exit\n");
+ break;
+ }
+
+ json_object_object_get_ex(fileterjson, "tag", &fileter_listjson);
+ char *str = json_object_get_string(fileter_listjson);
+ if (str) {
+ tmp_string = strdup(str);
+ printf("tag is %s\n", tmp_string);
+ if(strcmp(module_name, tmp_string) == 0)
+ {
+ json_object_object_get_ex(fileterjson, "priority", &fileter_listjson);
+ str = json_object_get_string(fileter_listjson);
+ if (str) {
+ tmp_string = str[0];
+ printf("fileter_listjson: %c\n", tmp_string);
+ *level = filter_char_to_pri(tmp_string);
+ //get the log level
+ json_object_put(jsonobj);
+ return 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ continue;
+ }
+ }
+ *level = LOG_UNSET;
+ /***释放json对象***/
+ json_object_put(jsonobj);
return 0;
}
diff --git a/mbtk/mbtk_logd/alog_read.c b/mbtk/mbtk_logd/alog_read.c
index 33f227f..061516d 100755
--- a/mbtk/mbtk_logd/alog_read.c
+++ b/mbtk/mbtk_logd/alog_read.c
@@ -12,6 +12,7 @@
#include "log_config.h"
#define ALOG_DEV "/dev/log_radio"
+#define LOG_CONFIG_LEN 50
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
@@ -36,7 +37,8 @@
const char * message;
} AndroidLogEntry;
-static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname;
+//static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname;
+static char log_file[LOG_CONFIG_LEN], log_ip[LOG_CONFIG_LEN], log_port[LOG_CONFIG_LEN], log_prefix[LOG_CONFIG_LEN], pid_file[LOG_CONFIG_LEN], hostname[LOG_CONFIG_LEN];
static int log_size = 1 * 1024 * 1024;
static log_config_entry *config = NULL;
@@ -243,13 +245,23 @@
memset(&file_list, 0, sizeof(struct file_list_t));
file_list.total = config->rotate_file_count;
- log_file = config->out_path;
+ //log_file = config->out_path;
+ memset(log_file, 0, sizeof(log_file));
+ memset(log_ip, 0, sizeof(log_ip));
+ memset(log_port, 0, sizeof(log_port));
+ memset(log_prefix, 0, sizeof(log_prefix));
+ memset(pid_file, 0, sizeof(pid_file));
+ memset(hostname, 0, sizeof(hostname));
+ if(config->out_path != NULL)
+ {
+ strncpy(log_file, config->out_path, LOG_CONFIG_LEN - 1);
+ }
if (config->ip && config->port) {
int port = atoi(config->port);
printf("%s %d : %s:%s\n", __FUNCTION__, __LINE__, config->ip, config->port);
log_fd = tcp_connect(config->ip, port);
- } else if (log_file) {
+ } else if (strlen(log_file) > 0) {
sprintf(tmp_log, "/tmp/log%s", strstr_tail(log_file, "/"));
// 先将文件保存到 /tmp/log/ 目录下,后面到达 rotate_file_size 后,转移到out_path
log_fd = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
diff --git a/mbtk/mbtk_logd/main.c b/mbtk/mbtk_logd/main.c
index e47bdca..edc5375 100755
--- a/mbtk/mbtk_logd/main.c
+++ b/mbtk/mbtk_logd/main.c
@@ -14,7 +14,7 @@
#include "json/printbuf.h"
#include "log_config.h"
-// #define DEBUG 1
+//#define DEBUG 1
#ifdef DEBUG
#define mbtk_log(...) printf(__VA_ARGS__)
@@ -67,7 +67,7 @@
json_object* fileterjson = NULL;
json_object* fileter_listjson = NULL;
log_config_entry* entry;
- int i, n, ret;
+ int i, n, ret, array_length;
char* cmdval = NULL;
printf("MBTK_LOGD: in parse_config\n");
@@ -145,7 +145,8 @@
entry->filter_list = (struct filter_list_t*)malloc(sizeof(struct filter_list_t));
_filter_list = entry->filter_list;
- for (n = 0 ; n < 5; n++) {
+ array_length = json_object_array_length(listjson);
+ for (n = 0 ; n <= array_length; n++) {
fileterjson = json_object_array_get_idx(listjson, n);
if (NULL == fileterjson) {
mbtk_log("the fileterjson exit\n");
@@ -169,6 +170,10 @@
_filter_list->tag = strdup(str);
mbtk_log("fileter_listjson: %s\n", _filter_list->tag);
}
+ else
+ {
+ _filter_list->tag = "\0";
+ }
//json_object_put(fileter_listjson);
_filter_list->next = (struct filter_list_t*)malloc(sizeof(struct filter_list_t));
@@ -216,6 +221,7 @@
return -2;
}
+
int main(int argc, char* argv[])
{
log_config_entry listdata[5];
diff --git a/mbtk/mbtk_logd/syslog_read.c b/mbtk/mbtk_logd/syslog_read.c
index c52a6ee..8b84cde 100755
--- a/mbtk/mbtk_logd/syslog_read.c
+++ b/mbtk/mbtk_logd/syslog_read.c
@@ -127,12 +127,20 @@
while(_filter)
{
int p = filter_char_to_pri(_filter->priority);
- if(_filter->tag)
+ int len = strlen(_filter->tag);
+ if(len > 0)
{
- int len = strlen(_filter->tag);
- // tag and priority
- if(0 == memcmp(_filter->tag, tag, len) && ((pri < p) || (pri == p)))
- return 0;
+ if(0 == memcmp(_filter->tag, tag, len))
+ {
+ if((pri < p) || (pri == p))
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
}else{ // have no tag
if(pri > p)
return -1;
@@ -148,7 +156,7 @@
{
struct blob_attr *tb[__LOG_MAX];
struct stat s;
- char buf[512];
+ char buf[512] = {'\0'};
uint32_t p;
char *str;
time_t t;
@@ -179,7 +187,8 @@
if(filter_log && syslog_fileter_log(LOG_PRI(p), m, filter_log))
{
// printf("%s %d: fileter pri:%d tag:%s!\n", __FUNCTION__, __LINE__, p, m);
- exit(-1);
+ return 0;
+ //exit(-1);
}
if (log_type == LOG_NET) {
int err;
diff --git a/mbtk/test/lynq_log_test.c b/mbtk/test/lynq_log_test.c
index bdfa74e..fe749ec 100755
--- a/mbtk/test/lynq_log_test.c
+++ b/mbtk/test/lynq_log_test.c
@@ -4,7 +4,7 @@
#include <errno.h>
#include <string.h>
#include "json/json.h"
-#include "liblog.h"
+#include "lynq_deflog.h"
int main(int argc, char *argv[])
{
@@ -14,6 +14,8 @@
int i = 0;
char operator[10];
int opt = 0;
+ const char * module_name = "MBTK_QL_TEST";
+ log_level_enum *level = -1;
lynq_log_configuration_init("MBTK_QL_TEST");
@@ -25,10 +27,12 @@
"\t 1 lynq_syslog_get_file_size\n"
"\t 2 lynq_syslog_set_file_rotate\n"
"\t 3 lynq_syslog_get_file_rotate\n"
- "\t 4 test write log\n"
- "\t 5 EXIT \n"
+ "\t 4 lynq_set_log_level\n"
+ "\t 5 lynq_get_log_level\n"
+ "\t 6 test write log\n"
+ "\t 7 EXIT \n"
"=========================\n");
-
+
fflush(stdin);
fgets(operator, sizeof(operator), stdin);
opt = atoi(operator);
@@ -72,13 +76,28 @@
}
case 3://"lynq_syslog_get_file_rotate"
{
- //ret = demo_lynq_syslog_get_file_rotate();
ret = lynq_syslog_get_file_rotate();
printf("lynq_syslog_get_file_rotate ret:%d!\n", ret);
break;
}
- case 4://test write log
+ case 4://"lynq_set_log_level"
+ {
+ printf("please input level:\n");
+ scanf("%d", &value);
+ ret = lynq_set_log_level(module_name, value);
+ printf("lynq_set_log_level ret:%d!\n", ret);
+
+ break;
+ }
+ case 5://"lynq_get_log_level"
+ {
+ ret = lynq_get_log_level(module_name, &level);
+ printf("lynq_get_log_level ret:%d, level:%d!\n", ret, level);
+
+ break;
+ }
+ case 6://test write log
{
for(i=0;i<10;i++)
{