pacemaker 3.0.1-16e74fc4da
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#ifndef PCMK__CRM_COMMON_LOGGING_INTERNAL__H
11#define PCMK__CRM_COMMON_LOGGING_INTERNAL__H
12
13#include <glib.h>
14
15#include <crm/common/logging.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
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 */
42
50#define pcmk__warn_once(wo_flag, fmt...) do { \
51 if (!pcmk_is_set(pcmk__warnings, wo_flag)) { \
52 if (wo_flag == pcmk__wo_blind) { \
53 crm_warn(fmt); \
54 } else { \
55 pcmk__config_warn(fmt); \
56 } \
57 pcmk__warnings = pcmk__set_flags_as(__func__, __LINE__, \
58 LOG_TRACE, \
59 "Warn-once", "logging", \
60 pcmk__warnings, \
61 (wo_flag), #wo_flag); \
62 } \
63 } while (0)
64
65typedef void (*pcmk__config_error_func) (void *ctx, const char *msg, ...)
66 G_GNUC_PRINTF(2, 3);
67typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...)
68 G_GNUC_PRINTF(2, 3);
69
72
75
76void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context);
77void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context);
78
79/* Pacemaker library functions set this when a configuration error is found,
80 * which turns on extra messages at the end of processing.
81 */
82extern bool pcmk__config_has_error;
83
84/* Pacemaker library functions set this when a configuration warning is found,
85 * which turns on extra messages at the end of processing.
86 */
87extern bool pcmk__config_has_warning;
88
95#define pcmk__config_err(fmt...) do { \
96 pcmk__config_has_error = true; \
97 if (pcmk__config_error_handler == NULL) { \
98 crm_err(fmt); \
99 } else { \
100 pcmk__config_error_handler(pcmk__config_error_context, fmt); \
101 } \
102 } while (0)
103
110#define pcmk__config_warn(fmt...) do { \
111 pcmk__config_has_warning = true; \
112 if (pcmk__config_warning_handler == NULL) { \
113 crm_warn(fmt); \
114 } else { \
115 pcmk__config_warning_handler(pcmk__config_warning_context, fmt);\
116 } \
117 } while (0)
118
132#define pcmk__if_tracing(if_action, else_action) do { \
133 static struct qb_log_callsite *trace_cs = NULL; \
134 \
135 if (trace_cs == NULL) { \
136 trace_cs = qb_log_callsite_get(__func__, __FILE__, \
137 "if_tracing", LOG_TRACE, \
138 __LINE__, crm_trace_nonlog); \
139 } \
140 if (crm_is_callsite_active(trace_cs, LOG_TRACE, \
141 crm_trace_nonlog)) { \
142 if_action; \
143 } else { \
144 else_action; \
145 } \
146 } while (0)
147
157#define pcmk__log_xml_changes(level, xml) do { \
158 uint8_t _level = pcmk__clip_log_level(level); \
159 static struct qb_log_callsite *xml_cs = NULL; \
160 \
161 switch (_level) { \
162 case LOG_STDOUT: \
163 case LOG_NEVER: \
164 break; \
165 default: \
166 if (xml_cs == NULL) { \
167 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
168 "xml-changes", _level, \
169 __LINE__, 0); \
170 } \
171 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
172 pcmk__log_xml_changes_as(__FILE__, __func__, __LINE__, \
173 0, _level, xml); \
174 } \
175 break; \
176 } \
177 } while(0)
178
188#define pcmk__log_xml_patchset(level, patchset) do { \
189 uint8_t _level = pcmk__clip_log_level(level); \
190 static struct qb_log_callsite *xml_cs = NULL; \
191 \
192 switch (_level) { \
193 case LOG_STDOUT: \
194 case LOG_NEVER: \
195 break; \
196 default: \
197 if (xml_cs == NULL) { \
198 xml_cs = qb_log_callsite_get(__func__, __FILE__, \
199 "xml-patchset", _level, \
200 __LINE__, 0); \
201 } \
202 if (crm_is_callsite_active(xml_cs, _level, 0)) { \
203 pcmk__log_xml_patchset_as(__FILE__, __func__, __LINE__, \
204 0, _level, patchset); \
205 } \
206 break; \
207 } \
208 } while(0)
209
210void pcmk__log_xml_changes_as(const char *file, const char *function,
211 uint32_t line, uint32_t tags, uint8_t level,
212 const xmlNode *xml);
213
214void pcmk__log_xml_patchset_as(const char *file, const char *function,
215 uint32_t line, uint32_t tags, uint8_t level,
216 const xmlNode *patchset);
217
227void pcmk__cli_init_logging(const char *name, unsigned int verbosity);
228
229int pcmk__add_logfile(const char *filename);
230void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out);
231
232void pcmk__free_common_logger(void);
233
234#ifdef __cplusplus
235}
236#endif
237
238#endif // PCMK__CRM_COMMON_LOGGING_INTERNAL__H
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:331
void pcmk__free_common_logger(void)
Definition logging.c:1280
pcmk__config_warning_func pcmk__config_warning_handler
Definition logging.c:58
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:1258
void * pcmk__config_warning_context
Definition logging.c:60
void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out)
Add multiple additional log files.
Definition logging.c:415
void typedef void pcmk__config_error_func pcmk__config_error_handler
bool pcmk__config_has_error
Definition utils.c:43
void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context)
Definition logging.c:1289
void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context)
Definition logging.c:1295
void * pcmk__config_error_context
Definition logging.c:59
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:1227
void typedef void(* pcmk__config_warning_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
void pcmk__cli_init_logging(const char *name, unsigned int verbosity)
Definition logging.c:1164
pcmk__warnings
@ pcmk__wo_require_all
@ pcmk__wo_group_coloc
@ pcmk__wo_op_attr_expr
@ pcmk__wo_group_order
@ pcmk__wo_blind
@ pcmk__wo_rdisc_enabled
@ pcmk__wo_order_score
@ pcmk__wo_clone_master_max
@ pcmk__wo_set_ordering
@ pcmk__wo_master_role
@ pcmk__wo_record_pending
@ pcmk__wo_clone_master_node_max
@ pcmk__wo_slave_role
bool pcmk__config_has_warning
Definition utils.c:44
Formatted output for pacemaker tools.
This structure contains everything that makes up a single output formatter.