pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
Macros | Functions | Variables
logging.h File Reference

Wrappers for and extensions to libqb logging. More...

#include <stdio.h>
#include <stdint.h>
#include <glib.h>
#include <qb/qblog.h>
#include <libxml/tree.h>
#include <assert.h>
#include <crm/common/logging_compat.h>
Include dependency graph for logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOG_TRACE   (LOG_DEBUG+1)
 
#define LOG_STDOUT   254
 
#define LOG_NEVER   255
 
#define CRM_XS   "|"
 
#define crm_log_output(level, prefix, output)   crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)
 
#define CRM_TRACE_INIT_DATA(name)   QB_LOG_INIT_DATA(name)
 
#define do_crm_log(level, fmt, args...)
 Log a message. More...
 
#define do_crm_log_unlikely(level, fmt, args...)
 Log a message that is likely to be filtered out. More...
 
#define CRM_LOG_ASSERT(expr)
 
#define CRM_CHECK(expr, failure_action)
 
#define do_crm_log_xml(level, text, xml)
 Log XML line-by-line in a formatted fashion. More...
 
#define do_crm_log_alias(level, file, function, line, fmt, args...)
 Log a message as if it came from a different code location. More...
 
#define crm_perror(level, fmt, args...)
 Send a system error message to both the log and stderr. More...
 
#define crm_log_tag(level, tag, fmt, args...)
 Log a message with a tag (for use with PCMK_trace_tags) More...
 
#define crm_emerg(fmt, args...)   qb_log(LOG_EMERG, fmt , ##args)
 
#define crm_crit(fmt, args...)   qb_logt(LOG_CRIT, 0, fmt , ##args)
 
#define crm_err(fmt, args...)   qb_logt(LOG_ERR, 0, fmt , ##args)
 
#define crm_warn(fmt, args...)   qb_logt(LOG_WARNING, 0, fmt , ##args)
 
#define crm_notice(fmt, args...)   qb_logt(LOG_NOTICE, 0, fmt , ##args)
 
#define crm_info(fmt, args...)   qb_logt(LOG_INFO, 0, fmt , ##args)
 
#define crm_debug(fmt, args...)   do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
 
#define crm_trace(fmt, args...)   do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
 
#define crm_log_xml_crit(xml, text)   do_crm_log_xml(LOG_CRIT, text, xml)
 
#define crm_log_xml_err(xml, text)   do_crm_log_xml(LOG_ERR, text, xml)
 
#define crm_log_xml_warn(xml, text)   do_crm_log_xml(LOG_WARNING, text, xml)
 
#define crm_log_xml_notice(xml, text)   do_crm_log_xml(LOG_NOTICE, text, xml)
 
#define crm_log_xml_info(xml, text)   do_crm_log_xml(LOG_INFO, text, xml)
 
#define crm_log_xml_debug(xml, text)   do_crm_log_xml(LOG_DEBUG, text, xml)
 
#define crm_log_xml_trace(xml, text)   do_crm_log_xml(LOG_TRACE, text, xml)
 
#define crm_log_xml_explicit(xml, text)
 

Functions

void crm_enable_blackbox (int nsig)
 
void crm_disable_blackbox (int nsig)
 
void crm_write_blackbox (int nsig, const struct qb_log_callsite *callsite)
 
void crm_update_callsites (void)
 
void crm_log_deinit (void)
 
void crm_log_preinit (const char *entity, int argc, char *const *argv)
 Initializes the logging system and defaults to the least verbose output level. More...
 
gboolean crm_log_init (const char *entity, uint8_t level, gboolean daemon, gboolean to_stderr, int argc, char **argv, gboolean quiet)
 
void crm_log_args (int argc, char **argv)
 Log the command line (once) More...
 
void crm_log_output_fn (const char *file, const char *function, int line, int level, const char *prefix, const char *output)
 
void crm_bump_log_level (int argc, char **argv)
 Make logging more verbose. More...
 
void crm_enable_stderr (int enable)
 
