14 #include <rc/start_stop.h> 16 #include <rc/pthread.h> 23 #define MAX_LOG_FILES 500 42 #define X(type, fmt, name) printf("%s " fmt "\n", #name, entry.name); 53 fprintf(stderr,
"ERROR: trying to log entry while logger isn't running\n");
57 fprintf(stderr,
"WARNING: logging buffer full, skipping log entry\n");
78 #define X(type, fmt, name) fprintf(fd, fmt "," , entry.name); 128 struct stat st = {0};
138 if (stat(
LOG_DIR, &st) == -1) {
144 memset(&path, 0,
sizeof(path));
145 sprintf(path,
LOG_DIR "%d.csv", i);
147 if(stat(path, &st)==0)
continue;
152 printf(
"ERROR: log file limit exceeded\n");
153 printf(
"delete old log files before continuing\n");
157 fd = fopen(path,
"w+");
159 printf(
"ERROR: can't open log file for writing\n");
163 #define X(type, fmt, name) fprintf(fd, "%s," , #name); 178 fprintf(stderr,
"ERROR in start_log_manager, failed to start thread\n");
195 if(ret==1) fprintf(stderr,
"WARNING: log_manager_thread exit timeout\n");
196 else if(ret==-1) fprintf(stderr,
"ERROR: failed to join log_manager thread\n");
int log_manager_cleanup()
Finish writing remaining data to log and close thread.
Functions to start, stop, and interact with the log manager thread.
int log_manager_init()
creates a new csv log file and starts the background thread.
int add_log_entry(log_entry_t new)
quickly add new data to local buffer
int __write_log_entry(log_entry_t entry)
void * __log_manager_func(__attribute__((unused)) void *ptr)
log_entry_t buffer[2][BUF_LEN]
int print_entry(log_entry_t entry)
Write the contents of one entry to the console.