summaryrefslogtreecommitdiff
path: root/src/log.h
blob: d53b79523160396cabbe1c78432fbaa4065e4072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef __LOG_H
#define __LOG_H

#include "config.h"

#if CONFIG_USE_SYSLOG
# include <syslog.h>
# define LOG_FACILITY		LOG_USER

# define __log(level, name, format, args...) \
	syslog(LOG_FACILITY | level, "[" name "] %s:%s:%d: " format "\n" , \
			__FILE__ , __func__ , __LINE__ , ## args)
#else
# define __log(level, name, format, args...) \
	fprintf(stderr, "[" name "] %s:%s:%d: " format "\n" , \
			__FILE__ , __func__ , __LINE__ , ## args)
#endif

#define log_emerg(format, args...)	__log(LOG_EMERG, "EMERG", format , ## args)
#define log_alert(format, args...)	__log(LOG_ALERT, "ALERT", format , ## args)
#define log_crit(format, args...)	__log(LOG_CRIT, "CRIT", format , ## args)
#define log_error(format, args...)	__log(LOG_ERR, "ERROR", format , ## args)
#define log_warning(format, args...)	__log(LOG_WARNING, "WARNING", format , ## args)
#define log_notice(format, args...)	__log(LOG_NOTICE, "NOTICE", format , ## args)
#define log_info(format, args...)	__log(LOG_INFO, "INFO", format , ## args)
#if DEBUG
#  define log_debug(format, args...)	__log(LOG_DEBUG, "DEBUG", format , ## args)
#else
#  define log_debug(format, args...) do {} while (0)
#endif

#if DEBUG
# define debug_buffer(msg, buf, len) \
do { \
	__log(LOG_DEBUG, "DEBUG", msg " \"%.*J\"", len, buf); \
} while (0)
#else
# define debug_buffer(_msg, _buf, _len) do { } while (0)
#endif

#define BUG(format, args...) \
do { \
  log_emerg("BUG: " format , ## args); \
  exit(124); \
} while (0)

#endif /* ~__LOG_H */