10
10
#include <dirent.h>
11
11
#include <errno.h>
12
12
#include <fcntl.h>
13
+ #include <libgen.h>
13
14
#include <limits.h>
14
15
#include <pthread.h>
15
16
#include <stdarg.h>
21
22
#include <sys/time.h>
22
23
#include <sys/types.h>
23
24
#include <sys/wait.h>
24
- #include <libgen.h>
25
25
#include <unistd.h>
26
26
27
27
#ifndef likely
@@ -103,13 +103,13 @@ struct tlog_segment_log_head {
103
103
struct tlog_loginfo info ;
104
104
unsigned short len ;
105
105
char data [0 ];
106
- } __attribute__((packed ));
106
+ } __attribute__((packed ));
107
107
108
108
struct tlog_segment_head {
109
109
unsigned int magic ;
110
110
unsigned short len ;
111
111
char data [0 ];
112
- } __attribute__((packed ));
112
+ } __attribute__((packed ));
113
113
114
114
struct oldest_log {
115
115
char name [TLOG_LOG_NAME_LEN ];
@@ -172,8 +172,8 @@ static int _tlog_mkdir(const char *path)
172
172
if (access (path , F_OK ) == 0 ) {
173
173
return 0 ;
174
174
}
175
-
176
- while (* path == ' ' && * path != '\0' ) {
175
+
176
+ while (* path == ' ' && * path != '\0' ) {
177
177
path ++ ;
178
178
}
179
179
@@ -297,10 +297,10 @@ void tlog_set_maxline_size(struct tlog_log *log, int size)
297
297
298
298
if (size < TLOG_MIN_LINE_SIZE_SET ) {
299
299
size = TLOG_MIN_LINE_SIZE_SET ;
300
- } else if ( size > TLOG_MAX_LINE_SIZE_SET ) {
300
+ } else if (size > TLOG_MAX_LINE_SIZE_SET ) {
301
301
size = TLOG_MAX_LINE_SIZE_SET ;
302
- }
303
-
302
+ }
303
+
304
304
log -> max_line_size = size ;
305
305
}
306
306
@@ -309,7 +309,8 @@ int tlog_localtime(struct tlog_time *tm)
309
309
return _tlog_gettime (tm );
310
310
}
311
311
312
- tlog_log * tlog_get_root () {
312
+ tlog_log * tlog_get_root ()
313
+ {
313
314
return tlog .root ;
314
315
}
315
316
@@ -336,19 +337,19 @@ static int _tlog_format(char *buff, int maxlen, struct tlog_loginfo *info, void
336
337
int len = 0 ;
337
338
int total_len = 0 ;
338
339
struct tlog_time * tm = & info -> time ;
339
- void * unused __attribute__ ((unused ));
340
+ void * unused __attribute__((unused ));
340
341
341
342
unused = userptr ;
342
343
343
344
if (tlog .root -> multi_log ) {
344
345
/* format prefix */
345
- len = snprintf (buff , maxlen , "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5d][%4s][%17s:%-4d] " ,
346
- tm -> year , tm -> mon , tm -> mday , tm -> hour , tm -> min , tm -> sec , tm -> usec / 1000 , getpid (),
346
+ len = snprintf (buff , maxlen , "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5d][%4s][%17s:%-4d] " ,
347
+ tm -> year , tm -> mon , tm -> mday , tm -> hour , tm -> min , tm -> sec , tm -> usec / 1000 , getpid (),
347
348
tlog_get_level_string (info -> level ), info -> file , info -> line );
348
349
} else {
349
350
/* format prefix */
350
- len = snprintf (buff , maxlen , "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5s][%17s:%-4d] " ,
351
- tm -> year , tm -> mon , tm -> mday , tm -> hour , tm -> min , tm -> sec , tm -> usec / 1000 ,
351
+ len = snprintf (buff , maxlen , "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5s][%17s:%-4d] " ,
352
+ tm -> year , tm -> mon , tm -> mday , tm -> hour , tm -> min , tm -> sec , tm -> usec / 1000 ,
352
353
tlog_get_level_string (info -> level ), info -> file , info -> line );
353
354
}
354
355
@@ -384,7 +385,7 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
384
385
}
385
386
386
387
if (tlog .root -> segment_log ) {
387
- log_head = (struct tlog_segment_log_head * ) buff ;
388
+ log_head = (struct tlog_segment_log_head * )buff ;
388
389
len += sizeof (* log_head );
389
390
memcpy (& log_head -> info , & info_inter -> info , sizeof (log_head -> info ));
390
391
}
@@ -425,7 +426,7 @@ static int _tlog_print_buffer(char *buff, int maxlen, void *userptr, const char
425
426
{
426
427
int len ;
427
428
int total_len = 0 ;
428
- void * unused __attribute__ ((unused ));
429
+ void * unused __attribute__((unused ));
429
430
430
431
unused = userptr ;
431
432
@@ -527,7 +528,7 @@ static int _tlog_vprintf(struct tlog_log *log, vprint_callback print_callback, v
527
528
pthread_mutex_unlock (& tlog .lock );
528
529
return -1 ;
529
530
}
530
-
531
+
531
532
pthread_mutex_unlock (& tlog .lock );
532
533
pthread_mutex_lock (& log -> lock );
533
534
log -> waiters ++ ;
@@ -587,12 +588,12 @@ int tlog_printf(struct tlog_log *log, const char *format, ...)
587
588
return len ;
588
589
}
589
590
590
- static int _tlog_early_print (const char * format , va_list ap )
591
+ static int _tlog_early_print (const char * format , va_list ap )
591
592
{
592
593
char log_buf [TLOG_MAX_LINE_LEN ];
593
594
size_t len = 0 ;
594
595
size_t out_len = 0 ;
595
- int unused __attribute__ ((unused ));
596
+ int unused __attribute__((unused ));
596
597
597
598
if (tlog_disable_early_print ) {
598
599
return 0 ;
@@ -668,13 +669,13 @@ static int _tlog_rename_logfile(struct tlog_log *log, const char *log_file)
668
669
return -1 ;
669
670
}
670
671
671
- snprintf (archive_file , sizeof (archive_file ), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%s" ,
672
+ snprintf (archive_file , sizeof (archive_file ), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%s" ,
672
673
log -> logdir , log -> logname , logtime .year , logtime .mon , logtime .mday ,
673
674
logtime .hour , logtime .min , logtime .sec , log -> suffix );
674
675
675
676
while (access (archive_file , F_OK ) == 0 ) {
676
677
i ++ ;
677
- snprintf (archive_file , sizeof (archive_file ), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d-%d%s" ,
678
+ snprintf (archive_file , sizeof (archive_file ), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d-%d%s" ,
678
679
log -> logdir , log -> logname , logtime .year , logtime .mon ,
679
680
logtime .mday , logtime .hour , logtime .min , logtime .sec , i , log -> suffix );
680
681
}
@@ -691,7 +692,7 @@ static int _tlog_list_dir(const char *path, list_callback callback, void *userpt
691
692
DIR * dir = NULL ;
692
693
struct dirent * ent ;
693
694
int ret = 0 ;
694
- const char * unused __attribute__ ((unused )) = path ;
695
+ const char * unused __attribute__((unused )) = path ;
695
696
696
697
dir = opendir (path );
697
698
if (dir == NULL ) {
@@ -724,7 +725,7 @@ static int _tlog_count_log_callback(const char *path, struct dirent *entry, void
724
725
struct count_log * count_log = (struct count_log * )userptr ;
725
726
struct tlog_log * log = count_log -> log ;
726
727
char logname [TLOG_LOG_NAME_LEN * 2 ];
727
- const char * unused __attribute__ ((unused )) = path ;
728
+ const char * unused __attribute__((unused )) = path ;
728
729
729
730
if (strstr (entry -> d_name , log -> suffix ) == NULL ) {
730
731
return 0 ;
@@ -1064,14 +1065,14 @@ void _tlog_get_log_name_dir(struct tlog_log *log)
1064
1065
strncpy (log_file , log -> pending_logfile , PATH_MAX );
1065
1066
log_file [sizeof (log_file ) - 1 ] = '\0' ;
1066
1067
strncpy (log -> logname , basename (log_file ), sizeof (log -> logname ));
1067
- log -> logname [sizeof (log -> logname ) - 1 ] = '\0' ;
1068
+ log -> logname [sizeof (log -> logname ) - 1 ] = '\0' ;
1068
1069
pthread_mutex_unlock (& tlog .lock );
1069
1070
}
1070
1071
1071
1072
static int _tlog_write (struct tlog_log * log , const char * buff , int bufflen )
1072
1073
{
1073
1074
int len ;
1074
- int unused __attribute__ ((unused ));
1075
+ int unused __attribute__((unused ));
1075
1076
1076
1077
if (bufflen <= 0 || log -> fail ) {
1077
1078
return 0 ;
@@ -1082,7 +1083,7 @@ static int _tlog_write(struct tlog_log *log, const char *buff, int bufflen)
1082
1083
log -> rename_pending = 0 ;
1083
1084
}
1084
1085
1085
- /* output log to screen */
1086
+ /* output log to screen */
1086
1087
if (log -> logscreen ) {
1087
1088
unused = write (STDOUT_FILENO , buff , bufflen );
1088
1089
}
@@ -1181,7 +1182,6 @@ static int _tlog_any_has_data_locked(void)
1181
1182
return 0 ;
1182
1183
}
1183
1184
1184
-
1185
1185
static int _tlog_any_has_data (void )
1186
1186
{
1187
1187
int ret = 0 ;
@@ -1212,7 +1212,7 @@ static int _tlog_wait_pids(void)
1212
1212
continue ;
1213
1213
}
1214
1214
1215
- last_log = next ;
1215
+ last_log = next ;
1216
1216
next -> last_waitpid = now ;
1217
1217
pthread_mutex_unlock (& tlog .lock );
1218
1218
_tlog_wait_pid (next , 0 );
@@ -1313,7 +1313,6 @@ static void _tlog_wakeup_waiters(struct tlog_log *log)
1313
1313
pthread_mutex_unlock (& log -> lock );
1314
1314
}
1315
1315
1316
-
1317
1316
static void _tlog_write_one_segment_log (struct tlog_log * log , char * buff , int bufflen )
1318
1317
{
1319
1318
struct tlog_segment_head * segment_head = NULL ;
@@ -1395,10 +1394,10 @@ static void *_tlog_work(void *arg)
1395
1394
int log_dropped = 0 ;
1396
1395
struct tlog_log * log = NULL ;
1397
1396
struct tlog_log * loop_log = NULL ;
1398
- void * unused __attribute__ ((unused ));
1397
+ void * unused __attribute__((unused ));
1399
1398
1400
1399
unused = arg ;
1401
-
1400
+
1402
1401
while (1 ) {
1403
1402
log_len = 0 ;
1404
1403
log_extlen = 0 ;
@@ -1480,7 +1479,7 @@ static void *_tlog_work(void *arg)
1480
1479
1481
1480
void tlog_set_early_printf (int enable )
1482
1481
{
1483
- tlog_disable_early_print = (enable == 0 ) ? 1 : 0 ;
1482
+ tlog_disable_early_print = (enable == 0 ) ? 1 : 0 ;
1484
1483
}
1485
1484
1486
1485
const char * tlog_get_level_string (tlog_level level )
@@ -1662,23 +1661,26 @@ void tlog_rename_logfile(struct tlog_log *log, const char *logfile)
1662
1661
log -> rename_pending = 1 ;
1663
1662
}
1664
1663
1665
- static void tlog_fork_prepare () {
1664
+ static void tlog_fork_prepare ()
1665
+ {
1666
1666
if (tlog .root == NULL ) {
1667
1667
return ;
1668
1668
}
1669
1669
1670
1670
pthread_mutex_lock (& tlog .lock );
1671
1671
}
1672
1672
1673
- static void tlog_fork_parent () {
1673
+ static void tlog_fork_parent ()
1674
+ {
1674
1675
if (tlog .root == NULL ) {
1675
1676
return ;
1676
1677
}
1677
1678
1678
1679
pthread_mutex_unlock (& tlog .lock );
1679
1680
}
1680
1681
1681
- static void tlog_fork_child () {
1682
+ static void tlog_fork_child ()
1683
+ {
1682
1684
pthread_attr_t attr ;
1683
1685
tlog_log * next ;
1684
1686
if (tlog .root == NULL ) {
@@ -1701,7 +1703,6 @@ static void tlog_fork_child() {
1701
1703
}
1702
1704
out :
1703
1705
pthread_mutex_unlock (& tlog .lock );
1704
-
1705
1706
}
1706
1707
1707
1708
int tlog_init (const char * logfile , int maxlogsize , int maxlogcount , int buffsize , unsigned int flag )
0 commit comments