@@ -162,44 +162,57 @@ void HAP_debug_runtime(int level, const char *file, int line,
162162 const char * format , ...) {
163163 int len = 0 ;
164164 va_list argp ;
165- char * buf = NULL , * log = NULL ;
166-
167- /*
168- * Adding logs to persist buffer when level is set to
169- * RUNTIME_RPC_CRITICAL and fastrpc_log mask is disabled.
170- */
171- if (((1 << level ) & (fastrpc_logmask )) ||
172- ((level == HAP_LEVEL_RPC_CRITICAL ) && persist_buf .buf ) ||
173- log_userspace_file_fd != NULL ) {
165+ char * buf = NULL ;
166+
167+ if (!((1 << level ) & (fastrpc_logmask ))) {
168+ /*
169+ * Adding logs to persist buffer when level is set to
170+ * RUNTIME_RPC_CRITICAL and fastrpc_log mask is disabled.
171+ */
172+ if ((level == HAP_LEVEL_RPC_CRITICAL ) && persist_buf .buf ) {
173+ buf = (char * )malloc (sizeof (char ) * MAX_FARF_LEN );
174+ if (buf == NULL ) {
175+ return ;
176+ }
177+ va_start (argp , format );
178+ len = vsnprintf (buf , MAX_FARF_LEN , format , argp );
179+ va_end (argp );
180+ if (len > 0 && len < MAX_FARF_LEN ) {
181+ print_dbgbuf_data (buf , len );
182+ }
183+ }
184+ } else {
174185 buf = (char * )malloc (sizeof (char ) * MAX_FARF_LEN );
175186 if (buf == NULL ) {
176187 return ;
177188 }
178189 va_start (argp , format );
179190 len = vsnprintf (buf , MAX_FARF_LEN , format , argp );
180191 va_end (argp );
181- log = (char * )malloc (sizeof (char ) * MAX_FARF_LEN );
182- if (log == NULL ) {
183- return ;
192+ /*
193+ * If level is set to RUNTIME_RPC_CRITICAL append the farf message
194+ * to persist buffer.
195+ */
196+ if (IS_PERSIST_BUF_DATA (len , level )) {
197+ print_dbgbuf_data (buf , len );
184198 }
185- snprintf (log , MAX_FARF_LEN , "%d:%d:%s:%s:%d: %s" , getpid (), gettid (),
186- __progname , file , line , buf );
187- }
188-
189- print_dbgbuf_data (log , len );
190- if (((1 << level ) & (fastrpc_logmask ))) {
191199 if (log_userspace_file_fd != NULL ) {
192- fputs (log , log_userspace_file_fd );
193- fputs ("\n" , log_userspace_file_fd );
200+ char * filelog = NULL ;
201+ filelog = (char * )malloc (sizeof (char ) * MAX_FARF_LEN );
202+ if (filelog ) {
203+ if (snprintf (filelog , MAX_FARF_LEN , "%d:%d:%s:%s:%d: %s" , getpid (),
204+ gettid (), __progname , file , line , buf )) {
205+ fputs (filelog , log_userspace_file_fd );
206+ fputs ("\n" , log_userspace_file_fd );
207+ }
208+ free (filelog );
209+ }
194210 }
195211 HAP_debug (buf , level , file , line );
196212 }
197- if (buf ) {
213+
214+ if (buf )
198215 free (buf );
199- }
200- if (log ) {
201- free (log );
202- }
203216}
204217
205218#ifdef __LE_TVM__
@@ -279,28 +292,14 @@ void HAP_debug(const char *msg, int level, const char *filename, int line) {
279292}
280293
281294void fastrpc_log_init () {
282- bool debug_build_type = false;
283295 int nErr = AEE_SUCCESS , fd = -1 ;
284296 char build_type [PROPERTY_VALUE_MAX ];
285297 char * logfilename ;
286298
287299 pthread_mutex_init (& persist_buf .mut , 0 );
288300 pthread_mutex_lock (& persist_buf .mut );
289- /*
290- * Get build type by reading the target properties,
291- * if buuid type is eng or userdebug allocate 1 MB persist buf.
292- */
293- if (fastrpc_get_property_string (FASTRPC_BUILD_TYPE , build_type , NULL )) {
294- #if !defined(LE_ENABLE )
295- if (!strncmp (build_type , "eng" , PROPERTY_VALUE_MAX ) ||
296- !strncmp (build_type , "userdebug" , PROPERTY_VALUE_MAX ))
297- debug_build_type = true;
298- #else
299- if (atoi (build_type ))
300- debug_build_type = true;
301- #endif
302- }
303- if (persist_buf .buf == NULL && debug_build_type ) {
301+
302+ if (persist_buf .buf == NULL ) {
304303 /* Create a debug buffer to append DEBUG FARF level message. */
305304 persist_buf .buf = (char * )rpcmem_alloc_internal (
306305 RPCMEM_HEAP_ID_SYSTEM , RPCMEM_DEFAULT_FLAGS | RPCMEM_TRY_MAP_STATIC ,
0 commit comments