1 /*
2  * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3  */
4 
5 #ifndef U_LOG_CONFIG_H_
6 #define U_LOG_CONFIG_H_
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 
12 #define ULOG_TAG_SELF "ULOG"
13 
14 #define ULOG_POLICY_RQST   '?'
15 #define ULOG_LEVEL_RSP     "{\"cloud log level\":%d}"
16 
17 /**
18  * syslog management command mark
19  * NOT RECOMMEND MODIFY THIS VALUE, READ ONLY!!
20  */
21 #define ULOG_CMD_PREFIX "#@"
22 
23 #define ULOG_HEADER_TYPE_LEN 5
24 
25 /**
26  * syslog protocol, facility local use 0
27  * NOT RECOMMEND MODIFY THIS VALUE, READ ONLY!!
28  */
29 #define SYSLOG_FACILITY        128
30 
31 #define TAG_FILE_NAME_MAX_LEN  16
32 
33 #define UNDEFINE_FILE_NAME "unknown"
34 
35 #define MOD_MAX_LEN 10
36 
37 #define FACILITY_NORMAL_LOG 248
38 
39 #define FACILITY_NORMAL_LOG_NO_POP_CLOUD 240
40 
41 #define HTTP_REQ_RETRY 3
42 
43 #define HTTP_RSP_RETRY  3
44 
45 #define URL_PREFIX_HTTP "http://"
46 #define URL_PREFIX_HTTPS "https://"
47 
48 #define RSP_BUF_SIZE 512
49 
50 #define HTTP_UP_HDR_SIZE 64
51 
52 /* 5 is result of cost <%03d> */
53 #define LOG_PREFIX_LEN 5
54 
55 typedef enum {
56     http_upload_file_operate_fail = -4,
57     http_upload_text_empty        = -3,
58     http_upload_memory_fail       = -2,
59     http_upload_common_fail       = -1,
60     http_upload_start             = 0,
61     http_upload_finish            = 1,
62 } http_upload_fail_t;
63 
64 /**
65  * sometimes found the pop log into file always fail, may result from file attribute,
66  * or other unknown reason. If the fail operte on the same file keeps 3 times, then
67  * destroy the log file and create new one.
68  */
69 #define ULOG_FILE_FAIL_COUNT        3
70 
71 /**
72  * Specify the port of syslog watcher
73  * NOT RECOMMEND MODIFY THIS VALUE, READ ONLY!!
74  */
75 #define SYSLOG_WATCHER_DEFAULT_PORT 514
76 
77 /* Specify if details mode used under sync log */
78 #ifndef ULOG_CONFIG_SYNC_LOG_DETAILS
79 #define SYNC_LOG_DETAILS 0
80 #else
81 #define SYNC_LOG_DETAILS ULOG_CONFIG_SYNC_LOG_DETAILS
82 #endif
83 
84 #ifndef ULOG_CONFIG_SYNC_DETAIL_COLOR
85 #define SYNC_DETAIL_COLOR 0
86 #else
87 #define SYNC_DETAIL_COLOR ULOG_CONFIG_SYNC_DETAIL_COLOR
88 #endif
89 
90 #ifndef ULOG_CONFIG_SYNC_ABS_PATH
91 #define SYNC_ABS_PATH 0
92 #else
93 #define SYNC_ABS_PATH ULOG_CONFIG_SYNC_ABS_PATH
94 #endif
95 
96 #ifndef ULOG_CONFIG_DEFAULT_DIR_ASYNC
97 #define LOG_DIR_ASYNC 0
98 #else
99 #define LOG_DIR_ASYNC ULOG_CONFIG_DEFAULT_DIR_ASYNC
100 #endif
101 
102 #ifndef ULOG_CONFIG_SYSLOG_TIME_FORMAT
103 #define SYSLOG_TIME_FORMAT 0
104 #else
105 #define SYSLOG_TIME_FORMAT ULOG_CONFIG_SYSLOG_TIME_FORMAT
106 #endif
107 
108 #ifndef ULOG_CONFIG_EXTREAM_LOG_TAG
109 #define EXTREAM_LOG_TAG 1
110 #else
111 #define EXTREAM_LOG_TAG ULOG_CONFIG_EXTREAM_LOG_TAG
112 #endif
113 
114 /**
115  * the max length of every trace log to be recorded, include syslog format(if EXTREAM_LOG_TEXT
116  * is not set), so 100 is reseanable value when syslog format support, 50 is fit for extream log mode
117  * Log Content will be trimmed if it's too long.
118  * SYSLOG_SIZE*SYSLOG_SIZE is the log mechanism cost heap size
119  */
120 #ifndef ULOG_CONFIG_LOG_SIZE
121 #define ULOG_SIZE         256
122 #else
123 #define ULOG_SIZE         ULOG_CONFIG_LOG_SIZE
124 #endif
125 
126 /**
127  * Default size of buffer queue that used to record log under aync mode.
128  * May the trace log miss if this value was set too small.
129  * More RAM will be costed if it set too large
130  * So consider balance of this value and system resouce
131  */
132 #ifndef ULOG_CONFIG_ASYNC_BUF_SIZE
133 #define DEFAULT_ASYNC_BUF_SIZE    6144
134 #else
135 #define DEFAULT_ASYNC_BUF_SIZE    ULOG_CONFIG_ASYNC_BUF_SIZE
136 #endif
137 
138 #ifndef ULOG_CONFIG_RESERVED_FS
139 #define ULOG_RESERVED_FS   0
140 #else
141 #define ULOG_RESERVED_FS ULOG_CONFIG_RESERVED_FS
142 #endif
143 
144 #ifndef ULOG_CONFIG_RESERVED_FS_SIZE
145 #define ULOG_RESERVED_FS_SIZE   64
146 #else
147 #define ULOG_RESERVED_FS_SIZE ULOG_CONFIG_RESERVED_FS_SIZE
148 #endif
149 
150 /**
151  * Level Stop Filter of default direction(uart for rtos), any log level qual or lower than this (value higher than it)
152  * will be abondoned LOG_EMERG will make none log pop out.
153  */
154 #ifndef ULOG_CONFIG_STOP_FILTER_DEFAULT
155 #define STOP_FILTER_DEFAULT   LOG_WARNING
156 #else
157 #define STOP_FILTER_DEFAULT   ULOG_CONFIG_STOP_FILTER_DEFAULT
158 #endif
159 
160 /**
161  * Level Stop Filter of udp, any log level qual or lower than this (value higher than it)
162  * will be abondoned LOG_EMERG will make none log pop out.
163  */
164 #ifndef ULOG_CONFIG_STOP_FILTER_UDP
165 #define STOP_FILTER_UDP       LOG_WARNING
166 #else
167 #define STOP_FILTER_UDP       ULOG_CONFIG_STOP_FILTER_UDP
168 #endif
169 
170 /**
171  * switch on pop out log into file system
172  */
173 #ifndef ULOG_CONFIG_POP_FS
174 #define ULOG_POP_FS_ENABLE       0
175 #else
176 #define ULOG_POP_FS_ENABLE ULOG_CONFIG_POP_FS
177 #endif
178 
179 #ifndef ULOG_CONFIG_UPLOAD
180 #define ULOG_UPLOAD_LOG_FILE     0
181 #else
182 #define ULOG_UPLOAD_LOG_FILE ULOG_CONFIG_UPLOAD
183 #endif
184 
185 /**
186  * switch on pop out log via UDP
187  */
188 #ifndef ULOG_CONFIG_POP_UDP
189 #define ULOG_POP_UDP_ENABLE       0
190 #else
191 #define ULOG_POP_UDP_ENABLE ULOG_CONFIG_POP_UDP
192 #endif
193 
194 /**
195  * Level Stop Filter of File system, any log level qual or lower than this (value higher than it)
196  * will be abondoned LOG_EMERG will make none log pop out.
197  */
198 #ifndef ULOG_CONFIG_STOP_FILTER_FS
199 #define STOP_FILTER_FS       LOG_WARNING
200 #else
201 #define STOP_FILTER_FS       ULOG_CONFIG_STOP_FILTER_FS
202 #endif
203 
204 /**
205  * switch on pop out log into cloud real-time
206  */
207 #ifndef AOS_COMP_UAGENT
208 #define ULOG_POP_CLOUD_ENABLE       0
209 #else
210 #define ULOG_POP_CLOUD_ENABLE       1
211 #endif
212 
213 /**
214  * Level Stop Filter of File system, any log level qual or lower than this (value higher than it)
215  * will be abondoned LOG_EMERG will make none log pop out.
216  */
217 #ifndef ULOG_CONFIG_STOP_FILTER_CLOUD
218 #define STOP_FILTER_CLOUD       LOG_EMERG
219 #else
220 #define STOP_FILTER_CLOUD       ULOG_CONFIG_STOP_FILTER_CLOUD
221 #endif
222 
223 
224 /**
225  * STACK DEPTH of Log Task, will cost 3072 Byte room
226  */
227 #ifndef ULOG_CONFIG_LOG_ROUTINE_TASK_STACK_DEPTH
228 #define LOG_ROUTINE_TASK_STACK_DEPTH 3072
229 #else
230 #define LOG_ROUTINE_TASK_STACK_DEPTH ULOG_CONFIG_LOG_ROUTINE_TASK_STACK_DEPTH
231 #endif
232 
233 /**
234  * Max log files support in fs, if the recording file more than this value, rolling back mechanism trigged.
235  */
236 #ifndef ULOG_CONFIG_LOCAL_FILE_CNT
237 #define LOCAL_FILE_CNT 5
238 #else
239 #define LOCAL_FILE_CNT ULOG_CONFIG_LOCAL_FILE_CNT
240 #endif
241 
242 /**
243  * Max log file size locate in local file system, if the recording file larger than this value,
244  * new files will be used to be recored.
245  */
246 #ifndef ULOG_CONFIG_LOCAL_FILE_SIZE
247 #define LOCAL_FILE_SIZE 4096
248 #else
249 #define LOCAL_FILE_SIZE ULOG_CONFIG_LOCAL_FILE_SIZE
250 #endif
251 
252 #if ULOG_POP_FS_ENABLE
253 #ifdef CSP_LINUXHOST
254 #error(modify below PATH as log file located, then disable this statement)
255 #define ULOG_DEAULT_FS_PATH              "/workspace/"
256 #elif defined (AOS_COMP_SPIFFS)
257 #define ULOG_DEAULT_FS_PATH              "/spiffs/"
258 #elif defined (AOS_COMP_FATFS)
259 #ifdef CONFIG_AOS_FATFS_SUPPORT_MMC
260 #define ULOG_DEAULT_FS_PATH              "/sdcard/"
261 #else
262 #define ULOG_DEAULT_FS_PATH              "/fatfs/"
263 #endif /* CONFIG_AOS_FATFS_SUPPORT_MMC */
264 #else
265 #define ULOG_DEAULT_FS_PATH              "/data/ulog/"
266 #endif
267 #endif /* ULOG_POP_FS_ENABLE  */
268 
269 #if ULOG_POP_UDP_ENABLE
270 #ifdef CONFIG_NO_TCPIP
271 #error ("pop log via udp not support in no tcpip board")
272 #endif
273 #endif
274 
275 #if ULOG_POP_CLOUD_ENABLE
276 #include "uagent_type.h"
277 #define ULOG_SHOW         (UAGENT_FUNC_USER_BASE)
278 #define ULOG_LEVEL_CHANGE (UAGENT_FUNC_USER_BASE + 1)
279 #define ULOG_LOG_LIST     (UAGENT_FUNC_USER_BASE + 2)
280 #define ULOG_POLICY       (UAGENT_FUNC_USER_BASE + 3)
281 #endif
282 
283 typedef enum {
284     ulog_session_std = 0,  /* default out direction, usually uart for rtos, termial for Linux */
285 
286 #if ULOG_POP_CLOUD_ENABLE
287     ulog_session_cloud,      /* to cloud, via uagent */
288 #endif
289 
290 #if ULOG_POP_FS_ENABLE
291     ulog_session_file,       /* log on local file system */
292 #endif
293 
294 #if ULOG_POP_UDP_ENABLE
295     ulog_session_udp,        /* syslog via udp, port 514 is default for syslog watcher */
296 #endif
297     ulog_session_size
298 } ulog_session_type_t;
299 
300 #endif /*U_LOG_CONFIG_H_*/
301 
302