pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
logging_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2015-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#ifndef PCMK__LOGGING_INTERNAL_H
15#define PCMK__LOGGING_INTERNAL_H
16
17#include <glib.h>
18
19#include <crm/common/logging.h>
21
22/* Some warnings are too noisy when logged every time a given function is called
23 * (for example, using a deprecated feature). As an alternative, we allow
24 * warnings to be logged once per invocation of the calling program. Each of
25 * those warnings needs a flag defined here.
26 */
57
65#define pcmk__warn_once(wo_flag, fmt...) do { \
66 if (!pcmk_is_set(pcmk__warnings, wo_flag)) { \
67 if (wo_flag == pcmk__wo_blind) { \
68 crm_warn(fmt); \
69 } else { \
70 pcmk__config_warn(fmt); \
71 } \
72 pcmk__warnings = pcmk__set_flags_as(__func__, __LINE__, \
73 LOG_TRACE, \
74 "Warn-once", "logging", \
75 pcmk__warnings, \
76 (wo_flag), #wo_flag); \
77 } \
78 } while (0)
79
80typedef void (*pcmk__config_error_func) (void *ctx, const char *msg, ...)
81 G_GNUC_PRINTF(2, 3);
82typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...)
83 G_GNUC_PRINTF(2, 3);
84
87
90
91void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context);
92void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context);
93
100#define pcmk__config_err(fmt...) do { \
101 crm_config_error = TRUE; \
102 if (pcmk__config_error_handler == NULL) { \
103 crm_err(fmt); \
104 } else { \
105 pcmk__config_error_handler(pcmk__config_error_context, fmt); \
106 } \
107 } while (0)
108
115#define pcmk__config_warn(fmt...) do { \
116 crm_config_warning = TRUE; \
117 if (pcmk__config_warning_handler == NULL) { \
118 crm_warn(fmt); \
119 } else { \
120 pcmk__config_warning_handler(pcmk__config_warning_context, fmt);\
121 } \
122 } while (0)
123
137#define pcmk__if_tracing(if_action, else_action) do { \
138 static struct qb_log_callsite *trace_cs = NULL; \
139 \
140 if (trace_cs == NULL) { \
141 trace_cs = qb_log_callsite_get(__func__, __FILE__, \
142 "if_tracing", LOG_TRACE, \
143 __LINE__, crm_trace_nonlog); \
144 } \
145 if (crm_is_callsite_active(trace_cs, LOG_TRACE, \
146 crm_trace_nonlog)) { \
147 if_action; \
148 } else { \
149 else_action; \
150 } \
151 } while (0)
152
162#define pcmk__log_xml_changes(level, xml) do { \
163 uint8_t _level = pcmk__clip_log_level(level); \
164 static struct qb_log_callsite *xml_cs = NULL; \
165 \
166 switch (_level) { \
167 case LOG_STDOUT: \
168 case LOG_NEVER: \
169 break; \
170 default: \
171 if (xml_cs == NULL) { \
172 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
173 "xml-changes", _level, \
174 __LINE__, 0); \
175 } \
176 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
177 pcmk__log_xml_changes_as(__FILE__, __func__, __LINE__, \
178 0, _level, xml); \
179 } \
180 break; \
181 } \
182 } while(0)
183
193#define pcmk__log_xml_patchset(level, patchset) do { \
194 uint8_t _level = pcmk__clip_log_level(level); \
195 static struct qb_log_callsite *xml_cs = NULL; \
196 \
197 switch (_level) { \
198 case LOG_STDOUT: \
199 case LOG_NEVER: \
200 break; \
201 default: \
202 if (xml_cs == NULL) { \
203 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
204 "xml-patchset", _level, \
205 __LINE__, 0); \
206 } \
207 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
208 pcmk__log_xml_patchset_as(__FILE__, __func__, __LINE__, \
209 0, _level, patchset); \
210 } \
211 break; \
212 } \
213 } while(0)
214
215void pcmk__log_xml_changes_as(const char *file, const char *function,
216 uint32_t line, uint32_t tags, uint8_t level,
217 const xmlNode *xml);
218
219void pcmk__log_xml_patchset_as(const char *file, const char *function,
220 uint32_t line, uint32_t tags, uint8_t level,
221 const xmlNode *patchset);
222
232void pcmk__cli_init_logging(const char *name, unsigned int verbosity);
233
234int pcmk__add_logfile(const char *filename);
235void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out);
236
237void pcmk__free_common_logger(void);
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif
const char * name
Definition cib.c:26
Wrappers for and extensions to libqb logging.
void(* pcmk__config_error_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
int pcmk__add_logfile(const char *filename)
Add a file to be used as a Pacemaker detail log.
Definition logging.c:317
void pcmk__free_common_logger(void)
Definition logging.c:1251
pcmk__config_warning_func pcmk__config_warning_handler
Definition logging.c:55
void(*) typedef void(* pcmk__config_warning_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
void pcmk__log_xml_patchset_as(const char *file, const char *function, uint32_t line, uint32_t tags, uint8_t level, const xmlNode *patchset)
Definition logging.c:1229
void * pcmk__config_warning_context
Definition logging.c:57
void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out)
Add multiple additional log files.
Definition logging.c:401
void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context)
Definition logging.c:1287
void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context)
Definition logging.c:1293
void * pcmk__config_error_context
Definition logging.c:56
void pcmk__log_xml_changes_as(const char *file, const char *function, uint32_t line, uint32_t tags, uint8_t level, const xmlNode *xml)
Definition logging.c:1198
void pcmk__cli_init_logging(const char *name, unsigned int verbosity)
Definition logging.c:1135
pcmk__warnings
@ pcmk__wo_order_inst
@ pcmk__wo_require_all
@ pcmk__wo_group_coloc
@ pcmk__wo_op_attr_expr
@ pcmk__wo_instance_defaults
@ pcmk__wo_nagios
@ pcmk__wo_ping_node
@ pcmk__wo_restart_type
@ pcmk__wo_group_order
@ pcmk__wo_poweroff
@ pcmk__wo_blind
@ pcmk__wo_coloc_inst
@ pcmk__wo_neg_threshold
@ pcmk__wo_master_element
@ pcmk__wo_rdisc_enabled
@ pcmk__wo_location_rules
@ pcmk__wo_rkt
@ pcmk__wo_upstart
@ pcmk__wo_multiple_rules
@ pcmk__wo_order_score
@ pcmk__wo_bundle_master
@ pcmk__wo_clone_master_max
@ pcmk__wo_set_ordering
@ pcmk__wo_master_role
@ pcmk__wo_clone_master_node_max
@ pcmk__wo_remove_after
@ pcmk__wo_slave_role
@ pcmk__wo_role_after
void(*) typedef void(*) pcmk__config_error_fun pcmk__config_error_handler)
Formatted output for pacemaker tools.
This structure contains everything that makes up a single output formatter.