pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
logging.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2019 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 
20 #ifndef CRM_LOGGING__H
21 # define CRM_LOGGING__H
22 
23 # include <qb/qblog.h>
24 
25 # ifndef LOG_TRACE
26 # define LOG_TRACE LOG_DEBUG+1
27 # endif
28 
29 /* "Extended information" logging support */
30 #ifdef QB_XS
31 # define CRM_XS QB_XS
32 # define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
33 #else
34 # define CRM_XS "|"
35 
36 /* A caller might want to check the return value, so we can't define this as a
37  * no-op, and we can't simply define it to be 0 because gcc will then complain
38  * when the value isn't checked.
39  */
40 static inline int
41 crm_extended_logging(int t, int e)
42 {
43  return 0;
44 }
45 #endif
46 
47 extern unsigned int crm_log_level;
48 extern gboolean crm_config_error;
49 extern gboolean crm_config_warning;
50 extern unsigned int crm_trace_nonlog;
51 
53 {
56  xml_log_option_text = 0x0004, /* add this option to dump text into xml */
65 };
66 
67 void crm_enable_blackbox(int nsig);
68 void crm_disable_blackbox(int nsig);
69 void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
70 
71 void crm_update_callsites(void);
72 
73 void crm_log_deinit(void);
74 
75 gboolean crm_log_cli_init(const char *entity);
76 
77 void crm_log_preinit(const char *entity, int argc, char **argv);
78 gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon,
79  gboolean to_stderr, int argc, char **argv, gboolean quiet);
80 
81 void crm_log_args(int argc, char **argv);
82 void crm_log_output_fn(const char *file, const char *function, int line, int level,
83  const char *prefix, const char *output);
84 # define crm_log_output(level, prefix, output) crm_log_output_fn(__FILE__, __FUNCTION__, __LINE__, level, prefix, output)
85 
86 gboolean crm_add_logfile(const char *filename);
87 
88 void crm_bump_log_level(int argc, char **argv);
89 
90 void crm_enable_stderr(int enable);
91 
92 gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags);
93 
94 void log_data_element(int log_level, const char *file, const char *function, int line,
95  const char *prefix, xmlNode * data, int depth, gboolean formatted);
96 
97 /* returns the old value */
98 unsigned int set_crm_log_level(unsigned int level);
99 
100 unsigned int get_crm_log_level(void);
101 
102 /*
103  * Throughout the macros below, note the leading, pre-comma, space in the
104  * various ' , ##args' occurrences to aid portability across versions of 'gcc'.
105  * https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
106  */
107 #if defined(__clang__)
108 # define CRM_TRACE_INIT_DATA(name)
109 # else
110 # include <assert.h> // required by QB_LOG_INIT_DATA() macro
111 # define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
112 #endif
113 
121 # define do_crm_log(level, fmt, args...) \
122  qb_log_from_external_source(__func__, __FILE__, fmt, level, __LINE__, 0 , ##args)
123 
131 # define do_crm_log_unlikely(level, fmt, args...) do { \
132  static struct qb_log_callsite *trace_cs = NULL; \
133  if(trace_cs == NULL) { \
134  trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
135  } \
136  if (crm_is_callsite_active(trace_cs, level, 0)) { \
137  qb_log_from_external_source( \
138  __func__, __FILE__, fmt, level, __LINE__, 0 , ##args); \
139  } \
140  } while(0)
141 
142 # define CRM_LOG_ASSERT(expr) do { \
143  if(__unlikely((expr) == FALSE)) { \
144  static struct qb_log_callsite *core_cs = NULL; \
145  if(core_cs == NULL) { \
146  core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
147  } \
148  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
149  core_cs?core_cs->targets:FALSE, TRUE); \
150  } \
151  } while(0)
152 
153 /* 'failure_action' MUST NOT be 'continue' as it will apply to the
154  * macro's do-while loop
155  */
156 # define CRM_CHECK(expr, failure_action) do { \
157  if(__unlikely((expr) == FALSE)) { \
158  static struct qb_log_callsite *core_cs = NULL; \
159  if(core_cs == NULL) { \
160  core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
161  } \
162  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
163  core_cs?core_cs->targets:FALSE, TRUE); \
164  failure_action; \
165  } \
166  } while(0)
167 
168 # define do_crm_log_xml(level, text, xml) do { \
169  static struct qb_log_callsite *xml_cs = NULL; \
170  if(xml_cs == NULL) { \
171  xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blob", level, __LINE__, 0); \
172  } \
173  if (crm_is_callsite_active(xml_cs, level, 0)) { \
174  log_data_element(level, __FILE__, __FUNCTION__, __LINE__, text, xml, 1, xml_log_option_formatted); \
175  } \
176  } while(0)
177 
188 # define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
189  if(level > 0) { \
190  qb_log_from_external_source(function, file, fmt, level, line, 0 , ##args); \
191  } else { \
192  printf(fmt "\n" , ##args); \
193  } \
194  } while(0)
195 
205 # define do_crm_log_always(level, fmt, args...) qb_log(level, fmt , ##args)
206 
218 # define crm_perror(level, fmt, args...) do { \
219  const char *err = strerror(errno); \
220  /* cast to int makes coverity happy when level == 0 */ \
221  if (level <= (int)crm_log_level) { \
222  fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, errno); \
223  } \
224  do_crm_log(level, fmt ": %s (%d)" , ##args, err, errno); \
225  } while(0)
226 
227 # define crm_log_tag(level, tag, fmt, args...) do { \
228  static struct qb_log_callsite *trace_tag_cs = NULL; \
229  int converted_tag = g_quark_try_string(tag); \
230  if(trace_tag_cs == NULL) { \
231  trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, converted_tag); \
232  } \
233  if (crm_is_callsite_active(trace_tag_cs, level, converted_tag)) { \
234  qb_log_from_external_source(__func__, __FILE__, fmt, level, \
235  __LINE__, converted_tag , ##args); \
236  } \
237  } while(0)
238 
239 # define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
240 # define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
241 # define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
242 # define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
243 # define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
244 
245 # define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
246 # define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
247 
248 # define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
249 # define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
250 # define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
251 # define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
252 # define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
253 # define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
254 # define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
255 
256 # define crm_log_xml_explicit(xml, text) do { \
257  static struct qb_log_callsite *digest_cs = NULL; \
258  digest_cs = qb_log_callsite_get( \
259  __func__, __FILE__, text, LOG_TRACE, __LINE__, \
260  crm_trace_nonlog); \
261  if (digest_cs && digest_cs->targets) { \
262  do_crm_log_xml(LOG_TRACE, text, xml); \
263  } \
264  } while(0)
265 
266 # define crm_str(x) (const char*)(x?x:"<null>")
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 #endif
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
Definition: logging.c:457
void crm_enable_stderr(int enable)
Definition: logging.c:949
void log_data_element(int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, gboolean formatted)
gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon, gboolean to_stderr, int argc, char **argv, gboolean quiet)
Definition: logging.c:795
unsigned int crm_trace_nonlog
Definition: logging.c:39
gboolean crm_log_cli_init(const char *entity)
Definition: logging.c:514
void crm_bump_log_level(int argc, char **argv)
Definition: logging.c:961
void crm_log_deinit(void)
Definition: logging.c:177
gboolean crm_config_error
Definition: utils.c:59
int daemon(int nochdir, int noclose)
void crm_log_output_fn(const char *file, const char *function, int line, int level, const char *prefix, const char *output)
Definition: logging.c:1018
void crm_enable_blackbox(int nsig)
Definition: logging.c:435
xml_log_options
Definition: logging.h:52
void crm_log_args(int argc, char **argv)
Definition: logging.c:986
unsigned int set_crm_log_level(unsigned int level)
Definition: logging.c:938
void crm_log_preinit(const char *entity, int argc, char **argv)
Definition: logging.c:739
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:624
unsigned int get_crm_log_level(void)
Definition: logging.c:979
unsigned int crm_log_level
Definition: logging.c:37
void crm_disable_blackbox(int nsig)
Definition: logging.c:441
gboolean crm_config_warning
Definition: utils.c:60
char data[0]
Definition: internal.h:92
gboolean crm_add_logfile(const char *filename)
Definition: logging.c:229
void crm_update_callsites(void)
Definition: logging.c:653