[Feature][R305][task-view-1811][log] add internal storage log function

Change-Id: Icc94578c6aade7478b856e44e196596246c1ae25
diff --git a/lynq/R305/ap/lib/libsoftap/softap_log.c b/lynq/R305/ap/lib/libsoftap/softap_log.c
index 092b543..6cadda4 100755
--- a/lynq/R305/ap/lib/libsoftap/softap_log.c
+++ b/lynq/R305/ap/lib/libsoftap/softap_log.c
@@ -20,6 +20,7 @@
 int slog_printlevel  = SLOG_ERR;
 int slog_sysloglevel = SLOG_OFF;
 int soctime_sw       = SLOG_SOCTIME_OFF;
+int g_open_lynq_log  = 0;
 
 int log_switch = LOG_ON;
 long long time_us;
@@ -75,10 +76,14 @@
 	char nv_print_level[32]    = {0};
 	char nv_syslog_level[32]   = {0};
 	char nv_soctime_switch[32] = {0};
+	char open_lynq_log[8] = {0};
 
 	cfg_get_item("print_level", nv_print_level, sizeof(nv_print_level));
 	cfg_get_item("syslog_level", nv_syslog_level, sizeof(nv_syslog_level));
 	cfg_get_item("soctime_switch", nv_soctime_switch, sizeof(nv_soctime_switch));
+	cfg_get_item("open_lynq_log", open_lynq_log, sizeof(open_lynq_log));
+
+	g_open_lynq_log = atoi(open_lynq_log);
 
 	//loglevel·ÇÓÐЧֵʱ£¬½«Ä¬ÈÏ´òÓ¡¼¶±ðÉèÖÃΪoff£¬¼´¹Ø±Õ´òÓ¡
 	slog_printlevel = atoi(nv_print_level);
@@ -114,6 +119,10 @@
 		syslog(prio, "[%lld.%llds]: ", time_us / 1000000, time_us % 1000000);
 }
 
+#define LYNQ_LOG_FILE_PATH "/cache/lynqlog"
+#define LYNQ_LOG_FILE_BACKUP "/cache/lynqlog.0"
+#define LYNQ_LOG_FILE_MAX_SIZE (100 * 1024) // 100KB
+
 #define put_to_console(mod, fmt, arg) do {\
 	char buf[1024] = {0}; \
 	if(SLOG_SOCTIME_ON == soctime_sw) \
@@ -125,6 +134,24 @@
 	vsnprintf(buf+n, 1023-n, fmt, arg); \
 	va_end(arg); \
 	printf("%s",buf); \
+	if (1 == g_open_lynq_log) \
+	{\
+		struct stat st; \
+		if (stat(LYNQ_LOG_FILE_PATH, &st) == 0 && st.st_size >= LYNQ_LOG_FILE_MAX_SIZE) \
+		{ \
+			rename(LYNQ_LOG_FILE_PATH, LYNQ_LOG_FILE_BACKUP); \
+		} \
+		time_t now = time(NULL); \
+		struct tm *tm_info = localtime(&now); \
+		char time_buf[64]; \
+		strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", tm_info); \
+		FILE *fp = fopen(LYNQ_LOG_FILE_PATH, "a"); \
+		if (fp != NULL) \
+		{ \
+			fprintf(fp, "%s %s\n", time_buf, buf); \
+			fclose(fp); \
+		} \
+	} \
 }while(0)
 
 
diff --git a/lynq/R305/ap/project/zx297520v3/prj_cpe_min/fs/normal/rootfs/etc_ro/default/default_parameter_user b/lynq/R305/ap/project/zx297520v3/prj_cpe_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
index e817b30..7b18d0c 100755
--- a/lynq/R305/ap/project/zx297520v3/prj_cpe_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
+++ b/lynq/R305/ap/project/zx297520v3/prj_cpe_min/fs/normal/rootfs/etc_ro/default/default_parameter_user
@@ -488,3 +488,4 @@
 ping_result=
 use_network_adb=usb
 SSIDbak=
+open_lynq_log=0