add T108 mbtk_logd and liblog
Change-Id: Ib486a63a423e22ca07b3568a1b3c856b23e63ea3
diff --git a/mbtk/include/lynq/liblog.h b/mbtk/include/lynq/liblog.h
index d1ca261..31ab385 100755
--- a/mbtk/include/lynq/liblog.h
+++ b/mbtk/include/lynq/liblog.h
@@ -2,6 +2,7 @@
#define __LIBLOG_H__
#include <unistd.h>
+#include "mbtk_log.h"
#ifdef __cplusplus
extern "C" {
@@ -32,5 +33,143 @@
#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/lynq_lib/Makefile b/mbtk/lynq_lib/Makefile
index 5a0ed65..b130257 100755
--- a/mbtk/lynq_lib/Makefile
+++ b/mbtk/lynq_lib/Makefile
@@ -8,7 +8,7 @@
LIB_DIR +=
#LIBS += -llog -lmbtk_lib
-LIBS += -lmbtk_lib -lrilutil -lprop2uci -lmtel -laudio-apu -lcutils -ltinyalsa -lacm -llog
+LIBS += -lmbtk_lib -lrilutil -lprop2uci -lmtel -laudio-apu -lcutils -ltinyalsa -lacm -llog -ljson-c -lblobmsg_json
ifeq ($(BUILD_PLATFORM), asr1806)
LIBS += -lmbtk_audio_lib
endif
diff --git a/mbtk/lynq_lib/src/lynq_log.c b/mbtk/lynq_lib/src/lynq_log.c
index 7824d3f..670e5c9 100755
--- a/mbtk/lynq_lib/src/lynq_log.c
+++ b/mbtk/lynq_lib/src/lynq_log.c
@@ -1,12 +1,16 @@
+#include "json/json.h"
#include "liblog.h"
#include "mbtk_type.h"
+#define LOG_CONFIG_PATH "/etc/mbtk/mbtk_log.json"
+#define SYSLOG_PATCH "syslog"
+#define SYSLOG_NAME "syslog"
+#define SYSLOG_INDEX 0
void lynq_log_configuration_init(const char *log_name)
{
- UNUSED(log_name);
-
-
+ //UNUSED(log_name);
+ mbtk_log_init(SYSLOG_PATCH, log_name);
}
void lynq_log_global_output(log_level_enum Level,const char *format,...)
@@ -14,33 +18,212 @@
UNUSED(Level);
UNUSED(format);
-
}
int lynq_syslog_set_file_size(int value)
{
- UNUSED(value);
+// UNUSED(value);
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+ int tmp_int;
+ char* tmp_string = NULL;
+
+ if(value < 1)
+ {
+ value = 1;
+ }
+ else if(value > 100)
+ {
+ value = 100;
+ }
+// value = value*1024;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ system("echo Can't open config file > /dev/console");
+ 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_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("NULL == datajson\n");
+ system("echo NULL == datajson > /dev/console");
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("SYSLOG_NAME error, tmp_int != 1\n");
+ system("echo SYSLOG_NAME error, tmp_int != 1 > /dev/console");
+ return -1;
+ }
+
+ json_object_object_add(datajson, "rotate_file_size", json_object_new_int(value));
+
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
return 0;
}
int lynq_syslog_get_file_size(void)
{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
- return -1;
+ int tmp_int;
+ 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, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "rotate_file_size", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ /***释放json对象***/
+ json_object_put(jsonobj);
+
+// return tmp_int/1024;
+ return tmp_int;
}
int lynq_syslog_set_file_rotate(int value)
{
- UNUSED(value);
+ //UNUSED(value);
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+ int tmp_int;
+ char* tmp_string = NULL;
+
+ if(value < 0)
+ {
+ value = 0;
+ }
+ else if(value > 99)
+ {
+ value = 99;
+ }
+
+ 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_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_add(datajson, "rotate_file_count", json_object_new_int(value));
+
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
return 0;
}
int lynq_syslog_get_file_rotate(void)
{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
- return 0;
+ int tmp_int;
+ 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, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "rotate_file_count", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ /***释放json对象***/
+ json_object_put(jsonobj);
+
+ return tmp_int;
}
int lynq_set_log_level(const char * module_name, log_level_enum level)
@@ -86,39 +269,4 @@
UNUSED(pid);
return 0;
-}
-
-void lynq_log_debug(const char *format,...)
-{
- UNUSED(format);
-
-
-}
-
-void lynq_log_info(const char *format,...)
-{
- UNUSED(format);
-
-
-}
-
-void lynq_log_warning(const char *format,...)
-{
- UNUSED(format);
-
-
-}
-
-void lynq_log_error(const char *format,...)
-{
- UNUSED(format);
-
-
-}
-
-void lynq_log_verbose(const char *format,...)
-{
- UNUSED(format);
-
-
-}
+}
\ No newline at end of file
diff --git a/mbtk/mbtk_logd/common.c b/mbtk/mbtk_logd/common.c
index 1e293b6..5b2de92 100755
--- a/mbtk/mbtk_logd/common.c
+++ b/mbtk/mbtk_logd/common.c
@@ -226,6 +226,7 @@
sprintf(old, "%s.%02d", old, num);
}
}
+ printf("MBTK_LOGD: tmp_buf is %s, old is %s\n", tmp_buf, old);
if (movefile(tmp_buf, old) != 0){
printf("%s %d: Renamed error ,%s to %s.\n", __FUNCTION__, __LINE__, tmp_buf, old);
}
diff --git a/mbtk/mbtk_logd/main.c b/mbtk/mbtk_logd/main.c
index 25dbdb1..e47bdca 100755
--- a/mbtk/mbtk_logd/main.c
+++ b/mbtk/mbtk_logd/main.c
@@ -7,6 +7,7 @@
#include <time.h>
#include <errno.h>
#include <stdlib.h>
+#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "json/json.h"
@@ -69,6 +70,7 @@
int i, n, ret;
char* cmdval = NULL;
+ printf("MBTK_LOGD: in parse_config\n");
jsonobj = json_object_from_file(LOG_CONFIG_PATH);
if (NULL == jsonobj) {
printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
@@ -86,8 +88,10 @@
cmdval = json_object_get_string(tmpjson);
printf("logd enable : %s\n", cmdval);
json_object_put(tmpjson);
+
/***获取data***/
json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+
for (i = 0 ; i < 5; i++) {
struct filter_list_t* _filter_list = NULL;
struct filter_list_t* tmp_filter_list = NULL;
@@ -102,16 +106,17 @@
mbtk_log("enable: %d\n", entry->enable);
json_object_object_get_ex(datajson, "name", &listjson);
- entry->name = strdup(json_object_get_string(listjson));
- mbtk_log("cmdval: %x, %s\n", entry->name, entry->name);
+ entry->name = json_object_get_string(listjson);
+ printf("cmdval: %x, %s\n", entry->name, entry->name);
json_object_object_get_ex(datajson, "log_file", &listjson);
- entry->out_path = strdup(json_object_get_string(listjson));
+ entry->out_path = json_object_get_string(listjson);
mbtk_log("cmdval: %s\n", entry->out_path);
json_object_object_get_ex(datajson, "log_stream", &listjson);
if (listjson) {
- entry->ip = strdup(json_object_get_string(listjson));
+ entry->ip = json_object_get_string(listjson);
+
cmdval = strstr(entry->ip, ":");
if (cmdval) {
entry->port = &cmdval[1];
@@ -164,7 +169,8 @@
_filter_list->tag = strdup(str);
mbtk_log("fileter_listjson: %s\n", _filter_list->tag);
}
- json_object_put(fileter_listjson);
+
+ //json_object_put(fileter_listjson);
_filter_list->next = (struct filter_list_t*)malloc(sizeof(struct filter_list_t));
if (NULL == _filter_list->next) {
printf("%s %d: malloc failure!\n", __FUNCTION__, __LINE__);
@@ -173,13 +179,11 @@
tmp_filter_list = _filter_list;
_filter_list = _filter_list->next;
}
- json_object_put(listjson);
}
- json_object_put(tmpjson);
/***释放json对象***/
json_object_put(jsonobj);
-
+ printf("MBTK_LOGD: parse_config end\n");
return 0;
}
@@ -218,18 +222,22 @@
pthread_t pid[5] = {0};
int i, ret;
void* tret;
+ struct filter_list_t* _filter_list = NULL;
+
+ int lock_file = open("/tmp/mbtk_logd.lock", O_CREAT|O_RDWR, 0666);
+ int rc = flock(lock_file,LOCK_EX|LOCK_NB);
+ if(rc) {
+ if(EWOULDBLOCK == errno) {
+ printf("Error: cannot restart the mbtk_logd repeatedly\n");
+ exit(0);
+ }
+ }
memset(listdata, 0, sizeof(log_config_entry) * 5);
-
ret = parse_config(listdata);
if (ret) {
return -1;
}
- if(0 != save_pid())
- {
- printf("%s %d: logd exit!\n", __FUNCTION__, __LINE__);
- return -1;
- }
printf("logd %s start !\n", __FUNCTION__);
@@ -258,7 +266,7 @@
if (ret != 0) {
fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__);
}
- } else if (0 == memcmp(listdata[i].name, "/dev/tty", 8)) {
+ } else if (0 == memcmp(listdata[i].name, "/dev/ttyS0", 8)) {
ret = pthread_create(&pid[i], NULL, common_log_thread, &listdata[i]);
if (ret != 0) {
fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__);
@@ -266,6 +274,7 @@
}
}
+
for (i = 0; i < 5; ++i) {
if (NULL == listdata[i].name) {
break;
diff --git a/mbtk/mbtk_logd/syslog_read.c b/mbtk/mbtk_logd/syslog_read.c
index 3cae9e9..c52a6ee 100755
--- a/mbtk/mbtk_logd/syslog_read.c
+++ b/mbtk/mbtk_logd/syslog_read.c
@@ -33,6 +33,7 @@
#include "syslog.h"
#include "log_config.h"
+#define LOG_CONFIG_LEN 50
enum {
LOG_STDOUT,
LOG_FILE,
@@ -58,7 +59,8 @@
static struct uloop_timeout retry;
static struct uloop_fd sender;
-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_type = LOG_STDOUT;
static int log_size = 1 * 1024 * 1024, log_udp, log_follow = 0;
static struct file_list_t file_list;
@@ -184,11 +186,11 @@
snprintf(buf, sizeof(buf), "<%u>", p);
strncat(buf, c + 4, 16);
- if (hostname) {
+ if (strlen(hostname) > 0) {
strncat(buf, hostname, sizeof(buf));
strncat(buf, " ", sizeof(buf));
}
- if (log_prefix) {
+ if (strlen(log_prefix) > 0) {
strncat(buf, log_prefix, sizeof(buf));
strncat(buf, ": ", sizeof(buf));
}
@@ -258,7 +260,7 @@
const char *ubus_socket = NULL;
int ch, ret, lines = 0;
static struct blob_buf b;
- int tries = 5;
+ int tries = 60;
log_config_entry *config = (log_config_entry *)argv;
pthread_detach(pthread_self());
@@ -269,7 +271,19 @@
signal(SIGPIPE, SIG_IGN);
uloop_init();
- 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);
+ }
+
memset(&file_list, 0, sizeof(struct file_list_t));
file_list.total = config->rotate_file_count;
if(config->rotate_file_size)
@@ -277,8 +291,13 @@
if(config->ip)
{
printf("%s %d : %s:%s\n", __FUNCTION__, __LINE__, config->ip, config->port);
- log_ip = config->ip;
- log_port = config->port;
+ //log_ip = config->ip;
+ strncpy(log_ip, config->ip, LOG_CONFIG_LEN - 1);
+ //log_port = config->port;
+ if(config->port != NULL)
+ {
+ strncpy(log_port, config->port, LOG_CONFIG_LEN - 1);
+ }
}
filter_log = config->filter_list;
// Follow log messages
@@ -299,14 +318,13 @@
sleep(1);
continue;
}
-
blob_buf_init(&b, 0);
if (lines)
blobmsg_add_u32(&b, "lines", lines);
else if (log_follow)
blobmsg_add_u32(&b, "lines", 0);
if (log_follow) {
- if (pid_file) {
+ if (strlen(pid_file) > 0) {
FILE *fp = fopen(pid_file, "w+");
if (fp) {
fprintf(fp, "%d", getpid());
@@ -315,16 +333,16 @@
}
}
- if (log_ip && log_port) {
+ if (strlen(log_ip) > 0 && strlen(log_port) > 0) {
openlog("logread", LOG_PID, LOG_DAEMON);
log_type = LOG_NET;
sender.cb = log_handle_fd;
retry.cb = log_handle_reconnect;
uloop_timeout_set(&retry, 1000);
- } else if (log_file) {
+ } else if (strlen(log_file) > 0) {
log_type = LOG_FILE;
// 先将文件保存到 /tmp/log/ 目录下,后面到达 rotate_file_size 后,转移到out_path
- sprintf(tmp_log, "/tmp/log%s", strstr_tail(log_file, "/"));
+ sprintf(tmp_log, "/tmp/log%s", strstr_tail(log_file, "/"));
sender.fd = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
if (sender.fd < 0) {
fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
@@ -338,7 +356,7 @@
req.fd_cb = logread_fd_cb;
req.complete_cb = logread_complete_cb;
ubus_complete_request_async(ctx, &req);
-
+
uloop_run();
ubus_free(ctx);
uloop_done();
diff --git a/mbtk/test/lynq_log_test.c b/mbtk/test/lynq_log_test.c
new file mode 100755
index 0000000..bdfa74e
--- /dev/null
+++ b/mbtk/test/lynq_log_test.c
@@ -0,0 +1,106 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include "json/json.h"
+#include "liblog.h"
+
+int main(int argc, char *argv[])
+{
+ int err, value;
+ int cmdIdx = 0;
+ int ret = 0;
+ int i = 0;
+ char operator[10];
+ int opt = 0;
+
+ lynq_log_configuration_init("MBTK_QL_TEST");
+
+ while(1)
+ {
+
+ printf("=========log========\n"
+ "\t 0 lynq_syslog_set_file_size\n"
+ "\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"
+ "=========================\n");
+
+ fflush(stdin);
+ fgets(operator, sizeof(operator), stdin);
+ opt = atoi(operator);
+
+ switch(opt)
+ {
+ case 0://"lynq_syslog_set_file_size"
+ {
+ //fgets(arg_string, MAX_INPUT, stdin);
+ printf("please input size:\n");
+ scanf("%d", &value);
+ printf("Input value is %d\n",value);
+ ret = lynq_syslog_set_file_size(value);
+ if(ret < 0)
+ {
+ printf("lynq_syslog_set_file_size failed, ret=%d\n", ret);
+ }
+
+ break;
+ }
+ case 1://"lynq_syslog_get_file_size"
+ {
+ //ret = demo_lynq_syslog_get_file_size();
+ ret = lynq_syslog_get_file_size();
+ printf("lynq_syslog_get_file_size ret:%d!\n", ret);
+
+ break;
+ }
+ case 2://"lynq_syslog_set_file_rotate"
+ {
+ printf("please input count:\n");
+ scanf("%d", &value);
+ printf("Input value is %d\n",value);
+ ret = lynq_syslog_set_file_rotate(value);
+ if(ret < 0)
+ {
+ printf("lynq_syslog_set_file_rotate failed, ret=%d\n", ret);
+ }
+
+ break;
+ }
+ 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
+ {
+ for(i=0;i<10;i++)
+ {
+ LYVERBLOG("LYNQ: Test LYVERBLOG\n");
+ LYERRLOG("LYNQ: Test LYERRLOG\n");
+ LYWARNLOG("LYNQ: Test LYWARNLOG\n");
+ LYINFLOG("LYNQ: Test LYINFLOG\n");
+ LYDBGLOG("LYNQ: Test LYDBGLOG\n");
+ }
+
+ printf("test write log end\n");
+
+ break;
+ }
+ default://EXIT
+ {
+ printf("break\n");
+ return 0;
+ }
+ }
+ }
+
+ return 0;
+}
+