Merge tag 'samba-4.1.10' into v4-1-test
[Samba.git] / lib / tevent / tevent_debug.c
blob31da7b968366cad509e33bcb8e40caf4455d70ca
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Jelmer Vernooij 2005
7 ** NOTE! The following LGPL license applies to the tevent
8 ** library. This does NOT imply that all of Samba is released
9 ** under the LGPL
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 3 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "replace.h"
26 #include "tevent.h"
27 #include "tevent_internal.h"
29 /********************************************************************
30 * Debug wrapper functions, modeled (with lot's of code copied as is)
31 * after the ev debug wrapper functions
32 ********************************************************************/
35 this allows the user to choose their own debug function
37 int tevent_set_debug(struct tevent_context *ev,
38 void (*debug)(void *context,
39 enum tevent_debug_level level,
40 const char *fmt,
41 va_list ap) PRINTF_ATTRIBUTE(3,0),
42 void *context)
44 ev->debug_ops.debug = debug;
45 ev->debug_ops.context = context;
46 return 0;
50 debug function for ev_set_debug_stderr
52 static void tevent_debug_stderr(void *private_data,
53 enum tevent_debug_level level,
54 const char *fmt,
55 va_list ap) PRINTF_ATTRIBUTE(3,0);
56 static void tevent_debug_stderr(void *private_data,
57 enum tevent_debug_level level,
58 const char *fmt, va_list ap)
60 if (level <= TEVENT_DEBUG_WARNING) {
61 vfprintf(stderr, fmt, ap);
66 convenience function to setup debug messages on stderr
67 messages of level TEVENT_DEBUG_WARNING and higher are printed
69 int tevent_set_debug_stderr(struct tevent_context *ev)
71 return tevent_set_debug(ev, tevent_debug_stderr, ev);
75 * log a message
77 * The default debug action is to ignore debugging messages.
78 * This is the most appropriate action for a library.
79 * Applications using the library must decide where to
80 * redirect debugging messages
82 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
83 const char *fmt, ...)
85 va_list ap;
86 if (!ev) {
87 return;
89 if (ev->debug_ops.debug == NULL) {
90 return;
92 va_start(ap, fmt);
93 ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
94 va_end(ap);
97 void tevent_set_trace_callback(struct tevent_context *ev,
98 tevent_trace_callback_t cb,
99 void *private_data)
101 ev->tracing.callback = cb;
102 ev->tracing.private_data = private_data;
105 void tevent_get_trace_callback(struct tevent_context *ev,
106 tevent_trace_callback_t *cb,
107 void *private_data)
109 *cb = ev->tracing.callback;
110 *(void**)private_data = ev->tracing.private_data;
113 void tevent_trace_point_callback(struct tevent_context *ev,
114 enum tevent_trace_point tp)
116 if (ev->tracing.callback != NULL) {
117 ev->tracing.callback(tp, ev->tracing.private_data);