pacemaker  1.1.12-561c4cf
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 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 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 
25 #ifndef CRM_LOGGING__H
26 # define CRM_LOGGING__H
27 # include <qb/qblog.h>
28 # ifndef LOG_TRACE
29 # define LOG_TRACE LOG_DEBUG+1
30 # endif
31 # define LOG_DEBUG_2 LOG_TRACE
32 # define LOG_DEBUG_3 LOG_TRACE
33 # define LOG_DEBUG_4 LOG_TRACE
34 # define LOG_DEBUG_5 LOG_TRACE
35 # define LOG_DEBUG_6 LOG_TRACE
36 
37 extern unsigned int crm_log_level;
38 extern gboolean crm_config_error;
39 extern gboolean crm_config_warning;
40 extern unsigned int crm_trace_nonlog;
41 
43 {
54 };
55 
56 void crm_enable_blackbox(int nsig);
57 void crm_disable_blackbox(int nsig);
58 void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
59 
60 void crm_update_callsites(void);
61 
62 void crm_log_deinit(void);
63 
64 gboolean crm_log_cli_init(const char *entity);
65 
66 void crm_log_preinit(const char *entity, int argc, char **argv);
67 gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon,
68  gboolean to_stderr, int argc, char **argv, gboolean quiet);
69 
70 void crm_log_args(int argc, char **argv);
71 void crm_log_output_fn(const char *file, const char *function, int line, int level,
72  const char *prefix, const char *output);
73 # define crm_log_output(level, prefix, output) crm_log_output_fn(__FILE__, __FUNCTION__, __LINE__, level, prefix, output)
74 
75 gboolean crm_add_logfile(const char *filename);
76 
77 void crm_bump_log_level(int argc, char **argv);
78 
79 void crm_enable_stderr(int enable);
80 
81 gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags);
82 
83 void log_data_element(int log_level, const char *file, const char *function, int line,
84  const char *prefix, xmlNode * data, int depth, gboolean formatted);
85 
86 /* returns the old value */
87 unsigned int set_crm_log_level(unsigned int level);
88 
89 unsigned int get_crm_log_level(void);
90 
91 /*
92  * Throughout the macros below, note the leading, pre-comma, space in the
93  * various ' , ##args' occurences to aid portability across versions of 'gcc'.
94  * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
95  */
96 #if defined(__clang__)
97 # define CRM_TRACE_INIT_DATA(name)
98 # else
99 # define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
100 #endif
101 
102 # define do_crm_log(level, fmt, args...) qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, 0, ##args)
103 
104 /* level /MUST/ be a constant or compilation will fail */
105 # define do_crm_log_unlikely(level, fmt, args...) do { \
106  static struct qb_log_callsite *trace_cs = NULL; \
107  if(trace_cs == NULL) { \
108  trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
109  } \
110  if (crm_is_callsite_active(trace_cs, level, 0)) { \
111  qb_log_from_external_source( \
112  __func__, __FILE__, fmt, level, __LINE__, 0, ##args); \
113  } \
114  } while(0)
115 
116 # define CRM_LOG_ASSERT(expr) do { \
117  if(__unlikely((expr) == FALSE)) { \
118  static struct qb_log_callsite *core_cs = NULL; \
119  if(core_cs == NULL) { \
120  core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
121  } \
122  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
123  core_cs?core_cs->targets:FALSE, TRUE); \
124  } \
125  } while(0)
126 
127 /* 'failure_action' MUST NOT be 'continue' as it will apply to the
128  * macro's do-while loop
129  */
130 # define CRM_CHECK(expr, failure_action) do { \
131  if(__unlikely((expr) == FALSE)) { \
132  static struct qb_log_callsite *core_cs = NULL; \
133  if(core_cs == NULL) { \
134  core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
135  } \
136  crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, \
137  core_cs?core_cs->targets:FALSE, TRUE); \
138  failure_action; \
139  } \
140  } while(0)
141 
142 # define do_crm_log_xml(level, text, xml) do { \
143  static struct qb_log_callsite *xml_cs = NULL; \
144  if(xml_cs == NULL) { \
145  xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blob", level, __LINE__, 0); \
146  } \
147  if (crm_is_callsite_active(xml_cs, level, 0)) { \
148  log_data_element(level, __FILE__, __FUNCTION__, __LINE__, text, xml, 1, xml_log_option_formatted); \
149  } \
150  } while(0)
151 
152 # define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
153  if(level > 0) { \
154  qb_log_from_external_source(function, file, fmt, level, line, 0, ##args); \
155  } else { \
156  printf(fmt "\n", ##args); \
157  } \
158  } while(0)
159 
160 # define do_crm_log_always(level, fmt, args...) qb_log(level, "%s: " fmt, __FUNCTION__ , ##args)
161 
162 # define crm_perror(level, fmt, args...) do { \
163  const char *err = strerror(errno); \
164  if(level <= crm_log_level) { \
165  fprintf(stderr, "%s: " fmt ": %s (%d)\n", __FUNCTION__, ##args, err, errno); \
166  } \
167  do_crm_log(level, fmt ": %s (%d)", ##args, err, errno); \
168  } while(0)
169 
170 # define crm_log_tag(level, tag, fmt, args...) do { \
171  static struct qb_log_callsite *trace_tag_cs = NULL; \
172  int converted_tag = g_quark_try_string(tag); \
173  if(trace_tag_cs == NULL) { \
174  trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, converted_tag); \
175  } \
176  if (crm_is_callsite_active(trace_tag_cs, level, converted_tag)) { \
177  qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, converted_tag, ##args); \
178  } \
179  } while(0)
180 
181 # define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
182 # define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
183 # define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
184 # define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
185 # define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
186 
187 # define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
188 # define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
189 
190 # define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
191 # define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
192 # define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
193 # define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
194 # define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
195 # define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
196 # define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
197 
198 # define crm_log_xml_explicit(xml, text) do { \
199  static struct qb_log_callsite *digest_cs = NULL; \
200  digest_cs = qb_log_callsite_get( \
201  __func__, __FILE__, text, LOG_TRACE, __LINE__, \
202  crm_trace_nonlog); \
203  if (digest_cs && digest_cs->targets) { \
204  do_crm_log_xml(LOG_TRACE, text, xml); \
205  } \
206  } while(0)
207 
208 # define crm_str(x) (const char*)(x?x:"<null>")
209 
210 #endif
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
void crm_enable_stderr(int enable)
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)
unsigned int crm_trace_nonlog
gboolean crm_log_cli_init(const char *entity)
void crm_bump_log_level(int argc, char **argv)
void crm_log_deinit(void)
gboolean crm_config_error
void crm_log_output_fn(const char *file, const char *function, int line, int level, const char *prefix, const char *output)
void crm_enable_blackbox(int nsig)
xml_log_options
Definition: logging.h:42
void crm_log_args(int argc, char **argv)
unsigned int set_crm_log_level(unsigned int level)
void crm_log_preinit(const char *entity, int argc, char **argv)
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
unsigned int get_crm_log_level(void)
unsigned int crm_log_level
void crm_disable_blackbox(int nsig)
gboolean crm_config_warning
char data[0]
Definition: internal.h:58
gboolean crm_add_logfile(const char *filename)
void crm_update_callsites(void)