pacemaker  2.1.9-49aab99839
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 #ifdef __cplusplus
11 extern "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  */
28  pcmk__wo_blind = (1 << 0),
30  pcmk__wo_role_after = (1 << 2),
31  pcmk__wo_poweroff = (1 << 3),
36  pcmk__wo_ping_node = (1 << 8),
37  pcmk__wo_order_inst = (1 << 9),
38  pcmk__wo_coloc_inst = (1 << 10),
39  pcmk__wo_group_order = (1 << 11),
40  pcmk__wo_group_coloc = (1 << 12),
41  pcmk__wo_upstart = (1 << 13),
42  pcmk__wo_nagios = (1 << 14),
43  pcmk__wo_set_ordering = (1 << 15),
45  pcmk__wo_rkt = (1 << 17),
47  pcmk__wo_op_attr_expr = (1 << 19),
54  pcmk__wo_master_role = (1 << 26),
55  pcmk__wo_slave_role = (1 << 27),
56 };
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 
80 typedef void (*pcmk__config_error_func) (void *ctx, const char *msg, ...)
81  G_GNUC_PRINTF(2, 3);
82 typedef void (*pcmk__config_warning_func) (void *ctx, const char *msg, ...)
83  G_GNUC_PRINTF(2, 3);
84 
87 
88 extern void *pcmk__config_error_context;
89 extern void *pcmk__config_warning_context;
90 
91 void pcmk__set_config_error_handler(pcmk__config_error_func error_handler, void *error_context);
92 void 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 
215 void 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 
219 void 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 
232 void pcmk__cli_init_logging(const char *name, unsigned int verbosity);
233 
234 int pcmk__add_logfile(const char *filename);
235 void pcmk__add_logfiles(gchar **log_files, pcmk__output_t *out);
236 
237 void pcmk__free_common_logger(void);
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif
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:56
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__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:1293
Formatted output for pacemaker tools.
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__cli_init_logging(const char *name, unsigned int verbosity)
Definition: logging.c:1135
void(* pcmk__config_error_func)(void *ctx, const char *msg,...) G_GNUC_PRINTF(2
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:1198
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