#ifndef LOG_H
#define LOG_H

#include <stdio.h>
#include <time.h>

#define LOG_LEVEL_ERR  0
#define LOG_LEVEL_INFO 1
#define LOG_LEVEL_DBG  2

#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_LEVEL_INFO
#endif

#define LOG_FMT(level, ...)                \
	do {                                   \
		fprintf(stderr, "[%s] ", level); \
		fprintf(stderr, __VA_ARGS__);      \
		fprintf(stderr, "\n");             \
	} while (0)

#define LOG_ERR(...) \
	LOG_FMT("ERR",  __VA_ARGS__)

#if LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_INFO(...) \
	LOG_FMT("INFO", __VA_ARGS__)
#else
#define LOG_INFO(...) do {} while (0)
#endif

#if LOG_LEVEL >= LOG_LEVEL_DBG
#define LOG_DBG(...) \
	LOG_FMT("DBG",  __VA_ARGS__)
#else
#define LOG_DBG(...) do {} while (0)
#endif

#endif /* LOG_H */
