xref: /libevent-2.1.12/log-internal.h (revision 802be13a)
1169321c9SNick Mathewson /*
2b85b710cSNick Mathewson  * Copyright (c) 2000-2007 Niels Provos <[email protected]>
3e49e2891SNick Mathewson  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4169321c9SNick Mathewson  *
5169321c9SNick Mathewson  * Redistribution and use in source and binary forms, with or without
6169321c9SNick Mathewson  * modification, are permitted provided that the following conditions
7169321c9SNick Mathewson  * are met:
8169321c9SNick Mathewson  * 1. Redistributions of source code must retain the above copyright
9169321c9SNick Mathewson  *    notice, this list of conditions and the following disclaimer.
10169321c9SNick Mathewson  * 2. Redistributions in binary form must reproduce the above copyright
11169321c9SNick Mathewson  *    notice, this list of conditions and the following disclaimer in the
12169321c9SNick Mathewson  *    documentation and/or other materials provided with the distribution.
13169321c9SNick Mathewson  * 3. The name of the author may not be used to endorse or promote products
14169321c9SNick Mathewson  *    derived from this software without specific prior written permission.
15169321c9SNick Mathewson  *
16169321c9SNick Mathewson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17169321c9SNick Mathewson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18169321c9SNick Mathewson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19169321c9SNick Mathewson  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20169321c9SNick Mathewson  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21169321c9SNick Mathewson  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22169321c9SNick Mathewson  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23169321c9SNick Mathewson  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24169321c9SNick Mathewson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25169321c9SNick Mathewson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26169321c9SNick Mathewson  */
273f8c7cd0SNick Mathewson #ifndef LOG_INTERNAL_H_INCLUDED_
283f8c7cd0SNick Mathewson #define LOG_INTERNAL_H_INCLUDED_
29169321c9SNick Mathewson 
30fbe64f21SEvan Jones #include "event2/util.h"
31292467c0SNick Mathewson 
32ebd12e6dSAzat Khuzhin #ifdef __cplusplus
33ebd12e6dSAzat Khuzhin extern "C" {
34ebd12e6dSAzat Khuzhin #endif
35ebd12e6dSAzat Khuzhin 
36169321c9SNick Mathewson #ifdef __GNUC__
37169321c9SNick Mathewson #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
3833bbbed9SNick Mathewson #define EV_NORETURN __attribute__((noreturn))
39169321c9SNick Mathewson #else
40169321c9SNick Mathewson #define EV_CHECK_FMT(a,b)
4133bbbed9SNick Mathewson #define EV_NORETURN
42169321c9SNick Mathewson #endif
43169321c9SNick Mathewson 
44cb9da0bfSNick Mathewson #define EVENT_ERR_ABORT_ ((int)0xdeaddead)
4537c3456dSNick Mathewson 
4668120d9bSNick Mathewson #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
47e30a82f1SNick Mathewson #define EVENT_DEBUG_LOGGING_ENABLED
48e30a82f1SNick Mathewson #endif
49e30a82f1SNick Mathewson 
50e30a82f1SNick Mathewson #ifdef EVENT_DEBUG_LOGGING_ENABLED
51*802be13aSAzat Khuzhin EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_;
52cb9da0bfSNick Mathewson #define event_debug_get_logging_mask_() (event_debug_logging_mask_)
53e30a82f1SNick Mathewson #else
54cb9da0bfSNick Mathewson #define event_debug_get_logging_mask_() (0)
55e30a82f1SNick Mathewson #endif
56e30a82f1SNick Mathewson 
579806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
5833bbbed9SNick Mathewson void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
599806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
60169321c9SNick Mathewson void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
619806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
6233bbbed9SNick Mathewson void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
639806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
64292467c0SNick Mathewson void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
659806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
6633bbbed9SNick Mathewson void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
679806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
68169321c9SNick Mathewson void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
699806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
70169321c9SNick Mathewson void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
719806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
72cb9da0bfSNick Mathewson void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2);
73169321c9SNick Mathewson 
749806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
75e1766a1bSNick Mathewson void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
76e1766a1bSNick Mathewson 	EV_CHECK_FMT(3,0);
77e1766a1bSNick Mathewson 
78e30a82f1SNick Mathewson #ifdef EVENT_DEBUG_LOGGING_ENABLED
79e30a82f1SNick Mathewson #define event_debug(x) do {			\
80cb9da0bfSNick Mathewson 	if (event_debug_get_logging_mask_()) {	\
81cb9da0bfSNick Mathewson 		event_debugx_ x;		\
82e30a82f1SNick Mathewson 	}					\
83e30a82f1SNick Mathewson 	} while (0)
84169321c9SNick Mathewson #else
85e30a82f1SNick Mathewson #define event_debug(x) ((void)0)
86169321c9SNick Mathewson #endif
87169321c9SNick Mathewson 
88169321c9SNick Mathewson #undef EV_CHECK_FMT
89169321c9SNick Mathewson 
90ebd12e6dSAzat Khuzhin #ifdef __cplusplus
91ebd12e6dSAzat Khuzhin }
92169321c9SNick Mathewson #endif
93ebd12e6dSAzat Khuzhin 
94ebd12e6dSAzat Khuzhin #endif /* LOG_INTERNAL_H_INCLUDED_ */
95