using debug() in getconfig()
[radsecproxy.git] / debug.c
1 /*
2  * Copyright (C) 2007 Stig Venaas <venaas@uninett.no>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  */
8
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <stdarg.h>
13 #include "debug.h"
14
15 static uint8_t debug_level = DBG_WARN;
16
17 void debug_set_level(uint8_t level) {
18     debug_level = level;
19 }
20
21 void debug(uint8_t level, char *format, ...) {
22     if (level >= debug_level) {
23         va_list ap;
24         va_start(ap, format);
25         vfprintf(stderr, format, ap);
26         va_end(ap);
27         fprintf(stderr, "\n");
28     }
29     if (level >= DBG_ERR)
30         exit(1);
31 }