0

How do I add timestamp to the log file in ubuntu? I have the following code in my c file:

#define LOG_MSG(args, ...)  fprintf(log_file, "%-*d" args " \n", 5,line_count++, ##__VA_ARGS__);

#define LOG_ERR(args, ...) do {fprintf(log_file, "%-*d%s" args " \n",5, line_count++, "Error: ", ##__VA_ARGS__); increment_error_count();} while(0)

I tried including `date +%H:%M:%S in the above code, but it throws an error - undefined Any help is appreciated :) Thanks in advance.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621

1 Answers1

0

This answer is referred and checked from this link.

#include <time.h>
void timestamp()
{
    time_t ltime; /* calendar time */
    ltime=time(NULL); /* get current cal time */
    printf("%s",asctime( localtime(&ltime) ) );
}

Hope it helps for you.

Rathna Kumar
  • 176
  • 1
  • 10