2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2010 The FreeBSD Foundation
5 * Copyright (c) 2011 Pawel Jakub Dawidek <pjd@FreeBSD.org>
8 * This software was developed by Pawel Jakub Dawidek under sponsorship from
9 * the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/cdefs.h>
45 #define PJDLOG_MODE_STD 0
46 #define PJDLOG_MODE_SYSLOG 1
47 #define PJDLOG_MODE_SOCK 2
49 void pjdlog_init(int mode);
50 void pjdlog_fini(void);
52 void pjdlog_mode_set(int mode);
53 int pjdlog_mode_get(void);
56 void pjdlog_sock_set(int sock);
57 int pjdlog_sock_get(void);
60 void pjdlog_debug_set(int level);
61 int pjdlog_debug_get(void);
63 void pjdlog_prefix_set(const char *fmt, ...) __printflike(1, 2);
64 void pjdlogv_prefix_set(const char *fmt, va_list ap) __printflike(1, 0);
65 const char *pjdlog_prefix_get(void);
66 void pjdlog_prefix_push(const char *fmt, ...) __printflike(1, 2);
67 void pjdlogv_prefix_push(const char *fmt, va_list ap) __printflike(1, 0);
68 void pjdlog_prefix_pop(void);
70 void _pjdlogv_common(const char *func, const char *file, int line, int loglevel,
71 int debuglevel, int error, const char *fmt, va_list ap) __printflike(7, 0);
72 void _pjdlog_common(const char *func, const char *file, int line, int loglevel,
73 int debuglevel, int error, const char *fmt, ...) __printflike(7, 8);
75 void _pjdlogv_exit(const char *func, const char *file, int line, int exitcode,
76 int error, const char *fmt, va_list ap) __printflike(6, 0) __dead2;
77 void _pjdlog_exit(const char *func, const char *file, int line, int exitcode,
78 int error, const char *fmt, ...) __printflike(6, 7) __dead2;
80 void _pjdlog_abort(const char *func, const char *file, int line, int error,
81 const char *failedexpr, const char *fmt, ...) __printflike(6, 7) __dead2;
84 int pjdlog_receive(int sock);
87 #define pjdlogv_common(loglevel, debuglevel, error, fmt, ap) \
88 _pjdlogv_common(__func__, __FILE__, __LINE__, (loglevel), \
89 (debuglevel), (error), (fmt), (ap))
90 #define pjdlog_common(loglevel, debuglevel, error, ...) \
91 _pjdlog_common(__func__, __FILE__, __LINE__, (loglevel), \
92 (debuglevel), (error), __VA_ARGS__)
94 #define pjdlogv(loglevel, fmt, ap) \
95 pjdlogv_common((loglevel), 0, -1, (fmt), (ap))
96 #define pjdlog(loglevel, ...) \
97 pjdlog_common((loglevel), 0, -1, __VA_ARGS__)
99 #define pjdlogv_emergency(fmt, ap) pjdlogv(LOG_EMERG, (fmt), (ap))
100 #define pjdlog_emergency(...) pjdlog(LOG_EMERG, __VA_ARGS__)
101 #define pjdlogv_alert(fmt, ap) pjdlogv(LOG_ALERT, (fmt), (ap))
102 #define pjdlog_alert(...) pjdlog(LOG_ALERT, __VA_ARGS__)
103 #define pjdlogv_critical(fmt, ap) pjdlogv(LOG_CRIT, (fmt), (ap))
104 #define pjdlog_critical(...) pjdlog(LOG_CRIT, __VA_ARGS__)
105 #define pjdlogv_error(fmt, ap) pjdlogv(LOG_ERR, (fmt), (ap))
106 #define pjdlog_error(...) pjdlog(LOG_ERR, __VA_ARGS__)
107 #define pjdlogv_warning(fmt, ap) pjdlogv(LOG_WARNING, (fmt), (ap))
108 #define pjdlog_warning(...) pjdlog(LOG_WARNING, __VA_ARGS__)
109 #define pjdlogv_notice(fmt, ap) pjdlogv(LOG_NOTICE, (fmt), (ap))
110 #define pjdlog_notice(...) pjdlog(LOG_NOTICE, __VA_ARGS__)
111 #define pjdlogv_info(fmt, ap) pjdlogv(LOG_INFO, (fmt), (ap))
112 #define pjdlog_info(...) pjdlog(LOG_INFO, __VA_ARGS__)
114 #define pjdlog_debug(debuglevel, ...) \
115 pjdlog_common(LOG_DEBUG, (debuglevel), -1, __VA_ARGS__)
116 #define pjdlogv_debug(debuglevel, fmt, ap) \
117 pjdlogv_common(LOG_DEBUG, (debuglevel), -1, (fmt), (ap))
119 #define pjdlog_errno(loglevel, ...) \
120 pjdlog_common((loglevel), 0, (errno), __VA_ARGS__)
121 #define pjdlogv_errno(loglevel, fmt, ap) \
122 pjdlogv_common((loglevel), 0, (errno), (fmt), (ap))
124 #define pjdlogv_exit(exitcode, fmt, ap) \
125 _pjdlogv_exit(__func__, __FILE__, __LINE__, (exitcode), \
126 (errno), (fmt), (ap))
127 #define pjdlog_exit(exitcode, ...) \
128 _pjdlog_exit(__func__, __FILE__, __LINE__, (exitcode), (errno), \
131 #define pjdlogv_exitx(exitcode, fmt, ap) \
132 _pjdlogv_exit(__func__, __FILE__, __LINE__, (exitcode), -1, \
134 #define pjdlog_exitx(exitcode, ...) \
135 _pjdlog_exit(__func__, __FILE__, __LINE__, (exitcode), -1, \
138 #define PJDLOG_VERIFY(expr) do { \
140 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
144 #define PJDLOG_RVERIFY(expr, ...) do { \
146 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
150 #define PJDLOG_EVERIFY(expr) do { \
152 _pjdlog_abort(__func__, __FILE__, __LINE__, errno, \
156 #define PJDLOG_ABORT(...) _pjdlog_abort(__func__, __FILE__, \
157 __LINE__, -1, NULL, __VA_ARGS__)
159 #define PJDLOG_ASSERT(expr) do { } while (0)
160 #define PJDLOG_RASSERT(...) do { } while (0)
162 #define PJDLOG_ASSERT(expr) do { \
164 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
168 #define PJDLOG_RASSERT(expr, ...) do { \
170 _pjdlog_abort(__func__, __FILE__, __LINE__, -1, #expr, \
176 #endif /* !_PJDLOG_H_ */