1275970Scy/*
2275970Scy * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4275970Scy *
5275970Scy * Redistribution and use in source and binary forms, with or without
6275970Scy * modification, are permitted provided that the following conditions
7275970Scy * are met:
8275970Scy * 1. Redistributions of source code must retain the above copyright
9275970Scy *    notice, this list of conditions and the following disclaimer.
10275970Scy * 2. Redistributions in binary form must reproduce the above copyright
11275970Scy *    notice, this list of conditions and the following disclaimer in the
12275970Scy *    documentation and/or other materials provided with the distribution.
13275970Scy * 3. The name of the author may not be used to endorse or promote products
14275970Scy *    derived from this software without specific prior written permission.
15275970Scy *
16275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26275970Scy */
27275970Scy#ifndef LOG_INTERNAL_H_INCLUDED_
28275970Scy#define LOG_INTERNAL_H_INCLUDED_
29275970Scy
30275970Scy#include "event2/util.h"
31275970Scy
32275970Scy#ifdef __GNUC__
33275970Scy#define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b)))
34275970Scy#define EV_NORETURN __attribute__((noreturn))
35275970Scy#else
36275970Scy#define EV_CHECK_FMT(a,b)
37275970Scy#define EV_NORETURN
38275970Scy#endif
39275970Scy
40275970Scy#define EVENT_ERR_ABORT_ ((int)0xdeaddead)
41275970Scy
42275970Scy#define USE_GLOBAL_FOR_DEBUG_LOGGING
43275970Scy
44275970Scy#if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG)
45275970Scy#define EVENT_DEBUG_LOGGING_ENABLED
46275970Scy#endif
47275970Scy
48275970Scy#ifdef EVENT_DEBUG_LOGGING_ENABLED
49275970Scy#ifdef USE_GLOBAL_FOR_DEBUG_LOGGING
50275970Scyextern ev_uint32_t event_debug_logging_mask_;
51275970Scy#define event_debug_get_logging_mask_() (event_debug_logging_mask_)
52275970Scy#else
53275970Scyev_uint32_t event_debug_get_logging_mask_(void);
54275970Scy#endif
55275970Scy#else
56275970Scy#define event_debug_get_logging_mask_() (0)
57275970Scy#endif
58275970Scy
59275970Scyvoid event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
60275970Scyvoid event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2);
61275970Scyvoid event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN;
62275970Scyvoid event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3);
63275970Scyvoid event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN;
64275970Scyvoid event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2);
65275970Scyvoid event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2);
66275970Scyvoid event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2);
67275970Scy
68275970Scyvoid event_logv_(int severity, const char *errstr, const char *fmt, va_list ap)
69275970Scy	EV_CHECK_FMT(3,0);
70275970Scy
71275970Scy#ifdef EVENT_DEBUG_LOGGING_ENABLED
72275970Scy#define event_debug(x) do {			\
73275970Scy	if (event_debug_get_logging_mask_()) {	\
74275970Scy		event_debugx_ x;		\
75275970Scy	}					\
76275970Scy	} while (0)
77275970Scy#else
78275970Scy#define event_debug(x) ((void)0)
79275970Scy#endif
80275970Scy
81275970Scy#undef EV_CHECK_FMT
82275970Scy
83275970Scy#endif
84