pacemaker 2.1.8-2.1.8~rc4
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, ...);
81typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...);
82
85
88
89void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context);
90void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context);
91
98#define pcmk__config_err(fmt...) do { \
99 crm_config_error = TRUE; \
100 if (pcmk__config_error_handler == NULL) { \
101 crm_err(fmt); \
102 } else { \
103 pcmk__config_error_handler(pcmk__config_error_context, fmt); \
104 } \
105 } while (0)
106
113#define pcmk__config_warn(fmt...) do { \
114 crm_config_warning = TRUE; \
115 if (pcmk__config_warning_handler == NULL) { \
116 crm_warn(fmt); \
117 } else { \
118 pcmk__config_warning_handler(pcmk__config_warning_context, fmt);\
119 } \
120 } while (0)
121
135#define pcmk__if_tracing(if_action, else_action) do { \
136 static struct qb_log_callsite *trace_cs = NULL; \
137 \
138 if (trace_cs == NULL) { \
139 trace_cs = qb_log_callsite_get(__func__, __FILE__, \
140 "if_tracing", LOG_TRACE, \
141 __LINE__, crm_trace_nonlog); \
142 } \
143 if (crm_is_callsite_active(trace_cs, LOG_TRACE, \
144 crm_trace_nonlog)) { \
145 if_action; \
146 } else { \
147 else_action; \
148 } \
149 } while (0)
150
160#define pcmk__log_xml_changes(level, xml) do { \
161 uint8_t _level = pcmk__clip_log_level(level); \
162 static struct qb_log_callsite *xml_cs = NULL; \
163 \
164 switch (_level) { \
165 case LOG_STDOUT: \
166 case LOG_NEVER: \
167 break; \
168 default: \
169 if (xml_cs == NULL) { \
170 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
171 "xml-changes", _level, \
172 __LINE__, 0); \
173 } \
174 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
175 pcmk__log_xml_changes_as(__FILE__, __func__, __LINE__, \
176 0, _level, xml); \
177 } \
178 break; \
179 } \
180 } while(0)
181
191#define pcmk__log_xml_patchset(level, patchset) do { \
192 uint8_t _level = pcmk__clip_log_level(level); \
193 static struct qb_log_callsite *xml_cs = NULL; \
194 \
195 switch (_level) { \
196 case LOG_STDOUT: \
197 case LOG_NEVER: \
198 break; \
199 default: \
200 if (xml_cs == NULL) { \
201 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
202 "xml-patchset", _level, \
203 __LINE__, 0); \
204 } \
205 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
206 pcmk__log_xml_patchset_as(__FILE__, __func__, __LINE__, \
207 0, _level, patchset); \
208 } \
209 break; \
210 } \
211 } while(0)
212
213void pcmk__log_xml_changes_as(const char *file, const char *function,
214 uint32_t line, uint32_t tags, uint8_t level,
215 const xmlNode *xml);
216
217void pcmk__log_xml_patchset_as(const char *file, const char *function,
218 uint32_t line, uint32_t tags, uint8_t level,
219 const xmlNode *patchset);
220
230void pcmk__cli_init_logging(const char *name, unsigned int verbosity);
231
232int pcmk__add_logfile(const char *filename);
233void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out);
234
235void pcmk__free_common_logger(void);
236
237#ifdef __cplusplus
238}
239#endif
240
241#endif
const char * name
Definition cib.c:26
Wrappers for and extensions to libqb logging.
void(* pcmk__config_warning_func)(void *ctx, const char *msg,...)
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 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__config_error_func)(void *ctx, const char *msg,...)
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
pcmk__config_error_func pcmk__config_error_handler
Definition logging.c:54
Formatted output for pacemaker tools.
This structure contains everything that makes up a single output formatter.