10#ifndef PCMK__CRM_COMMON_LOGGING__H
11# define PCMK__CRM_COMMON_LOGGING__H
16# include <libxml/tree.h>
37# define LOG_TRACE (LOG_DEBUG+1)
42# define LOG_STDOUT 254
53# define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
62crm_extended_logging(
int t,
int e)
102 gboolean to_stderr,
int argc,
char **argv, gboolean quiet);
105void crm_log_output_fn(
const char *file,
const char *function,
int line,
int level,
106 const char *prefix,
const char *output);
109#define crm_log_output(level, prefix, output) \
110 crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)
130#if defined(__clang__)
131# define CRM_TRACE_INIT_DATA(name)
134# define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
150pcmk__clip_log_level(
int level)
155 if (level >= UINT8_MAX) {
172# define do_crm_log(level, fmt, args...) do { \
173 uint8_t _level = pcmk__clip_log_level(level); \
177 printf(fmt "\n" , ##args); \
182 qb_log_from_external_source(__func__, __FILE__, fmt, \
183 _level, __LINE__, 0 , ##args); \
197# define do_crm_log_unlikely(level, fmt, args...) do { \
198 uint8_t _level = pcmk__clip_log_level(level); \
201 case LOG_STDOUT: case LOG_NEVER: \
204 static struct qb_log_callsite *trace_cs = NULL; \
205 if (trace_cs == NULL) { \
206 trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, \
207 _level, __LINE__, 0); \
209 if (crm_is_callsite_active(trace_cs, _level, 0)) { \
210 qb_log_from_external_source(__func__, __FILE__, fmt, \
211 _level, __LINE__, 0 , \
219# define CRM_LOG_ASSERT(expr) do { \
221 static struct qb_log_callsite *core_cs = NULL; \
222 if(core_cs == NULL) { \
223 core_cs = qb_log_callsite_get(__func__, __FILE__, \
224 "log-assert", LOG_TRACE, \
227 crm_abort(__FILE__, __func__, __LINE__, #expr, \
228 core_cs?core_cs->targets:FALSE, TRUE); \
235# define CRM_CHECK(expr, failure_action) do { \
237 static struct qb_log_callsite *core_cs = NULL; \
238 if (core_cs == NULL) { \
239 core_cs = qb_log_callsite_get(__func__, __FILE__, \
241 LOG_TRACE, __LINE__, 0); \
243 crm_abort(__FILE__, __func__, __LINE__, #expr, \
244 (core_cs? core_cs->targets: FALSE), TRUE); \
258# define do_crm_log_xml(level, text, xml) do { \
259 uint8_t _level = pcmk__clip_log_level(level); \
260 static struct qb_log_callsite *xml_cs = NULL; \
267 if (xml_cs == NULL) { \
268 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
269 "xml-blob", _level, \
272 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
273 pcmk_log_xml_impl(_level, text, xml); \
289# define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
290 uint8_t _level = pcmk__clip_log_level(level); \
294 printf(fmt "\n" , ##args); \
299 qb_log_from_external_source(function, file, fmt, _level, \
319# define crm_perror(level, fmt, args...) do { \
320 uint8_t _level = pcmk__clip_log_level(level); \
326 const char *err = strerror(errno); \
327 if (_level <= crm_log_level) { \
328 fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, \
334 do_crm_log((level), fmt ": %s (%d)" , ##args, err, errno); \
350# define crm_log_tag(level, tag, fmt, args...) do { \
351 uint8_t _level = pcmk__clip_log_level(level); \
354 case LOG_STDOUT: case LOG_NEVER: \
357 static struct qb_log_callsite *trace_tag_cs = NULL; \
358 int converted_tag = g_quark_try_string(tag); \
359 if (trace_tag_cs == NULL) { \
360 trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, \
365 if (crm_is_callsite_active(trace_tag_cs, _level, \
367 qb_log_from_external_source(__func__, __FILE__, fmt, \
369 converted_tag , ##args); \
375# define crm_emerg(fmt, args...) qb_log(LOG_EMERG, fmt , ##args)
376# define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
377# define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
378# define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
379# define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
380# define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
382# define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
383# define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
385# define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
386# define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
387# define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
388# define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
389# define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
390# define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
391# define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
393# define crm_log_xml_explicit(xml, text) do { \
394 static struct qb_log_callsite *digest_cs = NULL; \
395 digest_cs = qb_log_callsite_get( \
396 __func__, __FILE__, text, LOG_TRACE, __LINE__, \
398 if (digest_cs && digest_cs->targets) { \
399 do_crm_log_xml(LOG_TRACE, text, xml); \
403#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 pcmk_log_xml_impl(uint8_t level, const char *text, const xmlNode *xml)
Log XML line-by-line in a formatted fashion.
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)
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.
int daemon(int nochdir, int noclose)