@@ -62,16 +62,12 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
6262 time_t now_sec = a_thread -> event -> time_stamp .tv_sec ;
6363 struct tm * time ;
6464 time_t * time_sec ;
65- typedef struct tm * (* zlog_spec_time_fn ) (const time_t * , struct tm * );
66- zlog_spec_time_fn time_stamp_convert_function ;
6765 if ( use_utc ) {
6866 time = & (a_thread -> event -> time_utc );
6967 time_sec = & (a_thread -> event -> time_utc_sec );
70- time_stamp_convert_function = gmtime_r ;
7168 } else {
7269 time = & (a_thread -> event -> time_local );
7370 time_sec = & (a_thread -> event -> time_local_sec );
74- time_stamp_convert_function = localtime_r ;
7571 }
7672
7773 /* the event meet the 1st time_spec in his life cycle */
@@ -82,7 +78,11 @@ static int zlog_spec_write_time_internal(zlog_spec_t * a_spec, zlog_thread_t * a
8278
8379 /* When this event's last cached time_local is not now */
8480 if (* time_sec != now_sec ) {
85- time_stamp_convert_function (& (now_sec ), time );
81+ if (use_utc ) {
82+ gmtime_r (& (now_sec ), time );
83+ } else {
84+ localtime_r (& (now_sec ), time );
85+ }
8686 * time_sec = now_sec ;
8787 }
8888
@@ -241,7 +241,7 @@ static int zlog_spec_write_pid(zlog_spec_t * a_spec, zlog_thread_t * a_thread, z
241241 if (a_thread -> event -> pid != a_thread -> event -> last_pid ) {
242242 a_thread -> event -> last_pid = a_thread -> event -> pid ;
243243 a_thread -> event -> pid_str_len
244- = sprintf (a_thread -> event -> pid_str , "%u " , a_thread -> event -> pid );
244+ = sprintf (a_thread -> event -> pid_str , "%ld " , ( long ) a_thread -> event -> pid );
245245 }
246246 }
247247
@@ -264,13 +264,15 @@ static int zlog_spec_write_tid_long(zlog_spec_t * a_spec, zlog_thread_t * a_thre
264264 return zlog_buf_append (a_buf , a_thread -> event -> tid_str , a_thread -> event -> tid_str_len );
265265}
266266
267+ #if defined __linux__ || __APPLE__
267268static int zlog_spec_write_ktid (zlog_spec_t * a_spec , zlog_thread_t * a_thread , zlog_buf_t * a_buf )
268269{
269270
270271 /* don't need to get ktid again, as tmap_new_thread fetched it already */
271272 /* and fork not change tid */
272273 return zlog_buf_append (a_buf , a_thread -> event -> ktid_str , a_thread -> event -> ktid_str_len );
273274}
275+ #endif
274276
275277static int zlog_spec_write_level_lowercase (zlog_spec_t * a_spec , zlog_thread_t * a_thread , zlog_buf_t * a_buf )
276278{
@@ -647,9 +649,11 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
647649 case 'H' :
648650 a_spec -> write_buf = zlog_spec_write_hostname ;
649651 break ;
652+ #if defined __linux__ || __APPLE__
650653 case 'k' :
651654 a_spec -> write_buf = zlog_spec_write_ktid ;
652655 break ;
656+ #endif
653657 case 'L' :
654658 a_spec -> write_buf = zlog_spec_write_srcline ;
655659 break ;
0 commit comments