#ifndef __LOG_H_
#define __LOG_H_
+#include<pthread.h>
#include<stdarg.h>
#include<stdio.h>
extern int verbose_flag;
+extern pthread_t logging_thread;
enum log_level {
LOG_LEVEL_SILENT = 0, /* suppresses all output */
#define log_info(...) log_enqueue(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__)
#define log_msg(...) log_enqueue(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__)
+struct log_entry {
+ enum log_level level;
+ char buf[LOG_ENTRY_MAX_LENGTH];
+ FILE *out_stream;
+};
+
void log_enqueue(enum log_level,FILE*,const char*,...);
void log_message(enum log_level,FILE*,const char*,...);
void log_poll();
void log_enqueue(enum log_level level, FILE *out_stream, const char *format,...) {
va_list args;
va_start(args,format);
- vsnprintf(buf,format,args);
+// vsnprintf(buf,format,args);
va_end(args);
}
void log_message(enum log_level level, FILE *out_stream, const char *format,...) {
if(level>verbose_flag) { return; }
- if(thrd_equal(logging_thread,thrd_current())) {
- va_list args;
- va_start(args,format);
- vfprintf(out_stream,message);
- va_end(args);
- } else {
+ va_list args;
+
+ if(0==pthread_equal(pthread_self(),logging_thread)) {
log_enqueue(level,out_stream,format,...);
+ } else {
+ va_start(args,format);
+ vfprintf(out_stream,format,args);
}
+
+ va_end(args);
}
-int log_poll(void *arg) {
+void log_poll() {
while(1) {
}
-
- return 1;
}
#include<setup.h>
+pthread_t logging_thread;
+
int setup() {
- if(pthread_create(&logging_thread,&log_poll)!=0) {
+ if(pthread_create(&logging_thread,NULL,&log_poll)!=0) {
perror("pthread_create");
return -1;
}