2
* Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
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.
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.
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
21
* \brief Wrappers for and extensions to libqb logging
25
#ifndef CRM_LOGGING__H
26
# define CRM_LOGGING__H
27
# include <qb/qblog.h>
29
# define LOG_TRACE LOG_DEBUG+1
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
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;
42
void crm_enable_blackbox(int nsig);
43
void crm_enable_blackbox_tracing(int nsig);
44
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
46
void crm_update_callsites(void);
48
void crm_log_deinit(void);
50
gboolean crm_log_cli_init(const char *entity);
52
gboolean crm_log_init(const char *entity, int level, gboolean daemon,
53
gboolean to_stderr, int argc, char **argv, gboolean quiet);
55
void crm_log_args(int argc, char **argv);
56
void crm_log_output_fn(const char *file, const char *function, int line, int level,
57
const char *prefix, const char *output);
58
# define crm_log_output(level, prefix, output) crm_log_output_fn(__FILE__, __FUNCTION__, __LINE__, level, prefix, output)
60
gboolean crm_add_logfile(const char *filename);
62
void crm_bump_log_level(int argc, char **argv);
64
void crm_enable_stderr(int enable);
66
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, int level, int tags);
68
void log_data_element(int log_level, const char *file, const char *function, int line,
69
const char *prefix, xmlNode * data, int depth, gboolean formatted);
71
/* returns the old value */
72
unsigned int set_crm_log_level(unsigned int level);
74
unsigned int get_crm_log_level(void);
77
* Throughout the macros below, note the leading, pre-comma, space in the
78
* various ' , ##args' occurences to aid portability across versions of 'gcc'.
79
* http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
81
# define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
83
# define do_crm_log(level, fmt, args...) qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, 0, ##args)
85
/* level /MUST/ be a constant or compilation will fail */
86
# define do_crm_log_unlikely(level, fmt, args...) do { \
87
static struct qb_log_callsite *trace_cs = NULL; \
88
if(trace_cs == NULL) { \
89
trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
91
if (crm_is_callsite_active(trace_cs, level, 0)) { \
92
qb_log_from_external_source( \
93
__func__, __FILE__, fmt, level, __LINE__, 0, ##args); \
97
# define CRM_LOG_ASSERT(expr) do { \
98
if(__unlikely((expr) == FALSE)) { \
99
static struct qb_log_callsite *core_cs = NULL; \
100
if(core_cs == NULL) { \
101
core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
103
crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
104
core_cs?core_cs->targets:FALSE, TRUE); \
108
# define CRM_CHECK(expr, failure_action) do { \
109
if(__unlikely((expr) == FALSE)) { \
110
static struct qb_log_callsite *core_cs = NULL; \
111
if(core_cs == NULL) { \
112
core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
114
crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
115
core_cs?core_cs->targets:FALSE, TRUE); \
120
# define do_crm_log_xml(level, text, xml) do { \
121
static struct qb_log_callsite *xml_cs = NULL; \
122
if(xml_cs == NULL) { \
123
xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blog", level, __LINE__, 0); \
125
if (crm_is_callsite_active(xml_cs, level, 0)) { \
126
log_data_element(level, __FILE__, __PRETTY_FUNCTION__, __LINE__, text, xml, 0, TRUE); \
130
# define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
131
qb_log_from_external_source(function, file, fmt, level, line, 0, ##args); \
134
# define do_crm_log_always(level, fmt, args...) qb_log(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args)
136
# define crm_perror(level, fmt, args...) do { \
137
const char *err = strerror(errno); \
138
fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \
139
do_crm_log(level, fmt ": %s (%d)", ##args, err, errno); \
142
# define crm_log_tag(level, tag, fmt, args...) do { \
143
static struct qb_log_callsite *trace_tag_cs = NULL; \
144
int converted_tag = g_quark_try_string(tag); \
145
if(trace_tag_cs == NULL) { \
146
trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, converted_tag); \
148
if (crm_is_callsite_active(trace_tag_cs, level, converted_tag)) { \
149
qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, converted_tag, ##args); \
153
# define crm_crit(fmt, args...) qb_logt(LOG_CRIT, 0, fmt , ##args)
154
# define crm_err(fmt, args...) qb_logt(LOG_ERR, 0, fmt , ##args)
155
# define crm_warn(fmt, args...) qb_logt(LOG_WARNING, 0, fmt , ##args)
156
# define crm_notice(fmt, args...) qb_logt(LOG_NOTICE, 0, fmt , ##args)
157
# define crm_info(fmt, args...) qb_logt(LOG_INFO, 0, fmt , ##args)
159
# define crm_debug(fmt, args...) do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
160
# define crm_trace(fmt, args...) do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
162
# define crm_log_xml_crit(xml, text) do_crm_log_xml(LOG_CRIT, text, xml)
163
# define crm_log_xml_err(xml, text) do_crm_log_xml(LOG_ERR, text, xml)
164
# define crm_log_xml_warn(xml, text) do_crm_log_xml(LOG_WARNING, text, xml)
165
# define crm_log_xml_notice(xml, text) do_crm_log_xml(LOG_NOTICE, text, xml)
166
# define crm_log_xml_info(xml, text) do_crm_log_xml(LOG_INFO, text, xml)
167
# define crm_log_xml_debug(xml, text) do_crm_log_xml(LOG_DEBUG, text, xml)
168
# define crm_log_xml_trace(xml, text) do_crm_log_xml(LOG_TRACE, text, xml)
170
# define crm_log_xml_explicit(xml, text) do { \
171
static struct qb_log_callsite *digest_cs = NULL; \
172
digest_cs = qb_log_callsite_get( \
173
__func__, __FILE__, text, LOG_TRACE, __LINE__, \
175
if (digest_cs && digest_cs->targets) { \
176
do_crm_log_xml(LOG_TRACE, text, xml); \
180
# define crm_str(x) (const char*)(x?x:"<null>")