gboolean crm_is_callsite_active (struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
 
unsigned int set_crm_log_level (unsigned int level)
 
unsigned int get_crm_log_level (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. More...
 

Variables

unsigned int crm_log_level
 
unsigned int crm_trace_nonlog
 
gboolean crm_config_error
 
gboolean crm_config_warning
 

Detailed Description

Wrappers for and extensions to libqb logging.

Definition in file logging.h.

Macro Definition Documentation

◆ CRM_CHECK

#define CRM_CHECK (   expr,
  failure_action 
)
Value:
do { \
if (!(expr)) { \
static struct qb_log_callsite *core_cs = NULL; \
if (core_cs == NULL) { \
core_cs = qb_log_callsite_get(__func__, __FILE__, \
"check-assert", \
LOG_TRACE, __LINE__, 0); \
} \
crm_abort(__FILE__, __func__, __LINE__, #expr, \
(core_cs? core_cs->targets: FALSE), TRUE); \
failure_action; \
} \
} while(0)
#define LOG_TRACE
Definition: logging.h:38

Definition at line 238 of file logging.h.

◆ crm_crit

#define crm_crit (   fmt,
  args... 
)    qb_logt(LOG_CRIT, 0, fmt , ##args)

Definition at line 380 of file logging.h.

◆ crm_debug

#define crm_debug (   fmt,
  args... 
)    do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)

Definition at line 386 of file logging.h.

◆ crm_emerg

#define crm_emerg (   fmt,
  args... 
)    qb_log(LOG_EMERG, fmt , ##args)

Definition at line 379 of file logging.h.

◆ crm_err

#define crm_err (   fmt,
  args... 
)    qb_logt(LOG_ERR, 0, fmt , ##args)

Definition at line 381 of file logging.h.

◆ crm_info

#define crm_info (   fmt,
  args... 
)    qb_logt(LOG_INFO, 0, fmt , ##args)

Definition at line 384 of file logging.h.

◆ CRM_LOG_ASSERT

#define CRM_LOG_ASSERT (   expr)
Value:
do { \
if (!(expr)) { \
static struct qb_log_callsite *core_cs = NULL; \
if(core_cs == NULL) { \
core_cs = qb_log_callsite_get(__func__, __FILE__, \
"log-assert", LOG_TRACE, \
__LINE__, 0); \
} \
crm_abort(__FILE__, __func__, __LINE__, #expr, \
core_cs?core_cs->targets:FALSE, TRUE); \
} \
} while(0)
#define LOG_TRACE
Definition: logging.h:38

Definition at line 222 of file logging.h.

◆ crm_log_output

#define crm_log_output (   level,
  prefix,
  output 
)    crm_log_output_fn(__FILE__, __func__, __LINE__, level, prefix, output)

Definition at line 110 of file logging.h.

◆ crm_log_tag

#define crm_log_tag (   level,
  tag,
  fmt,
  args... 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
\
switch (_level) { \
case LOG_STDOUT: case LOG_NEVER: \
break; \
default: { \
static struct qb_log_callsite *trace_tag_cs = NULL; \
int converted_tag = g_quark_try_string(tag); \
if (trace_tag_cs == NULL) { \
trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, \
fmt, _level, \
__LINE__, \
converted_tag); \
} \
if (crm_is_callsite_active(trace_tag_cs, _level, \
converted_tag)) { \
qb_log_from_external_source(__func__, __FILE__, fmt, \
_level, __LINE__, \
converted_tag , ##args); \
} \
} \
} \
} while (0)
#define LOG_NEVER
Definition: logging.h:48
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:680
#define LOG_STDOUT
Definition: logging.h:43

Log a message with a tag (for use with PCMK_trace_tags)

Parameters
[in]levelPriority at which to log the message
[in]tagString to tag message with
[in]fmtprintf-style format string for message
[in]argsAny arguments needed by format string
Note
This does nothing when level is LOG_STDOUT.

Definition at line 354 of file logging.h.

◆ crm_log_xml_crit

