lib/util: add samba_tevent_context_init()
[Samba/gebeck_regimport.git] / lib / util / tevent_debug.c
blob3a5a3132f99815e39a1b3874bcb14bf92161593a
1 /*
2 Unix SMB/CIFS implementation.
3 Copyright (C) Andrew Tridgell 2003
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include <tevent.h>
22 static void samba_tevent_debug(void *context,
23 enum tevent_debug_level level,
24 const char *fmt,
25 va_list ap) PRINTF_ATTRIBUTE(3,0);
27 static void samba_tevent_debug(void *context,
28 enum tevent_debug_level level,
29 const char *fmt,
30 va_list ap)
32 int samba_level = -1;
33 char *s = NULL;
34 switch (level) {
35 case TEVENT_DEBUG_FATAL:
36 samba_level = 0;
37 break;
38 case TEVENT_DEBUG_ERROR:
39 samba_level = 1;
40 break;
41 case TEVENT_DEBUG_WARNING:
42 samba_level = 2;
43 break;
44 case TEVENT_DEBUG_TRACE:
45 samba_level = 50;
46 break;
49 if (CHECK_DEBUGLVL(samba_level)) {
50 vasprintf(&s, fmt, ap);
51 if (!s) return;
52 DEBUG(samba_level, ("samba_tevent: %s", s));
53 free(s);
57 struct tevent_context *samba_tevent_context_init(TALLOC_CTX *mem_ctx)
59 struct tevent_context *ev;
61 ev = tevent_context_init(mem_ctx);
62 if (ev) {
63 tevent_set_debug(ev, samba_tevent_debug, NULL);
66 return ev;