@@ -70,6 +70,17 @@ static uint64_t __sys_now(void) {
7070 return ret ;
7171}
7272
73+ static void time_ymdhms (char * buf , size_t buflen ) {
74+ struct timeval now ;
75+ gettimeofday (& now , NULL );
76+ struct tm * tm_info = localtime (& now .tv_sec );
77+ char time_buf [20 ];
78+ strftime (time_buf , buflen , "%Y%m%d-%H:%M:%S" , tm_info );
79+ // Append milliseconds
80+ int millisec = now .tv_usec / 1000 ;
81+ snprintf (buf , buflen , "%s.%03d" , time_buf , millisec );
82+ }
83+
7384static bool callback (FileMonitor * fm , FileMonitorEvent * ev ) {
7485 if (fm -> child ) {
7586 if (fm -> pid && ev -> pid != fm -> pid ) {
@@ -169,6 +180,11 @@ static bool callback(FileMonitor *fm, FileMonitorEvent *ev) {
169180 const char * color_begin = colorful ? fm_colorstr (ev -> type ): "" ;
170181 const char * color_begin2 = colorful ? Color_MAGENTA : "" ;
171182 const char * color_end = colorful ? Color_RESET : "" ;
183+ if (fm -> show_timestamps ) {
184+ char datetime [20 ];
185+ time_ymdhms (datetime , sizeof (datetime ));
186+ printf ("%s " , datetime );
187+ }
172188 // TODO . show event type
173189 if (ev -> type == FSE_RENAME ) {
174190 printf ("%s%s%s\t%d\t\"%s%s%s\"\t%s -> %s\n" ,
@@ -221,10 +237,11 @@ static void help (const char *argv0) {
221237 " -h show this help\n"
222238 " -j output in JSON format\n"
223239 " -J output in JSON stream format\n"
224- " -n do not use colors\n"
225240 " -L list all filemonitor backends\n"
241+ " -n do not use colors\n"
226242 " -p [pid] only show events from this pid\n"
227243 " -P [proc] events only from process name\n"
244+ " -t show timestamps in default logs\n"
228245 " -v show version\n"
229246 " [path] only get events from this path\n"
230247 "Examples:\n"
@@ -261,7 +278,7 @@ int main (int argc, char **argv) {
261278 fm .backend = fmb_inotify ;
262279#endif
263280
264- while ((c = getopt (argc , argv , "a:chb:B:d:fjJlLnp:P:v " )) != -1 ) {
281+ while ((c = getopt (argc , argv , "a:chb:B:d:fjJlLnp:P:vt " )) != -1 ) {
265282 switch (c ) {
266283 case 'a' :
267284 fm .alarm = atoi (optarg );
@@ -285,6 +302,9 @@ int main (int argc, char **argv) {
285302 case 'f' :
286303 fm .fileonly = true;
287304 break ;
305+ case 't' :
306+ fm .show_timestamps = true;
307+ break ;
288308 case 'j' :
289309 fm .json = true;
290310 break ;
0 commit comments