#define crm_log_xml_crit (   xml,
  text 
)    do_crm_log_xml(LOG_CRIT, text, xml)

Definition at line 389 of file logging.h.

◆ crm_log_xml_debug

#define crm_log_xml_debug (   xml,
  text 
)    do_crm_log_xml(LOG_DEBUG, text, xml)

Definition at line 394 of file logging.h.

◆ crm_log_xml_err

#define crm_log_xml_err (   xml,
  text 
)    do_crm_log_xml(LOG_ERR, text, xml)

Definition at line 390 of file logging.h.

◆ crm_log_xml_explicit

#define crm_log_xml_explicit (   xml,
  text 
)
Value:
do { \
static struct qb_log_callsite *digest_cs = NULL; \
digest_cs = qb_log_callsite_get( \
__func__, __FILE__, text, LOG_TRACE, __LINE__, \
if (digest_cs && digest_cs->targets) { \
do_crm_log_xml(LOG_TRACE, text, xml); \
} \
} while(0)
#define LOG_TRACE
Definition: logging.h:38
unsigned int crm_trace_nonlog
Definition: logging.c:46

Definition at line 397 of file logging.h.

◆ crm_log_xml_info

#define crm_log_xml_info (   xml,
  text 
)    do_crm_log_xml(LOG_INFO, text, xml)

Definition at line 393 of file logging.h.

◆ crm_log_xml_notice

#define crm_log_xml_notice (   xml,
  text 
)    do_crm_log_xml(LOG_NOTICE, text, xml)

Definition at line 392 of file logging.h.

◆ crm_log_xml_trace

#define crm_log_xml_trace (   xml,
  text 
)    do_crm_log_xml(LOG_TRACE, text, xml)

Definition at line 395 of file logging.h.

◆ crm_log_xml_warn

#define crm_log_xml_warn (   xml,
  text 
)    do_crm_log_xml(LOG_WARNING, text, xml)

Definition at line 391 of file logging.h.

◆ crm_notice

#define crm_notice (   fmt,
  args... 
)    qb_logt(LOG_NOTICE, 0, fmt , ##args)

Definition at line 383 of file logging.h.

◆ crm_perror

#define crm_perror (   level,
  fmt,
  args... 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
\
switch (_level) { \
case LOG_NEVER: \
break; \
default: { \
const char *err = strerror(errno); \
if (_level <= crm_log_level) { \
fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, \
errno); \
} \
/* Pass original level arg since do_crm_log() also declares \
* _level \
*/ \
do_crm_log((level), fmt ": %s (%d)" , ##args, err, errno); \
} \
break; \
} \
} while (0)
#define LOG_NEVER
Definition: logging.h:48
unsigned int crm_log_level
Definition: logging.c:45

Send a system error message to both the log and stderr.

Parameters
[in]levelPriority at which to log the message
[in]fmtprintf-style format string for message
[in]argsAny arguments needed by format string
Deprecated:
One of the other logging functions should be used with pcmk_strerror() instead.
Note
This is a macro, and level may be evaluated more than once.
Because crm_perror() adds the system error message and error number onto the end of fmt, that information will become extended information if CRM_XS is used inside fmt and will not show up in syslog.

Definition at line 323 of file logging.h.

◆ crm_trace

