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)
43# define LOG_STDOUT 254
54# define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
63crm_extended_logging(
int t,
int e)
102gboolean
crm_log_init(
const char *entity, uint8_t level, gboolean daemon,
103 gboolean to_stderr,
int argc,
char **argv, gboolean quiet);
106void crm_log_output_fn(
const char *file,
const char *function,
int line,
int level,
107 const char *prefix,
const char *output);
110#define crm_log_output(level, prefix, output) \
111 crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)
124void pcmk_log_xml_as(
const char *file,
const char *function, uint32_t line,
125 uint32_t tags, uint8_t level,
const char *text,
133#if defined(__clang__)
134# define CRM_TRACE_INIT_DATA(name)
137# define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
153pcmk__clip_log_level(
int level)
158 if (level >= UINT8_MAX) {
175# define do_crm_log(level, fmt, args...) do { \
176 uint8_t _level = pcmk__clip_log_level(level); \
180 printf(fmt "\n" , ##args); \
185 qb_log_from_external_source(__func__, __FILE__, fmt, \
186 _level, __LINE__, 0 , ##args); \
200# define do_crm_log_unlikely(level, fmt, args...) do { \
201 uint8_t _level = pcmk__clip_log_level(level); \
204 case LOG_STDOUT: case LOG_NEVER: \
207 static struct qb_log_callsite *trace_cs = NULL; \
208 if (trace_cs == NULL) { \
209 trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, \
210 _level, __LINE__, 0); \
212 if (crm_is_callsite_active(trace_cs, _level, 0)) { \
213 qb_log_from_external_source(__func__, __FILE__, fmt, \
214 _level, __LINE__, 0 , \
222# define CRM_LOG_ASSERT(expr) do { \
224 static struct qb_log_callsite *core_cs = NULL; \
225 if(core_cs == NULL) { \
226 core_cs = qb_log_callsite_get(__func__, __FILE__, \
227 "log-assert", LOG_TRACE, \
230 crm_abort(__FILE__, __func__, __LINE__, #expr, \
231 core_cs?core_cs->targets:FALSE, TRUE); \
238# define CRM_CHECK(expr, failure_action) do { \
240 static struct qb_log_callsite *core_cs = NULL; \
241 if (core_cs == NULL) { \
242 core_cs = qb_log_callsite_get(__func__, __FILE__, \
244 LOG_TRACE, __LINE__, 0); \
246 crm_abort(__FILE__, __func__, __LINE__, #expr, \
247 (core_cs? core_cs->targets: FALSE), TRUE); \
261# define do_crm_log_xml(level, text, xml) do { \
262 uint8_t _level = pcmk__clip_log_level(level); \
263 static struct qb_log_callsite *xml_cs = NULL; \
270 if (xml_cs == NULL) { \
271 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
272 "xml-blob", _level, \
275 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
276 pcmk_log_xml_as(__FILE__, __func__, __LINE__, 0, \
277 _level, text, (xml)); \
293# define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
294 uint8_t _level = pcmk__clip_log_level(level); \
298 printf(fmt "\n" , ##args); \
303 qb_log_from_external_source(function, file, fmt, _level, \
323# define crm_perror(level, fmt, args...) do { \
324 uint8_t _level = pcmk__clip_log_level(level); \
330 const char *err = strerror(errno); \
331 if (_level <= crm_log_level) { \
332 fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, \
338 do_crm_log((level), fmt ": %s (%d)" , ##args, err, errno); \
354# define crm_log_tag(level, tag, fmt, args...) do { \
355 uint8_t _level = pcmk__clip_log_level(level); \
358 case LOG_STDOUT: case LOG_NEVER: \
361 static struct qb_log_callsite *trace_tag_cs = NULL; \
362 int converted_tag = g_quark_try_string(tag); \
363 if (trace_tag_cs == NULL) { \
364 trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, \
369 if (crm_is_callsite_active(trace_tag_cs, _level, \
371 qb_log_from_external_source(__func__, __FILE__, fmt, \
373 converted_tag , ##args); \
379# define crm_emerg(fmt, args...) qb_log(LOG_EMERG, fmt , ##args)
380# define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
381# define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
382# define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
383# define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
384# define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
386# define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
387# define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
389# define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
390# define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
391# define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
392# define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
393# define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
394# define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
395# define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
397# define crm_log_xml_explicit(xml, text) do { \
398 static struct qb_log_callsite *digest_cs = NULL; \
399 digest_cs = qb_log_callsite_get( \
400 __func__, __FILE__, text, LOG_TRACE, __LINE__, \
402 if (digest_cs && digest_cs->targets) { \
403 do_crm_log_xml(LOG_TRACE, text, xml); \
407#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.