2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2011 Pawel Jakub Dawidek <pjd@FreeBSD.org>
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
43 #define PJDLOG_MODE_STD 0
44 #define PJDLOG_MODE_SYSLOG 1
45 #define PJDLOG_MODE_SOCK 2
47 void pjdlog_init(int mode);
48 void pjdlog_fini(void);
50 void pjdlog_mode_set(int mode);
51 int pjdlog_mode_get(void);
54 void pjdlog_sock_set(int sock);
55 int pjdlog_sock_get(void);
58 void pjdlog_debug_set(int level);
59 int pjdlog_debug_get(void);
61 void pjdlog_prefix_set(const char *fmt, ...) __printflike(1, 2);
62 void pjdlogv_prefix_set(const char *fmt, va_list ap) __printflike(1, 0);
63 const char *pjdlog_prefix_get(void);
64 void pjdlog_prefix_push(const char *fmt, ...) __printflike(1, 2);
65 void pjdlogv_prefix_push(const char *fmt, va_list ap) __printflike(1, 0);
66 void pjdlog_prefix_pop(void);
68 void _pjdlogv_common(const char *func, const char *file, int line, int loglevel,
69 int debuglevel, int error, const char *fmt, va_list ap) __printflike(7, 0);
70 void _pjdlog_common(const char *func, const char *file, int line, int loglevel,
71 int debuglevel, int error, const char *fmt, ...) __printflike(7, 8);
73 void _pjdlogv_exit(const char *func, const char *file, int line, int exitcode,
74 int error, const char *fmt, va_list ap) __printflike(6, 0) __dead2;
75 void _pjdlog_exit(const char *func, const char *file, int line, int exitcode,
76 int error, const char *fmt, ...) __printflike(6, 7) __dead2;
78 void _pjdlog_abort(const char *func, const char *file, int line, int error,
79 const char *failedexpr, const char *fmt, ...) __printflike(6, 7) __dead2;
82 int pjdlog_receive(int sock);
85 #define pjdlogv_common(loglevel, debuglevel, error, fmt, ap) \
86 _pjdlogv_common(__func__, __FILE__, __LINE__, (loglevel), \
87 (debuglevel), (error), (fmt), (ap))
88 #define pjdlog_common(loglevel, debuglevel, error, ...) \
89 _pjdlog_common(__func__, __FILE__, __LINE__, (loglevel), \
90 (debuglevel), (error), __VA_ARGS__)
92 #define pjdlogv(loglevel, fmt, ap) \
93 pjdlogv_common((loglevel), 0, -1, (fmt), (ap))
94 #define pjdlog(loglevel, ...) \
95 pjdlog_common((loglevel), 0, -1, __VA_ARGS__)
97 #define pjdlogv_emergency(fmt, ap) pjdlogv(LOG_EMERG, (fmt), (ap))
98 #define pjdlog_emergency(...) pjdlog(LOG_EMERG, __VA_ARGS__)
99 #define pjdlogv_alert(fmt, ap) pjdlogv(LOG_ALERT, (fmt), (ap))
100 #define pjdlog_alert(...) pjdlog(LOG_ALERT, __VA_ARGS__)
101 #define pjdlogv_critical(fmt, ap) pjdlogv(LOG_CRIT, (fmt), (ap))
102 #define pjdlog_critical(...) pjdlog(LOG_CRIT, __VA_ARGS__)
103 #define pjdlogv_error(fmt, ap) pjdlogv(LOG_ERR, (fmt), (ap))
104 #define pjdlog_error(...) pjdlog(LOG_ERR, __VA_ARGS__)
105 #define pjdlogv_warning(fmt, ap) pjdlogv(LOG_WARNING, (fmt), (ap))
106 #define pjdlog_warning(...) pjdlog(LOG_WARNING, __VA_ARGS__)
107 #define pjdlogv_notice(fmt, ap) pjdlogv(LOG_NOTICE, (fmt), (ap))
108 #define pjdlog_notice(...) pjdlog(LOG_NOTICE, __VA_ARGS__)
109 #define pjdlogv_info(fmt, ap) pjdlogv(LOG_INFO, (fmt), (ap))
110 #define pjdlog_info(...) pjdlog(LOG_INFO, __VA_ARGS__)
112 #define pjdlog_debug(debuglevel, ...) \
113 pjdlog_common(LOG_DEBUG, (debuglevel), -1, __VA_ARGS__)
114 #define pjdlogv_debug(debuglevel, fmt, ap) \
115 pjdlogv_common(LOG_DEBUG, (debuglevel), -1, (fmt), (ap))
117 #define pjdlog_errno(loglevel, ...) \
118 pjdlog_common((loglevel), 0, (errno), __VA_ARGS__)
119 #define pjdlogv_errno(loglevel, fmt, ap) \
120 pjdlogv_common((loglevel), 0, (errno), (fmt), (ap))
122 #define pjdlogv_exit(exitcode, fmt, ap) \
123 _pjdlogv_exit(__func__, __FILE__, __LINE__, (exitcode), \
124 (errno), (fmt), (ap))
125 #define pjdlog_exit(exitcode, ...) \
126 _pjdlog_exit(__func__, __FILE__, __LINE__, (exitcode), (errno), \
129 #define pjdlogv_exitx(exitcode, fmt, ap) \
130 _pjdlogv_exit(__func__, __FILE__, __LINE__, (exitcode), -1, \
132 #define pjdlog_exitx(exitcode, ...) \
133 _pjdlog_exit(__func__, __FILE__, __LINE__, (exitcode), -1, \
136 #define PJDLOG_VERIFY(expr) do { \
138 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
142 #define PJDLOG_RVERIFY(expr, ...) do { \
144 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
148 #define PJDLOG_EVERIFY(expr) do { \
150 _pjdlog_abort(__func__, __FILE__, __LINE__, errno, \
154 #define PJDLOG_ABORT(...) _pjdlog_abort(__func__, __FILE__, \
155 __LINE__, -1, NULL, __VA_ARGS__)
157 #define PJDLOG_ASSERT(expr) do { } while (0)
158 #define PJDLOG_RASSERT(...) do { } while (0)
160 #define PJDLOG_ASSERT(expr) do { \
162 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
166 #define PJDLOG_RASSERT(expr, ...) do { \
168 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
174 #endif /* !_PJDLOG_H_ */