#define crm_trace (   fmt,
  args... 
)    do_crm_log_unlikely(LOG_TRACE, fmt , ##args)

Definition at line 387 of file logging.h.

◆ CRM_TRACE_INIT_DATA

#define CRM_TRACE_INIT_DATA (   name)    QB_LOG_INIT_DATA(name)

Definition at line 137 of file logging.h.

◆ crm_warn

#define crm_warn (   fmt,
  args... 
)    qb_logt(LOG_WARNING, 0, fmt , ##args)

Definition at line 382 of file logging.h.

◆ CRM_XS

#define CRM_XS   "|"

Definition at line 56 of file logging.h.

◆ do_crm_log

#define do_crm_log (   level,
  fmt,
  args... 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
\
switch (_level) { \
case LOG_STDOUT: \
printf(fmt "\n" , ##args); \
break; \
case LOG_NEVER: \
break; \
default: \
qb_log_from_external_source(__func__, __FILE__, fmt, \
_level, __LINE__, 0 , ##args); \
break; \
} \
} while (0)
#define LOG_NEVER
Definition: logging.h:48
#define LOG_STDOUT
Definition: logging.h:43

Log a message.

Parameters
[in]levelPriority at which to log the message
[in]fmtprintf-style format string literal for message
[in]argsAny arguments needed by format string

Definition at line 175 of file logging.h.

◆ do_crm_log_alias

#define do_crm_log_alias (   level,
  file,
  function,
  line,
  fmt,
  args... 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
\
switch (_level) { \
case LOG_STDOUT: \
printf(fmt "\n" , ##args); \
break; \
case LOG_NEVER: \
break; \
default: \
qb_log_from_external_source(function, file, fmt, _level, \
line, 0 , ##args); \
break; \
} \
} while (0)
#define LOG_NEVER
Definition: logging.h:48
#define LOG_STDOUT
Definition: logging.h:43

Log a message as if it came from a different code location.

Parameters
[in]levelPriority at which to log the message
[in]fileSource file name to use instead of FILE
[in]functionSource function name to use instead of func
[in]lineSource line number to use instead of line
[in]fmtprintf-style format string literal for message
[in]argsAny arguments needed by format string

Definition at line 293 of file logging.h.

◆ do_crm_log_unlikely

#define do_crm_log_unlikely (   level,
  fmt,
  args... 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
\
switch (_level) { \
case LOG_STDOUT: case LOG_NEVER: \
break; \
default: { \
static struct qb_log_callsite *trace_cs = NULL; \
if (trace_cs == NULL) { \
trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, \
_level, __LINE__, 0); \
} \
if (crm_is_callsite_active(trace_cs, _level, 0)) { \
qb_log_from_external_source(__func__, __FILE__, fmt, \
_level, __LINE__, 0 , \
##args); \
} \
} \
break; \
} \
} while (0)
#define LOG_NEVER
Definition: logging.h:48
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:680
#define LOG_STDOUT
Definition: logging.h:43

Log a message that is likely to be filtered out.

Parameters
[in]levelPriority at which to log the message
[in]fmtprintf-style format string for message
[in]argsAny arguments needed by format string
Note
This does nothing when level is LOG_STDOUT.

Definition at line 200 of file logging.h.

◆ do_crm_log_xml

#define do_crm_log_xml (   level,
  text,
  xml 
)
Value:
do { \
uint8_t _level = pcmk__clip_log_level(level); \
static struct qb_log_callsite *xml_cs = NULL; \
\
switch (_level) { \
case LOG_STDOUT: \
case LOG_NEVER: \
break; \
default: \
if (xml_cs == NULL) { \
xml_cs = qb_log_callsite_get(__func__, __FILE__, \
"xml-blob", _level, \
__LINE__, 0); \
} \
if (crm_is_callsite_active(xml_cs, _level, 0)) { \
pcmk_log_xml_as(__FILE__, __func__, __LINE__, 0, \
_level, text, (xml)); \
} \
break; \
} \
} while(0)
#define LOG_NEVER
Definition: logging.h:48
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:680
#define LOG_STDOUT
Definition: logging.h:43

Log XML line-by-line in a formatted fashion.

Parameters
[in]levelPriority at which to log the messages
[in]textPrefix for each line
[in]xmlXML to log
Note
This does nothing when level is LOG_STDOUT.

Definition at line 261 of file logging.h.

◆ LOG_NEVER

#define LOG_NEVER   255

Definition at line 48 of file logging.h.

◆ LOG_STDOUT

#define LOG_STDOUT   254

Definition at line 43 of file logging.h.

◆ LOG_TRACE

#define LOG_TRACE   (LOG_DEBUG+1)

Definition at line 38 of file logging.h.

Function Documentation

◆ crm_bump_log_level()

void crm_bump_log_level ( int  argc,
char **  argv 
)

Make logging more verbose.

If logging to stderr is not already enabled when this function is called, enable it. Otherwise, increase the log level by 1.

Parameters
[in]argcIgnored
[in]argvIgnored

Definition at line 1065 of file logging.c.

◆ crm_disable_blackbox()

void crm_disable_blackbox ( int  nsig)

Definition at line 489 of file logging.c.

◆ crm_enable_blackbox()

void crm_enable_blackbox ( int  nsig)

Definition at line 483 of file logging.c.

◆ crm_enable_stderr()

void crm_enable_stderr ( int  enable)

Definition at line 1044 of file logging.c.

◆ crm_is_callsite_active()

gboolean crm_is_callsite_active ( struct qb_log_callsite *  cs,
uint8_t  level,
uint32_t  tags 
)

Definition at line 680 of file logging.c.

◆ crm_log_args()

void crm_log_args ( int  argc,
char **  argv 
)

Log the command line (once)

Parameters
[in]Numberof values in argv
[in]Command-linearguments (including command name)
Note
This function will only log once, even if called with different arguments.

Definition at line 1091 of file logging.c.

◆ crm_log_deinit()

void crm_log_deinit ( void  )

Definition at line 131 of file logging.c.

◆ crm_log_init()

gboolean crm_log_init ( const char *  entity,
uint8_t  level,
gboolean  daemon,
gboolean  to_stderr,
int  argc,
char **  argv,
gboolean  quiet 
)

Definition at line 896 of file logging.c.

◆ crm_log_output_fn()

void crm_log_output_fn ( const char *  file,
const char *  function,
int  line,
int  level,
const char *  prefix,
const char *  output 
)

Definition at line 1106 of file logging.c.

◆ crm_log_preinit()

void crm_log_preinit ( const char *  entity,
int  argc,
char *const *  argv 
)

Initializes the logging system and defaults to the least verbose output level.

Parameters
[in]entityIf not NULL, will be used as the identity for logging purposes
[in]argcThe number of command line parameters
[in]argvThe command line parameter values

Definition at line 811 of file logging.c.

◆ crm_update_callsites()

void crm_update_callsites ( void  )

Definition at line 709 of file logging.c.

◆ crm_write_blackbox()

void crm_write_blackbox ( int  nsig,
const struct qb_log_callsite *  callsite 
)

Definition at line 505 of file logging.c.

◆ get_crm_log_level()

unsigned int get_crm_log_level ( void  )

Definition at line 1076 of file logging.c.

◆ pcmk_log_xml_as()

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.

Parameters
[in]fileFile name to use for log filtering
[in]functionFunction name to use for log filtering
[in]lineLine number to use for log filtering
[in]tagsLogging tags to use for log filtering
[in]levelPriority at which to log the messages
[in]textPrefix for each line
[in]xmlXML to log
Note
This does nothing when level is LOG_STDOUT.
Do not call this function directly. It should be called only from the do_crm_log_xml() macro.

Definition at line 1163 of file logging.c.

◆ set_crm_log_level()

unsigned int set_crm_log_level ( unsigned int  level)

Definition at line 1030 of file logging.c.

Variable Documentation

◆ crm_config_error

gboolean crm_config_error
Deprecated:
Pacemaker library functions set this when a configuration error is found, which turns on extra messages at the end of processing. It should not be used directly and will be removed from the public C API in a future release.

Definition at line 49 of file utils.c.

◆ crm_config_warning

gboolean crm_config_warning
Deprecated:
Pacemaker library functions set this when a configuration warning is found, which turns on extra messages at the end of processing. It should not be used directly and will be removed from the public C API in a future release.

Definition at line 50 of file utils.c.

◆ crm_log_level

unsigned int crm_log_level

Definition at line 45 of file logging.c.

◆ crm_trace_nonlog

unsigned int crm_trace_nonlog

Definition at line 46 of file logging.c.