Skip to content

Commit

Permalink
使用一种全新的日志输出方式
Browse files Browse the repository at this point in the history
  • Loading branch information
chase535 authored Dec 10, 2023
1 parent f0005e4 commit 8d431cc
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions accurate_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
#include "sys/types.h"
#include "sys/stat.h"

#define printf_with_time(FORMAT,...)\
{\
get_utc8_time(&time_utc8_now);\
printf("[ %04d.%02d.%02d %02d:%02d:%02d UTC+8 ] "FORMAT"\n", time_utc8_now.tm_year, time_utc8_now.tm_mon, time_utc8_now.tm_mday, time_utc8_now.tm_hour, time_utc8_now.tm_min, time_utc8_now.tm_sec, ##__VA_ARGS__);\
fflush(stdout);\
}

struct tm time_utc8_now;

void get_utc8_time(struct tm *ptm)
{
time_t cur_time;
Expand Down Expand Up @@ -70,6 +61,20 @@ void get_utc8_time(struct tm *ptm)
}
}

void printf_with_time(const char *format, ...) __attribute__((__format__(__printf__, 1, 2)));
void printf_with_time(const char *format, ...)
{
char buffer[1024];
struct tm time_utc8_now;
va_list ap;
va_start(ap, format);
vsnprintf(buffer, 1024, format, ap);
va_end(ap);
get_utc8_time(&time_utc8_now);
printf("[ %04d.%02d.%02dT%02d:%02d:%02d UTC+8 ] %s\n", time_utc8_now.tm_year, time_utc8_now.tm_mon, time_utc8_now.tm_mday, time_utc8_now.tm_hour, time_utc8_now.tm_min, time_utc8_now.tm_sec, buffer);
fflush(stdout);
}

void set_value(char *file, char *numb)
{
FILE *fn;
Expand Down

0 comments on commit 8d431cc

Please sign in to comment.