This source file includes following definitions.
- crm_extended_logging
1
2
3
4
5
6
7
8
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14
15
16
17
18
19
20 #ifndef CRM_LOGGING__H
21 # define CRM_LOGGING__H
22
23 # include <stdio.h>
24 # include <glib.h>
25 # include <qb/qblog.h>
26 # include <libxml/tree.h>
27
28
29
30
31
32
33
34
35 # ifndef LOG_TRACE
36 # define LOG_TRACE (LOG_DEBUG+1)
37 # endif
38
39
40 # ifndef LOG_STDOUT
41 # define LOG_STDOUT 254
42 # endif
43
44
45 # ifndef LOG_NEVER
46 # define LOG_NEVER 255
47 # endif
48
49
50 #ifdef QB_XS
51 # define CRM_XS QB_XS
52 # define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
53 #else
54 # define CRM_XS "|"
55
56
57
58
59
60 static inline int
61 crm_extended_logging(int t, int e)
62 {
63 return 0;
64 }
65 #endif
66
67 extern unsigned int crm_log_level;
68 extern unsigned int crm_trace_nonlog;
69
70
71
72
73
74
75 extern gboolean crm_config_error;
76
77
78
79
80
81
82 extern gboolean crm_config_warning;
83
84 enum xml_log_options
85 {
86 xml_log_option_filtered = 0x0001,
87 xml_log_option_formatted = 0x0002,
88 xml_log_option_text = 0x0004,
89 xml_log_option_full_fledged = 0x0008,
90 xml_log_option_diff_plus = 0x0010,
91 xml_log_option_diff_minus = 0x0020,
92 xml_log_option_diff_short = 0x0040,
93 xml_log_option_diff_all = 0x0100,
94 xml_log_option_dirty_add = 0x1000,
95 xml_log_option_open = 0x2000,
96 xml_log_option_children = 0x4000,
97 xml_log_option_close = 0x8000,
98 };
99
100 void crm_enable_blackbox(int nsig);
101 void crm_disable_blackbox(int nsig);
102 void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
103
104 void crm_update_callsites(void);
105
106 void crm_log_deinit(void);
107
108 void crm_log_preinit(const char *entity, int argc, char **argv);
109 gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon,
110 gboolean to_stderr, int argc, char **argv, gboolean quiet);
111
112 void crm_log_args(int argc, char **argv);
113 void crm_log_output_fn(const char *file, const char *function, int line, int level,
114 const char *prefix, const char *output);
115
116
117 #define crm_log_output(level, prefix, output) \
118 crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)
119
120 void crm_bump_log_level(int argc, char **argv);
121
122 void crm_enable_stderr(int enable);
123
124 gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags);
125
126 void log_data_element(int log_level, const char *file, const char *function, int line,
127 const char *prefix, xmlNode * data, int depth, gboolean formatted);
128
129
130 unsigned int set_crm_log_level(unsigned int level);
131
132 unsigned int get_crm_log_level(void);
133
134
135
136
137
138
139 #if defined(__clang__)
140 # define CRM_TRACE_INIT_DATA(name)
141 # else
142 # include <assert.h>
143 # define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
144 #endif
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 # define do_crm_log(level, fmt, args...) do { \
160 switch (level) { \
161 case LOG_STDOUT: \
162 printf(fmt "\n" , ##args); \
163 break; \
164 case LOG_NEVER: \
165 break; \
166 default: \
167 qb_log_from_external_source(__func__, __FILE__, fmt, \
168 (level), __LINE__, 0 , ##args); \
169 break; \
170 } \
171 } while (0)
172
173
174
175
176
177
178
179
180
181
182
183 # define do_crm_log_unlikely(level, fmt, args...) do { \
184 switch (level) { \
185 case LOG_STDOUT: case LOG_NEVER: \
186 break; \
187 default: { \
188 static struct qb_log_callsite *trace_cs = NULL; \
189 if (trace_cs == NULL) { \
190 trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, \
191 (level), __LINE__, 0); \
192 } \
193 if (crm_is_callsite_active(trace_cs, (level), 0)) { \
194 qb_log_from_external_source(__func__, __FILE__, fmt, \
195 (level), __LINE__, 0 , ##args); \
196 } \
197 } \
198 break; \
199 } \
200 } while (0)
201
202 # define CRM_LOG_ASSERT(expr) do { \
203 if (!(expr)) { \
204 static struct qb_log_callsite *core_cs = NULL; \
205 if(core_cs == NULL) { \
206 core_cs = qb_log_callsite_get(__func__, __FILE__, \
207 "log-assert", LOG_TRACE, \
208 __LINE__, 0); \
209 } \
210 crm_abort(__FILE__, __func__, __LINE__, #expr, \
211 core_cs?core_cs->targets:FALSE, TRUE); \
212 } \
213 } while(0)
214
215
216
217
218 # define CRM_CHECK(expr, failure_action) do { \
219 if (!(expr)) { \
220 static struct qb_log_callsite *core_cs = NULL; \
221 if (core_cs == NULL) { \
222 core_cs = qb_log_callsite_get(__func__, __FILE__, \
223 "check-assert", \
224 LOG_TRACE, __LINE__, 0); \
225 } \
226 crm_abort(__FILE__, __func__, __LINE__, #expr, \
227 (core_cs? core_cs->targets: FALSE), TRUE); \
228 failure_action; \
229 } \
230 } while(0)
231
232
233
234
235
236
237
238
239
240
241
242 # define do_crm_log_xml(level, text, xml) do { \
243 switch (level) { \
244 case LOG_STDOUT: case LOG_NEVER: \
245 break; \
246 default: { \
247 static struct qb_log_callsite *xml_cs = NULL; \
248 if (xml_cs == NULL) { \
249 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
250 "xml-blob", (level), __LINE__, 0); \
251 } \
252 if (crm_is_callsite_active(xml_cs, (level), 0)) { \
253 log_data_element((level), __FILE__, __func__, \
254 __LINE__, text, xml, 1, xml_log_option_formatted); \
255 } \
256 } \
257 break; \
258 } \
259 } while(0)
260
261
262
263
264
265
266
267
268
269
270
271
272
273 # define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
274 switch (level) { \
275 case LOG_STDOUT: \
276 printf(fmt "\n" , ##args); \
277 break; \
278 case LOG_NEVER: \
279 break; \
280 default: \
281 qb_log_from_external_source(function, file, fmt, (level), \
282 line, 0 , ##args); \
283 break; \
284 } \
285 } while (0)
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301 # define crm_perror(level, fmt, args...) do { \
302 switch (level) { \
303 case LOG_NEVER: \
304 break; \
305 default: { \
306 const char *err = strerror(errno); \
307 \
308 if ((level) <= (int) crm_log_level) { \
309 fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, errno);\
310 } \
311 do_crm_log((level), fmt ": %s (%d)" , ##args, err, errno); \
312 } \
313 break; \
314 } \
315 } while (0)
316
317
318
319
320
321
322
323
324
325
326
327
328 # define crm_log_tag(level, tag, fmt, args...) do { \
329 switch (level) { \
330 case LOG_STDOUT: case LOG_NEVER: \
331 break; \
332 default: { \
333 static struct qb_log_callsite *trace_tag_cs = NULL; \
334 int converted_tag = g_quark_try_string(tag); \
335 if (trace_tag_cs == NULL) { \
336 trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, \
337 fmt, (level), __LINE__, converted_tag); \
338 } \
339 if (crm_is_callsite_active(trace_tag_cs, (level), \
340 converted_tag)) { \
341 qb_log_from_external_source(__func__, __FILE__, fmt, \
342 (level), __LINE__, converted_tag , ##args); \
343 } \
344 } \
345 } \
346 } while (0)
347
348 # define crm_emerg(fmt, args...) qb_log(LOG_EMERG, fmt , ##args)
349 # define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
350 # define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
351 # define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
352 # define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
353 # define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
354
355 # define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
356 # define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
357
358 # define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
359 # define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
360 # define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
361 # define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
362 # define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
363 # define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
364 # define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
365
366 # define crm_log_xml_explicit(xml, text) do { \
367 static struct qb_log_callsite *digest_cs = NULL; \
368 digest_cs = qb_log_callsite_get( \
369 __func__, __FILE__, text, LOG_TRACE, __LINE__, \
370 crm_trace_nonlog); \
371 if (digest_cs && digest_cs->targets) { \
372 do_crm_log_xml(LOG_TRACE, text, xml); \
373 } \
374 } while(0)
375
376 # define crm_str(x) (const char*)(x?x:"<null>")
377
378 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
379 #include <crm/common/logging_compat.h>
380 #endif
381
382 #ifdef __cplusplus
383 }
384 #endif
385
386 #endif