feat: allow setting log level
parent
eff1b13065
commit
3b1df332a3
|
@ -6,6 +6,8 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern const char *log_level_names[];
|
||||
|
||||
typedef enum log_level {
|
||||
log_level_debug = 0,
|
||||
log_level_info = 1,
|
||||
|
@ -14,10 +16,12 @@ typedef enum log_level {
|
|||
log_level_critical = 4,
|
||||
} log_level;
|
||||
|
||||
extern const char *log_level_names[];
|
||||
extern log_level _log_level;
|
||||
|
||||
void _lander_log(log_level level, FILE *f, const char *fmt, ...);
|
||||
|
||||
#define log_level(level) _log_level = level
|
||||
|
||||
#define flog(level, f, ...) _lander_log(level, f, __VA_ARGS__)
|
||||
#define log(level, ...) _lander_log(level, NULL, __VA_ARGS__)
|
||||
#define debug(...) _lander_log(log_level_debug, NULL, __VA_ARGS__)
|
||||
|
|
|
@ -45,6 +45,7 @@ static bool add_entry(char **key_ptr, int *key_len_ptr, http_loop_ctx *ctx,
|
|||
buf[key_len + 1] = '\0';
|
||||
|
||||
http_res_add_header(&ctx->res, http_header_location, buf, true);
|
||||
ctx->res.status = http_created;
|
||||
|
||||
if (key_ptr != NULL) {
|
||||
*key_ptr = key;
|
||||
|
|
|
@ -5,7 +5,13 @@
|
|||
const char *log_level_names[] = {"DEBUG", "INFO ", "WARN ", "ERROR",
|
||||
"CRITICAL"};
|
||||
|
||||
log_level _log_level = log_level_debug;
|
||||
|
||||
void _lander_log(log_level level, FILE *f, const char *fmt, ...) {
|
||||
if (level < _log_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Log to stdout by default
|
||||
f = (f == NULL) ? stdout : f;
|
||||
|
||||
|
|
Loading…
Reference in New Issue