From b80926797863c5a36417eb44a34483bb93610b79 Mon Sep 17 00:00:00 2001 From: PA4WDH Date: Sat, 27 May 2023 11:20:22 +0200 Subject: Add feature to use unixtime timestamps in logs and CSV --- logger.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'logger.c') diff --git a/logger.c b/logger.c index 00ee4a7..315c8c2 100644 --- a/logger.c +++ b/logger.c @@ -21,14 +21,21 @@ void logger_none(char *format,...) { } void logger_stdout(char *format,...) { va_list args; - struct timeval unixtime; - struct tm *time; + struct timeval systime; + struct tm *systime_tm; char timestring[255]; + time_t unixtime; - gettimeofday(&unixtime,NULL); - time=localtime(&unixtime.tv_sec); - strftime(timestring,255,"%F %T",time); - printf("%s: ",timestring); + if (config.use_unixtime==0) + { + gettimeofday(&systime,NULL); + systime_tm=localtime(&systime.tv_sec); + strftime(timestring,sizeof(timestring),"%F %T",systime_tm); + printf("%s: ",timestring); + } else { + unixtime=time(NULL); + printf("%ld: ",unixtime); + } va_start(args,format); vprintf(format,args); @@ -109,17 +116,24 @@ void csvlog_init() // Write a single line of CSV data void csvlog_write() { - struct timeval unixtime; - struct tm *time; + struct timeval systime; + struct tm *systime_tm; char timestring[255]; + time_t unixtime; DEBUG1_LOG("Writing data series to CSV file\n"); - gettimeofday(&unixtime,NULL); - time=localtime(&unixtime.tv_sec); - strftime(timestring,255,"%F %T",time); + if (config.use_unixtime==0) + { + gettimeofday(&systime,NULL); + systime_tm=localtime(&systime.tv_sec); + strftime(timestring,sizeof(timestring),"\"%F %T\"",systime_tm); + } else { + unixtime=time(NULL); + snprintf(timestring,sizeof(timestring),"%ld",unixtime); + } - fprintf(config.csvfile,"\"%s\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\"\n",timestring,cpudata.min_freq,cpudata.max_freq,cpudata.cur_freq,cpudata.cur_temp/1000,config.max_temp/1000,cpudata.scale_max); + fprintf(config.csvfile,"%s,\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\",\"%ld\"\n",timestring,cpudata.min_freq,cpudata.max_freq,cpudata.cur_freq,cpudata.cur_temp/1000,config.max_temp/1000,cpudata.scale_max); } // Close the CSV file -- cgit v1.2.3