diff options
Diffstat (limited to 'include/crm/common/logging_internal.h')
-rw-r--r-- | include/crm/common/logging_internal.h | 102 |
1 files changed, 96 insertions, 6 deletions
diff --git a/include/crm/common/logging_internal.h b/include/crm/common/logging_internal.h index 479dcab..981ddf3 100644 --- a/include/crm/common/logging_internal.h +++ b/include/crm/common/logging_internal.h @@ -19,6 +19,18 @@ extern "C" { # include <crm/common/logging.h> # include <crm/common/output_internal.h> +typedef void (*pcmk__config_error_func) (void *ctx, const char *msg, ...); +typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...); + +extern pcmk__config_error_func pcmk__config_error_handler; +extern pcmk__config_warning_func pcmk__config_warning_handler; + +extern void *pcmk__config_error_context; +extern void *pcmk__config_warning_context; + +void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context); +void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context); + /*! * \internal * \brief Log a configuration error @@ -26,9 +38,13 @@ extern "C" { * \param[in] fmt printf(3)-style format string * \param[in] ... Arguments for format string */ -# define pcmk__config_err(fmt...) do { \ - crm_config_error = TRUE; \ - crm_err(fmt); \ +# define pcmk__config_err(fmt...) do { \ + crm_config_error = TRUE; \ + if (pcmk__config_error_handler == NULL) { \ + crm_err(fmt); \ + } else { \ + pcmk__config_error_handler(pcmk__config_error_context, fmt); \ + } \ } while (0) /*! @@ -38,9 +54,13 @@ extern "C" { * \param[in] fmt printf(3)-style format string * \param[in] ... Arguments for format string */ -# define pcmk__config_warn(fmt...) do { \ - crm_config_warning = TRUE; \ - crm_warn(fmt); \ +# define pcmk__config_warn(fmt...) do { \ + crm_config_warning = TRUE; \ + if (pcmk__config_warning_handler == NULL) { \ + crm_warn(fmt); \ + } else { \ + pcmk__config_warning_handler(pcmk__config_warning_context, fmt); \ + } \ } while (0) /*! @@ -74,6 +94,76 @@ extern "C" { /*! * \internal + * \brief Log XML changes line-by-line in a formatted fashion + * + * \param[in] level Priority at which to log the messages + * \param[in] xml XML to log + * + * \note This does nothing when \p level is \c LOG_STDOUT. + */ +#define pcmk__log_xml_changes(level, xml) 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-changes", _level, \ + __LINE__, 0); \ + } \ + if (crm_is_callsite_active(xml_cs, _level, 0)) { \ + pcmk__log_xml_changes_as(__FILE__, __func__, __LINE__, \ + 0, _level, xml); \ + } \ + break; \ + } \ + } while(0) + +/*! + * \internal + * \brief Log an XML patchset line-by-line in a formatted fashion + * + * \param[in] level Priority at which to log the messages + * \param[in] patchset XML patchset to log + * + * \note This does nothing when \p level is \c LOG_STDOUT. + */ +#define pcmk__log_xml_patchset(level, patchset) 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-patchset", _level, \ + __LINE__, 0); \ + } \ + if (crm_is_callsite_active(xml_cs, _level, 0)) { \ + pcmk__log_xml_patchset_as(__FILE__, __func__, __LINE__, \ + 0, _level, patchset); \ + } \ + break; \ + } \ + } while(0) + +void pcmk__log_xml_changes_as(const char *file, const char *function, + uint32_t line, uint32_t tags, uint8_t level, + const xmlNode *xml); + +void pcmk__log_xml_patchset_as(const char *file, const char *function, + uint32_t line, uint32_t tags, uint8_t level, + const xmlNode *patchset); + +/*! + * \internal * \brief Initialize logging for command line tools * * \param[in] name The name of the program |