pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
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
19 extern "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  */
28  pcmk__wo_blind = (1 << 0),
32  pcmk__wo_group_order = (1 << 11),
33  pcmk__wo_group_coloc = (1 << 12),
34  pcmk__wo_set_ordering = (1 << 15),
36  pcmk__wo_op_attr_expr = (1 << 19),
39  pcmk__wo_master_role = (1 << 26),
40  pcmk__wo_slave_role = (1 << 27),
41 };
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 
65 typedef void (*pcmk__config_error_func) (void *ctx, const char *msg, ...)
66  G_GNUC_PRINTF(2, 3);
67 typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...)
68  G_GNUC_PRINTF(2, 3);
69 
72 
73 extern void *pcmk__config_error_context;
74 extern void *pcmk__config_warning_context;
75 
76 void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context);
77 void 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  */
82 extern 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  */
87 extern 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 
210 void 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 
214 void 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 
227 void pcmk__cli_init_logging(const char *name, unsigned int verbosity);
228 
229 int pcmk__add_logfile(const char *filename);
230 void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out);
231 
232 void 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
void(*) typedef void(* pcmk__config_warning_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
void * pcmk__config_error_context
Definition: logging.c:59
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:1276
pcmk__warnings
Wrappers for and extensions to libqb logging.
void pcmk__set_config_warning_handler(pcmk__config_warning_func warning_handler, void *warning_context)
Definition: logging.c:1291
Formatted output for pacemaker tools.
pcmk__config_warning_func pcmk__config_warning_handler
Definition: logging.c:58
bool pcmk__config_has_error
Definition: utils.c:42
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:1254
void * pcmk__config_warning_context
Definition: logging.c:60
void pcmk__cli_init_logging(const char *name, unsigned int verbosity)
Definition: logging.c:1160
void(* pcmk__config_error_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
bool pcmk__config_has_warning
Definition: utils.c:43
void(*) typedef void(*) pcmk__config_error_fun pcmk__config_error_handler)
This structure contains everything that makes up a single output formatter.
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:1223
void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out)
Add multiple additional log files.
Definition: logging.c:415
void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context)
Definition: logging.c:1285