added logs
This commit is contained in:
+28
-1
@@ -21,10 +21,37 @@
|
||||
|
||||
#if ENABLE_LOGGING
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
extern FILE *log_fp;
|
||||
#define LOG(fmt, ...) do { if (log_fp) { fprintf(log_fp, "[%s] " fmt "\n", __func__, ##__VA_ARGS__); fflush(log_fp); } } while(0)
|
||||
|
||||
static inline void openuf_log_emit(FILE *stream, const char *prefix,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
char ts[32];
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", &tm);
|
||||
|
||||
fprintf(stream, "[%s]", ts);
|
||||
if (prefix && prefix[0])
|
||||
fprintf(stream, " [%s]", prefix);
|
||||
fputc(' ', stream);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stream, fmt, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stream);
|
||||
fflush(stream);
|
||||
}
|
||||
|
||||
#define LOG(fmt, ...) do { if (log_fp) openuf_log_emit(log_fp, __func__, fmt, ##__VA_ARGS__); } while(0)
|
||||
#define LOGF(stream, fmt, ...) openuf_log_emit(stream, "openuf", fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG(fmt, ...) do {} while(0)
|
||||
#define LOGF(stream, fmt, ...) do { (void)(stream); } while(0)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user