]> git.samba.org - metze/samba/wip.git/blob - source4/lib/ldb/common/ldb_debug.c
r3783: - don't use make proto for ldb anymore
[metze/samba/wip.git] / source4 / lib / ldb / common / ldb_debug.c
1 /* 
2    ldb database library
3
4    Copyright (C) Andrew Tridgell  2004
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 /*
26  *  Name: ldb
27  *
28  *  Component: ldb debug
29  *
30  *  Description: functions for printing debug messages
31  *
32  *  Author: Andrew Tridgell
33  */
34
35 #include "includes.h"
36 #include "ldb/include/ldb.h"
37 #include "ldb/include/ldb_private.h"
38
39
40 /*
41   this allows the user to choose their own debug function
42 */
43 int ldb_set_debug(struct ldb_context *ldb,
44                   void (*debug)(void *context, enum ldb_debug_level level, 
45                                 const char *fmt, va_list ap),
46                   void *context)
47 {
48         ldb->debug_ops.debug = debug;
49         ldb->debug_ops.context = context;
50         return 0;
51 }
52
53 /*
54   debug function for ldb_set_debug_stderr
55 */
56 static void ldb_debug_stderr(void *context, enum ldb_debug_level level, 
57                              const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
58 static void ldb_debug_stderr(void *context, enum ldb_debug_level level, 
59                              const char *fmt, va_list ap)
60 {
61         if (level <= LDB_DEBUG_WARNING) {
62                 vfprintf(stderr, fmt, ap);
63         }
64 }
65
66 /*
67   convenience function to setup debug messages on stderr
68   messages of level LDB_DEBUG_WARNING and higher are printed
69 */
70 int ldb_set_debug_stderr(struct ldb_context *ldb)
71 {
72         return ldb_set_debug(ldb, ldb_debug_stderr, ldb);
73 }
74
75 /*
76   log a message
77 */
78 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...)
79 {
80         va_list ap;
81         if (ldb->debug_ops.debug == NULL) {
82                 return;
83         }
84         va_start(ap, fmt);
85         ldb->debug_ops.debug(ldb->debug_ops.context, level, fmt, ap);
86         va_end(ap);
87 }
88