[84929][85032][85034]fix syslog set/get log level, default file count and size
Change-Id: I56929b9b4a403c15650656fcaa8eab428e4d33bf
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;