pacemaker  2.0.1-15814c6c0d
Scalable High-Availability cluster resource manager
logging.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
29 #ifndef CRM_LOGGING__H
30 # define CRM_LOGGING__H
31 
32 # include <qb/qblog.h>
33 
34 # ifndef LOG_TRACE
35 # define LOG_TRACE LOG_DEBUG+1
36 # endif
37 
38 /* "Extended information" logging support */
39 #ifdef QB_XS
40 # define CRM_XS QB_XS
41 # define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
42 #else
43 # define CRM_XS "|"
44 
45 /* A caller might want to check the return value, so we can't define this as a
46  * no-op, and we can't simply define it to be 0 because gcc will then complain
47  * when the value isn't checked.
48  */
49 static inline int
50 crm_extended_logging(int t, int e)
51 {
52  return 0;
53 }
54 #endif
55 
56 extern unsigned int crm_log_level;
57 extern gboolean crm_config_error;
58 extern gboolean crm_config_warning;
59 extern unsigned int crm_trace_nonlog;
60 
62 {
65  xml_log_option_text = 0x0004, /* add this option to dump text into xml */
74 };
75 
76 void crm_enable_blackbox(int nsig);
77 void crm_disable_blackbox(int nsig);
78 void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
79 
80 void crm_update_callsites(void);
81 
82 void crm_log_deinit(void);
83 
84 gboolean crm_log_cli_init(const char *entity);
85 
86 void crm_log_preinit(const char *entity, int argc, char **argv);
87 gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon,
88  gboolean to_stderr, int argc, char **argv, gboolean quiet);
89 
90 void crm_log_args(int argc, char **argv);
91 void crm_log_output_fn(const char *file, const char *function, int line, int level,
92  const char *prefix, const char *output);
93 # define crm_log_output(level, prefix, output) crm_log_output_fn(__FILE__, __FUNCTION__, __LINE__, level, prefix, output)
94 
95 gboolean crm_add_logfile(const char *filename);
96 
97 void crm_bump_log_level(int argc, char **argv);
98 
99 void crm_enable_stderr(int enable);
100 
101 gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags);
102 
103 void log_data_element(int log_level, const char *file, const char *function, int line,
104  const char *prefix, xmlNode * data, int depth, gboolean formatted);
105 
106 /* returns the old value */
107 unsigned int set_crm_log_level(unsigned int level);
108 
109 unsigned int get_crm_log_level(void);
110 
111 /*
112  * Throughout the macros below, note the leading, pre-comma, space in the
113  * various ' , ##args' occurrences to aid portability across versions of 'gcc'.
114  * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
115  */
116 #if defined(__clang__)
117 # define CRM_TRACE_INIT_DATA(name)
118 # else
119 # include <assert.h> // required by QB_LOG_INIT_DATA() macro
120 # define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
121 #endif
122 
130 # define do_crm_log(level, fmt, args...) \
131  qb_log_from_external_source(__func__, __FILE__, fmt, level, __LINE__, 0 , ##args)
132 
140 # define do_crm_log_unlikely(level, fmt, args...) do { \
141  static struct qb_log_callsite *trace_cs = NULL; \
142  if(trace_cs == NULL) { \
143  trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
144  } \
145  if (crm_is_callsite_active(trace_cs, level, 0)) { \
146  qb_log_from_external_source( \
147  __func__, __FILE__, fmt, level, __LINE__, 0 , ##args); \
148  } \
149  } while(0)
150 
151 # define CRM_LOG_ASSERT(expr) do { \
152  if(__unlikely((expr) == FALSE)) { \
153  static struct qb_log_callsite *core_cs = NULL; \
154  if(core_cs == NULL) { \
155  core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
156  } \
157  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
158  core_cs?core_cs->targets:FALSE, TRUE); \
159  } \
160  } while(0)
161 
162 /* 'failure_action' MUST NOT be 'continue' as it will apply to the
163  * macro's do-while loop
164  */
165 # define CRM_CHECK(expr, failure_action) do { \
166  if(__unlikely((expr) == FALSE)) { \
167  static struct qb_log_callsite *core_cs = NULL; \
168  if(core_cs == NULL) { \
169  core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
170  } \
171  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
172  core_cs?core_cs->targets:FALSE, TRUE); \
173  failure_action; \
174  } \
175  } while(0)
176 
177 # define do_crm_log_xml(level, text, xml) do { \
178  static struct qb_log_callsite *xml_cs = NULL; \
179  if(xml_cs == NULL) { \
180  xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blob", level, __LINE__, 0); \
181  } \
182  if (crm_is_callsite_active(xml_cs, level, 0)) { \
183  log_data_element(level, __FILE__, __FUNCTION__, __LINE__, text, xml, 1, xml_log_option_formatted); \
184  } \
185  } while(0)
186 
197 # define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
198  if(level > 0) { \
199  qb_log_from_external_source(function, file, fmt, level, line, 0 , ##args); \
200  } else { \
201  printf(fmt "\n" , ##args); \
202  } \
203  } while(0)
204 
214 # define do_crm_log_always(level, fmt, args...) qb_log(level, fmt , ##args)
215 
227 # define crm_perror(level, fmt, args...) do { \
228  const char *err = strerror(errno); \
229  /* cast to int makes coverity happy when level == 0 */ \
230  if (level <= (int)crm_log_level) { \
231  fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, errno); \
232  } \
233  do_crm_log(level, fmt ": %s (%d)" , ##args, err, errno); \
234  } while(0)
235 
236 # define crm_log_tag(level, tag, fmt, args...) do { \
237  static struct qb_log_callsite *trace_tag_cs = NULL; \
238  int converted_tag = g_quark_try_string(tag); \
239  if(trace_tag_cs == NULL) { \
240  trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, converted_tag); \
241  } \
242  if (crm_is_callsite_active(trace_tag_cs, level, converted_tag)) { \
243  qb_log_from_external_source(__func__, __FILE__, fmt, level, \
244  __LINE__, converted_tag , ##args); \
245  } \
246  } while(0)
247 
248 # define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
249 # define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
250 # define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
251 # define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
252 # define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
253 
254 # define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
255 # define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
256 
257 # define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
258 # define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
259 # define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
260 # define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
261 # define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
262 # define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
263 # define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
264 
265 # define crm_log_xml_explicit(xml, text) do { \
266  static struct qb_log_callsite *digest_cs = NULL; \
267  digest_cs = qb_log_callsite_get( \
268  __func__, __FILE__, text, LOG_TRACE, __LINE__, \
269  crm_trace_nonlog); \
270  if (digest_cs && digest_cs->targets) { \
271  do_crm_log_xml(LOG_TRACE, text, xml); \
272  } \
273  } while(0)
274 
275 # define crm_str(x) (const char*)(x?x:"<null>")
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
Definition: logging.c:432
void crm_enable_stderr(int enable)
Definition: logging.c:924
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:770
unsigned int crm_trace_nonlog
Definition: logging.c:37
gboolean crm_log_cli_init(const char *entity)
Definition: logging.c:489
void crm_bump_log_level(int argc, char **argv)
Definition: logging.c:936
void crm_log_deinit(void)
Definition: logging.c:167
gboolean crm_config_error
Definition: utils.c:57
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:993
void crm_enable_blackbox(int nsig)
Definition: logging.c:420
xml_log_options
Definition: logging.h:61
void crm_log_args(int argc, char **argv)
Definition: logging.c:961
unsigned int set_crm_log_level(unsigned int level)
Definition: logging.c:913
void crm_log_preinit(const char *entity, int argc, char **argv)
Definition: logging.c:714
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Definition: logging.c:599
unsigned int get_crm_log_level(void)
Definition: logging.c:954
unsigned int crm_log_level
Definition: logging.c:35
void crm_disable_blackbox(int nsig)
Definition: logging.c:426
gboolean crm_config_warning
Definition: utils.c:58
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:87
#define uint8_t
Definition: stdint.in.h:144
gboolean crm_add_logfile(const char *filename)
Definition: logging.c:219
void crm_update_callsites(void)
Definition: logging.c:628