10#ifndef PCMK__CRM_COMMON_LOGGING__H
11#define PCMK__CRM_COMMON_LOGGING__H
17#include <libxml/tree.h>
38#define LOG_TRACE (LOG_DEBUG+1)
54#define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
63crm_extended_logging(
int t,
int e)
107gboolean
crm_log_init(
const char *entity, uint8_t level, gboolean daemon,
108 gboolean to_stderr,
int argc,
char **argv, gboolean quiet);
111void crm_log_output_fn(
const char *file,
const char *function,
int line,
int level,
112 const char *prefix,
const char *output);
115#define crm_log_output(level, prefix, output) \
116 crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)
130void pcmk_log_xml_as(
const char *file,
const char *function, uint32_t line,
131 uint32_t tags, uint8_t level,
const char *text,
139#if defined(__clang__)
140#define CRM_TRACE_INIT_DATA(name)
143#define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
159pcmk__clip_log_level(
int level)
164 if (level >= UINT8_MAX) {
181#define do_crm_log(level, fmt, args...) do { \
182 uint8_t _level = pcmk__clip_log_level(level); \
186 printf(fmt "\n" , ##args); \
191 qb_log_from_external_source(__func__, __FILE__, fmt, \
192 _level, __LINE__, 0 , ##args); \
206#define do_crm_log_unlikely(level, fmt, args...) do { \
207 uint8_t _level = pcmk__clip_log_level(level); \
210 case LOG_STDOUT: case LOG_NEVER: \
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); \
218 if (crm_is_callsite_active(trace_cs, _level, 0)) { \
219 qb_log_from_external_source(__func__, __FILE__, fmt, \
220 _level, __LINE__, 0 , \
228#define CRM_LOG_ASSERT(expr) do { \
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, \
236 crm_abort(__FILE__, __func__, __LINE__, #expr, \
237 core_cs?core_cs->targets:FALSE, TRUE); \
245#define CRM_CHECK(expr, failure_action) do { \
247 static struct qb_log_callsite *core_cs = NULL; \
248 if (core_cs == NULL) { \
249 core_cs = qb_log_callsite_get(__func__, __FILE__, \
251 LOG_TRACE, __LINE__, 0); \
253 crm_abort(__FILE__, __func__, __LINE__, #expr, \
254 (core_cs? core_cs->targets: FALSE), TRUE); \
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; \
277 if (xml_cs == NULL) { \
278 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
279 "xml-blob", _level, \
282 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
283 pcmk_log_xml_as(__FILE__, __func__, __LINE__, 0, \
284 _level, text, (xml)); \
300#define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
301 uint8_t _level = pcmk__clip_log_level(level); \
305 printf(fmt "\n" , ##args); \
310 qb_log_from_external_source(function, file, fmt, _level, \
331#define crm_perror(level, fmt, args...) do { \
332 uint8_t _level = pcmk__clip_log_level(level); \
338 const char *err = strerror(errno); \
339 if (_level <= crm_log_level) { \
340 fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, \
346 do_crm_log((level), fmt ": %s (%d)" , ##args, err, errno); \
362#define crm_log_tag(level, tag, fmt, args...) do { \
363 uint8_t _level = pcmk__clip_log_level(level); \
366 case LOG_STDOUT: case LOG_NEVER: \
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__, \
377 if (crm_is_callsite_active(trace_tag_cs, _level, \
379 qb_log_from_external_source(__func__, __FILE__, fmt, \
381 converted_tag , ##args); \
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)
391#define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
394#define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
397#define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
399#define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
402#define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
404#define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
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)
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__, \
419 if (digest_cs && digest_cs->targets) { \
420 do_crm_log_xml(LOG_TRACE, text, xml); \
424#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
unsigned int get_crm_log_level(void)
void crm_log_deinit(void)
gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon, gboolean to_stderr, int argc, char **argv, gboolean quiet)
void crm_write_blackbox(int nsig, const struct qb_log_callsite *callsite)
void crm_disable_blackbox(int nsig)
void crm_update_callsites(void)
void pcmk_log_xml_as(const char *file, const char *function, uint32_t line, uint32_t tags, uint8_t level, const char *text, const xmlNode *xml)
Log XML line-by-line in a formatted fashion.
gboolean crm_config_warning
void crm_enable_stderr(int enable)
void crm_enable_blackbox(int nsig)
unsigned int crm_trace_nonlog
void crm_log_output_fn(const char *file, const char *function, int line, int level, const char *prefix, const char *output)
unsigned int set_crm_log_level(unsigned int level)
void crm_log_args(int argc, char **argv)
Log the command line (once)
gboolean crm_config_error
void crm_bump_log_level(int argc, char **argv)
Make logging more verbose.
unsigned int crm_log_level
void crm_log_preinit(const char *entity, int argc, char *const *argv)
Initializes the logging system and defaults to the least verbose output level.
Deprecated Pacemaker logging API.