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