xref: /freebsd-src/contrib/libevent/log-internal.h (revision b50261e21f39a6c7249a49e7b60aa878c98512a8)
1c43e99fdSEd Maste /*
2c43e99fdSEd Maste  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3c43e99fdSEd Maste  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4c43e99fdSEd Maste  *
5c43e99fdSEd Maste  * Redistribution and use in source and binary forms, with or without
6c43e99fdSEd Maste  * modification, are permitted provided that the following conditions
7c43e99fdSEd Maste  * are met:
8c43e99fdSEd Maste  * 1. Redistributions of source code must retain the above copyright
9c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer.
10c43e99fdSEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
11c43e99fdSEd Maste  *    notice, this list of conditions and the following disclaimer in the
12c43e99fdSEd Maste  *    documentation and/or other materials provided with the distribution.
13c43e99fdSEd Maste  * 3. The name of the author may not be used to endorse or promote products
14c43e99fdSEd Maste  *    derived from this software without specific prior written permission.
15c43e99fdSEd Maste  *
16c43e99fdSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17c43e99fdSEd Maste  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18c43e99fdSEd Maste  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19c43e99fdSEd Maste  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20c43e99fdSEd Maste  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21c43e99fdSEd Maste  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22c43e99fdSEd Maste  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23c43e99fdSEd Maste  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24c43e99fdSEd Maste  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25c43e99fdSEd Maste  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26c43e99fdSEd Maste  */
27c43e99fdSEd Maste #ifndef LOG_INTERNAL_H_INCLUDED_
28c43e99fdSEd Maste #define LOG_INTERNAL_H_INCLUDED_
29c43e99fdSEd Maste 
30c43e99fdSEd Maste #include "event2/util.h"
31c43e99fdSEd Maste 
32*b50261e2SCy Schubert #ifdef __cplusplus
33*b50261e2SCy Schubert extern "C" {
34*b50261e2SCy Schubert #endif
35*b50261e2SCy Schubert 
36c43e99fdSEd Maste #ifdef __GNUC__
37c43e99fdSEd Maste #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
38c43e99fdSEd Maste #define EV_NORETURN __attribute__((noreturn))
39c43e99fdSEd Maste #else
40c43e99fdSEd Maste #define EV_CHECK_FMT(a,b)
41c43e99fdSEd Maste #define EV_NORETURN
42c43e99fdSEd Maste #endif
43c43e99fdSEd Maste 
44c43e99fdSEd Maste #define EVENT_ERR_ABORT_ ((int)0xdeaddead)
45c43e99fdSEd Maste 
46c43e99fdSEd Maste #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
47c43e99fdSEd Maste #define EVENT_DEBUG_LOGGING_ENABLED
48c43e99fdSEd Maste #endif
49c43e99fdSEd Maste 
50c43e99fdSEd Maste #ifdef EVENT_DEBUG_LOGGING_ENABLED
51*b50261e2SCy Schubert EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_;
52c43e99fdSEd Maste #define event_debug_get_logging_mask_() (event_debug_logging_mask_)
53c43e99fdSEd Maste #else
54c43e99fdSEd Maste #define event_debug_get_logging_mask_() (0)
55c43e99fdSEd Maste #endif
56c43e99fdSEd Maste 
57*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
58c43e99fdSEd Maste void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
59*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
60c43e99fdSEd Maste void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
61*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
62c43e99fdSEd Maste void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
63*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
64c43e99fdSEd Maste void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
65*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
66c43e99fdSEd Maste void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
67*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
68c43e99fdSEd Maste void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
69*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
70c43e99fdSEd Maste void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
71*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
72c43e99fdSEd Maste void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2);
73c43e99fdSEd Maste 
74*b50261e2SCy Schubert EVENT2_EXPORT_SYMBOL
75c43e99fdSEd Maste void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
76c43e99fdSEd Maste 	EV_CHECK_FMT(3,0);
77c43e99fdSEd Maste 
78c43e99fdSEd Maste #ifdef EVENT_DEBUG_LOGGING_ENABLED
79c43e99fdSEd Maste #define event_debug(x) do {			\
80c43e99fdSEd Maste 	if (event_debug_get_logging_mask_()) {	\
81c43e99fdSEd Maste 		event_debugx_ x;		\
82c43e99fdSEd Maste 	}					\
83c43e99fdSEd Maste 	} while (0)
84c43e99fdSEd Maste #else
85c43e99fdSEd Maste #define event_debug(x) ((void)0)
86c43e99fdSEd Maste #endif
87c43e99fdSEd Maste 
88c43e99fdSEd Maste #undef EV_CHECK_FMT
89c43e99fdSEd Maste 
90*b50261e2SCy Schubert #ifdef __cplusplus
91*b50261e2SCy Schubert }
92c43e99fdSEd Maste #endif
93*b50261e2SCy Schubert 
94*b50261e2SCy Schubert #endif /* LOG_INTERNAL_H_INCLUDED_ */
95