debug: get rid of DBGC_MAX_FIXED
[Samba.git] / lib / util / debug.h
blob9baf762a045d35e5184ce452c92046a45da08796
1 /*
2 Unix SMB/CIFS implementation.
3 SMB debug stuff
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) John H Terpstra 1996-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
7 Copyright (C) Paul Ashton 1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _SAMBA_DEBUG_H
24 #define _SAMBA_DEBUG_H
26 #include <stdbool.h>
27 #include <stddef.h>
29 #include "attr.h"
32 /* -------------------------------------------------------------------------- **
33 * Debugging code. See also debug.c
36 /* the maximum debug level to compile into the code. This assumes a good
37 optimising compiler that can remove unused code
38 for embedded or low-memory systems set this to a value like 2 to get
39 only important messages. This gives *much* smaller binaries
41 #ifndef MAX_DEBUG_LEVEL
42 #define MAX_DEBUG_LEVEL 1000
43 #endif
45 bool dbgtext_va(const char *, va_list ap) PRINTF_ATTRIBUTE(1,0);
46 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
47 bool dbghdrclass( int level, int cls, const char *location, const char *func);
48 bool dbghdr( int level, const char *location, const char *func);
51 * Redefine DEBUGLEVEL because so we don't have to change every source file
52 * that *unnecessarily* references it.
54 #define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
57 * Define all new debug classes here. A class is represented by an entry in
58 * the DEBUGLEVEL_CLASS array. Index zero of this arrray is equivalent to the
59 * old DEBUGLEVEL. Any source file that does NOT add the following lines:
61 * #undef DBGC_CLASS
62 * #define DBGC_CLASS DBGC_<your class name here>
64 * at the start of the file (after #include "includes.h") will default to
65 * using index zero, so it will behaive just like it always has.
67 #define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
69 #define DBGC_TDB 1
70 #define DBGC_PRINTDRIVERS 2
71 #define DBGC_LANMAN 3
72 #define DBGC_SMB 4
73 #define DBGC_RPC_PARSE 5
74 #define DBGC_RPC_SRV 6
75 #define DBGC_RPC_CLI 7
76 #define DBGC_PASSDB 8
77 #define DBGC_SAM 9
78 #define DBGC_AUTH 10
79 #define DBGC_WINBIND 11
80 #define DBGC_VFS 12
81 #define DBGC_IDMAP 13
82 #define DBGC_QUOTA 14
83 #define DBGC_ACLS 15
84 #define DBGC_LOCKING 16
85 #define DBGC_MSDFS 17
86 #define DBGC_DMAPI 18
87 #define DBGC_REGISTRY 19
88 #define DBGC_SCAVENGER 20
89 #define DBGC_DNS 21
90 #define DBGC_LDB 22
92 /* So you can define DBGC_CLASS before including debug.h */
93 #ifndef DBGC_CLASS
94 #define DBGC_CLASS 0 /* override as shown above */
95 #endif
97 extern int *DEBUGLEVEL_CLASS;
99 /* Debugging macros
101 * DEBUGLVL()
102 * If the 'file specific' debug class level >= level OR the system-wide
103 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
104 * generate a header using the default macros for file, line, and
105 * function name. Returns True if the debug level was <= DEBUGLEVEL.
107 * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
109 * DEBUG()
110 * If the 'file specific' debug class level >= level OR the system-wide
111 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
112 * generate a header using the default macros for file, line, and
113 * function name. Each call to DEBUG() generates a new header *unless* the
114 * previous debug output was unterminated (i.e. no '\n').
115 * See debug.c:dbghdr() for more info.
117 * Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
119 * DEBUGC()
120 * If the 'macro specified' debug class level >= level OR the system-wide
121 * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
122 * generate a header using the default macros for file, line, and
123 * function name. Each call to DEBUG() generates a new header *unless* the
124 * previous debug output was unterminated (i.e. no '\n').
125 * See debug.c:dbghdr() for more info.
127 * Example: DEBUGC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
129 * DEBUGADD(), DEBUGADDC()
130 * Same as DEBUG() and DEBUGC() except the text is appended to the previous
131 * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
132 * header.
134 * Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
135 * DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
137 * Note: If the debug class has not be redeined (see above) then the optimizer
138 * will remove the extra conditional test.
142 * From talloc.c:
145 /* these macros gain us a few percent of speed on gcc */
146 #if (__GNUC__ >= 3)
147 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
148 as its first argument */
149 #ifndef likely
150 #define likely(x) __builtin_expect(!!(x), 1)
151 #endif
152 #ifndef unlikely
153 #define unlikely(x) __builtin_expect(!!(x), 0)
154 #endif
155 #else
156 #ifndef likely
157 #define likely(x) (x)
158 #endif
159 #ifndef unlikely
160 #define unlikely(x) (x)
161 #endif
162 #endif
164 #define CHECK_DEBUGLVL( level ) \
165 ( ((level) <= MAX_DEBUG_LEVEL) && \
166 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
168 #define CHECK_DEBUGLVLC( dbgc_class, level ) \
169 ( ((level) <= MAX_DEBUG_LEVEL) && \
170 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)))
172 #define DEBUGLVL( level ) \
173 ( CHECK_DEBUGLVL(level) \
174 && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
176 #define DEBUGLVLC( dbgc_class, level ) \
177 ( CHECK_DEBUGLVLC( dbgc_class, level ) \
178 && dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ ) )
180 #define DEBUG( level, body ) \
181 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
182 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
183 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
184 && (dbgtext body) )
186 #define DEBUGC( dbgc_class, level, body ) \
187 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
188 unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \
189 && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
190 && (dbgtext body) )
192 #define DEBUGADD( level, body ) \
193 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
194 unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
195 && (dbgtext body) )
197 #define DEBUGADDC( dbgc_class, level, body ) \
198 (void)( ((level) <= MAX_DEBUG_LEVEL) && \
199 unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
200 && (dbgtext body) )
202 /* Print a separator to the debug log. */
203 #define DEBUGSEP(level)\
204 DEBUG((level),("===============================================================\n"))
207 * Debug levels matching RFC 3164
209 #define DBGLVL_ERR 0 /* error conditions */
210 #define DBGLVL_WARNING 1 /* warning conditions */
211 #define DBGLVL_NOTICE 3 /* normal, but significant, condition */
212 #define DBGLVL_INFO 5 /* informational message */
213 #define DBGLVL_DEBUG 10 /* debug-level message */
215 #define DBG_ERR(...) DEBUG(DBGLVL_ERR, (__VA_ARGS__))
216 #define DBG_WARNING(...) DEBUG(DBGLVL_WARNING, (__VA_ARGS__))
217 #define DBG_NOTICE(...) DEBUG(DBGLVL_NOTICE, (__VA_ARGS__))
218 #define DBG_INFO(...) DEBUG(DBGLVL_INFO, (__VA_ARGS__))
219 #define DBG_DEBUG(...) DEBUG(DBGLVL_DEBUG, (__VA_ARGS__))
221 /* The following definitions come from lib/debug.c */
223 /** Possible destinations for the debug log (in order of precedence -
224 * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
225 * for example. This makes it easy to override for debug to stderr on
226 * the command line, as the smb.conf cannot reset it back to
227 * file-based logging */
228 enum debug_logtype {
229 DEBUG_DEFAULT_STDERR = 0,
230 DEBUG_DEFAULT_STDOUT = 1,
231 DEBUG_FILE = 2,
232 DEBUG_STDOUT = 3,
233 DEBUG_STDERR = 4,
234 DEBUG_CALLBACK = 5
237 struct debug_settings {
238 size_t max_log_size;
239 bool timestamp_logs;
240 bool debug_prefix_timestamp;
241 bool debug_hires_timestamp;
242 bool debug_pid;
243 bool debug_uid;
244 bool debug_class;
247 void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
249 void gfree_debugsyms(void);
250 int debug_add_class(const char *classname);
251 bool debug_parse_levels(const char *params_str);
252 void debug_setup_talloc_log(void);
253 void debug_set_logfile(const char *name);
254 void debug_set_settings(struct debug_settings *settings,
255 const char *logging_param,
256 int syslog_level, bool syslog_only);
257 bool reopen_logs_internal( void );
258 void force_check_log_size( void );
259 bool need_to_check_log_size( void );
260 void check_log_size( void );
261 void dbgflush( void );
262 bool dbghdrclass(int level, int cls, const char *location, const char *func);
263 bool debug_get_output_is_stderr(void);
264 bool debug_get_output_is_stdout(void);
265 void debug_schedule_reopen_logs(void);
266 char *debug_list_class_names_and_levels(void);
268 typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg);
271 Set a callback for all debug messages. Use in dlz_bind9 to push output to the bind logs
273 void debug_set_callback(void *private_ptr, debug_callback_fn fn);
275 #endif /* _SAMBA_DEBUG_H */