xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/log-internal.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: log-internal.h,v 1.6 2024/08/18 20:47:21 christos Exp $	*/
28585484eSchristos 
38585484eSchristos /*
48585484eSchristos  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
58585484eSchristos  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
68585484eSchristos  *
78585484eSchristos  * Redistribution and use in source and binary forms, with or without
88585484eSchristos  * modification, are permitted provided that the following conditions
98585484eSchristos  * are met:
108585484eSchristos  * 1. Redistributions of source code must retain the above copyright
118585484eSchristos  *    notice, this list of conditions and the following disclaimer.
128585484eSchristos  * 2. Redistributions in binary form must reproduce the above copyright
138585484eSchristos  *    notice, this list of conditions and the following disclaimer in the
148585484eSchristos  *    documentation and/or other materials provided with the distribution.
158585484eSchristos  * 3. The name of the author may not be used to endorse or promote products
168585484eSchristos  *    derived from this software without specific prior written permission.
178585484eSchristos  *
188585484eSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198585484eSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208585484eSchristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218585484eSchristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228585484eSchristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238585484eSchristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248585484eSchristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258585484eSchristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268585484eSchristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278585484eSchristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288585484eSchristos  */
298585484eSchristos #ifndef LOG_INTERNAL_H_INCLUDED_
308585484eSchristos #define LOG_INTERNAL_H_INCLUDED_
318585484eSchristos 
328585484eSchristos #include "event2/util.h"
338585484eSchristos 
34*eabc0478Schristos #ifdef __cplusplus
35*eabc0478Schristos extern "C" {
36*eabc0478Schristos #endif
37*eabc0478Schristos 
388585484eSchristos #ifdef __GNUC__
398585484eSchristos #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
408585484eSchristos #define EV_NORETURN __attribute__((noreturn))
418585484eSchristos #else
428585484eSchristos #define EV_CHECK_FMT(a,b)
438585484eSchristos #define EV_NORETURN
448585484eSchristos #endif
458585484eSchristos 
468585484eSchristos #define EVENT_ERR_ABORT_ ((int)0xdeaddead)
478585484eSchristos 
488585484eSchristos #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
498585484eSchristos #define EVENT_DEBUG_LOGGING_ENABLED
508585484eSchristos #endif
518585484eSchristos 
528585484eSchristos #ifdef EVENT_DEBUG_LOGGING_ENABLED
53*eabc0478Schristos EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_;
548585484eSchristos #define event_debug_get_logging_mask_() (event_debug_logging_mask_)
558585484eSchristos #else
568585484eSchristos #define event_debug_get_logging_mask_() (0)
578585484eSchristos #endif
588585484eSchristos 
59*eabc0478Schristos EVENT2_EXPORT_SYMBOL
608585484eSchristos void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
61*eabc0478Schristos EVENT2_EXPORT_SYMBOL
628585484eSchristos void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
63*eabc0478Schristos EVENT2_EXPORT_SYMBOL
648585484eSchristos void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
65*eabc0478Schristos EVENT2_EXPORT_SYMBOL
668585484eSchristos void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
67*eabc0478Schristos EVENT2_EXPORT_SYMBOL
688585484eSchristos void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
69*eabc0478Schristos EVENT2_EXPORT_SYMBOL
708585484eSchristos void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
71*eabc0478Schristos EVENT2_EXPORT_SYMBOL
728585484eSchristos void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
73*eabc0478Schristos EVENT2_EXPORT_SYMBOL
748585484eSchristos void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2);
758585484eSchristos 
76*eabc0478Schristos EVENT2_EXPORT_SYMBOL
77b8ecfcfeSchristos void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
78b8ecfcfeSchristos 	EV_CHECK_FMT(3,0);
79b8ecfcfeSchristos 
808585484eSchristos #ifdef EVENT_DEBUG_LOGGING_ENABLED
818585484eSchristos #define event_debug(x) do {			\
828585484eSchristos 	if (event_debug_get_logging_mask_()) {	\
838585484eSchristos 		event_debugx_ x;		\
848585484eSchristos 	}					\
858585484eSchristos 	} while (0)
868585484eSchristos #else
878585484eSchristos #define event_debug(x) ((void)0)
888585484eSchristos #endif
898585484eSchristos 
908585484eSchristos #undef EV_CHECK_FMT
918585484eSchristos 
92*eabc0478Schristos #ifdef __cplusplus
93*eabc0478Schristos }
948585484eSchristos #endif
95*eabc0478Schristos 
96*eabc0478Schristos #endif /* LOG_INTERNAL_H_INCLUDED_ */
97