xref: /netbsd-src/external/bsd/libevent/dist/log-internal.h (revision 81d2345cc4f87f54efa9edec2199119599391d4b)
1*81d2345cSrillig /*	$NetBSD: log-internal.h,v 1.7 2021/04/10 19:18:45 rillig Exp $	*/
27e68cdd7Schristos 
36ecf6635Schristos /*
46ecf6635Schristos  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
56ecf6635Schristos  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
66ecf6635Schristos  *
76ecf6635Schristos  * Redistribution and use in source and binary forms, with or without
86ecf6635Schristos  * modification, are permitted provided that the following conditions
96ecf6635Schristos  * are met:
106ecf6635Schristos  * 1. Redistributions of source code must retain the above copyright
116ecf6635Schristos  *    notice, this list of conditions and the following disclaimer.
126ecf6635Schristos  * 2. Redistributions in binary form must reproduce the above copyright
136ecf6635Schristos  *    notice, this list of conditions and the following disclaimer in the
146ecf6635Schristos  *    documentation and/or other materials provided with the distribution.
156ecf6635Schristos  * 3. The name of the author may not be used to endorse or promote products
166ecf6635Schristos  *    derived from this software without specific prior written permission.
176ecf6635Schristos  *
186ecf6635Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
196ecf6635Schristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
206ecf6635Schristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
216ecf6635Schristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
226ecf6635Schristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
236ecf6635Schristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246ecf6635Schristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256ecf6635Schristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266ecf6635Schristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
276ecf6635Schristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286ecf6635Schristos  */
290d738af4Schristos #ifndef LOG_INTERNAL_H_INCLUDED_
300d738af4Schristos #define LOG_INTERNAL_H_INCLUDED_
316ecf6635Schristos 
326ecf6635Schristos #include "event2/util.h"
336ecf6635Schristos 
347e68cdd7Schristos #ifdef __cplusplus
357e68cdd7Schristos extern "C" {
367e68cdd7Schristos #endif
377e68cdd7Schristos 
386ecf6635Schristos #ifdef __GNUC__
396c6fe893Sspz #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
406ecf6635Schristos #define EV_NORETURN __attribute__((noreturn))
416ecf6635Schristos #else
426ecf6635Schristos #define EV_CHECK_FMT(a,b)
436ecf6635Schristos #define EV_NORETURN
446ecf6635Schristos #endif
456ecf6635Schristos 
460d738af4Schristos #define EVENT_ERR_ABORT_ ((int)0xdeaddead)
470d738af4Schristos 
480d738af4Schristos #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
490d738af4Schristos #define EVENT_DEBUG_LOGGING_ENABLED
500d738af4Schristos #endif
510d738af4Schristos 
520d738af4Schristos #ifdef EVENT_DEBUG_LOGGING_ENABLED
537e68cdd7Schristos EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_;
540d738af4Schristos #define event_debug_get_logging_mask_() (event_debug_logging_mask_)
550d738af4Schristos #else
560d738af4Schristos #define event_debug_get_logging_mask_() (0)
570d738af4Schristos #endif
586ecf6635Schristos 
597e68cdd7Schristos EVENT2_EXPORT_SYMBOL
606ecf6635Schristos void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
617e68cdd7Schristos EVENT2_EXPORT_SYMBOL
626ecf6635Schristos void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
637e68cdd7Schristos EVENT2_EXPORT_SYMBOL
646ecf6635Schristos void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
657e68cdd7Schristos EVENT2_EXPORT_SYMBOL
666ecf6635Schristos void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
677e68cdd7Schristos EVENT2_EXPORT_SYMBOL
686ecf6635Schristos void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
697e68cdd7Schristos EVENT2_EXPORT_SYMBOL
706ecf6635Schristos void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
717e68cdd7Schristos EVENT2_EXPORT_SYMBOL
726ecf6635Schristos void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
737e68cdd7Schristos EVENT2_EXPORT_SYMBOL
740d738af4Schristos void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2);
756ecf6635Schristos 
767e68cdd7Schristos EVENT2_EXPORT_SYMBOL
770d738af4Schristos void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
780d738af4Schristos 	EV_CHECK_FMT(3,0);
790d738af4Schristos 
800d738af4Schristos #ifdef EVENT_DEBUG_LOGGING_ENABLED
810d738af4Schristos #define event_debug(x) do {			\
820d738af4Schristos 	if (event_debug_get_logging_mask_()) {	\
830d738af4Schristos 		event_debugx_ x;		\
840d738af4Schristos 	}					\
850d738af4Schristos 	} while (0)
866ecf6635Schristos #else
87*81d2345cSrillig #define event_debug(x) do {;} while (0)
886ecf6635Schristos #endif
896ecf6635Schristos 
906c6fe893Sspz #undef EV_CHECK_FMT
916c6fe893Sspz 
927e68cdd7Schristos #ifdef __cplusplus
937e68cdd7Schristos }
946ecf6635Schristos #endif
957e68cdd7Schristos 
967e68cdd7Schristos #endif /* LOG_INTERNAL_H_INCLUDED_ */
97