~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to include/crm/common/logging.h

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-07-16 16:40:24 UTC
  • mfrom: (1.1.11) (2.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130716164024-lvwrf4xivk1wdr3c
Tags: 1.1.9+git20130321-1ubuntu1
* Resync from debian expiremental.
* debian/control:
  - Use lower version for Build-Depends on libcorosync-dev
    and libqb-dev.
  - Build-Depends on libcfg-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
/**
 
20
 * \file
 
21
 * \brief Wrappers for and extensions to libqb logging
 
22
 * \ingroup core
 
23
 */
 
24
 
 
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
 
 
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);
 
45
 
 
46
void crm_update_callsites(void);
 
47
 
 
48
void crm_log_deinit(void);
 
49
 
 
50
gboolean crm_log_cli_init(const char *entity);
 
51
 
 
52
gboolean crm_log_init(const char *entity, int level, gboolean daemon,
 
53
                      gboolean to_stderr, int argc, char **argv, gboolean quiet);
 
54
 
 
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)
 
59
 
 
60
gboolean crm_add_logfile(const char *filename);
 
61
 
 
62
void crm_bump_log_level(int argc, char **argv);
 
63
 
 
64
void crm_enable_stderr(int enable);
 
65
 
 
66
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, int level, int tags);
 
67
 
 
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);
 
70
 
 
71
/* returns the old value */
 
72
unsigned int set_crm_log_level(unsigned int level);
 
73
 
 
74
unsigned int get_crm_log_level(void);
 
75
 
 
76
/*
 
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
 
80
 */
 
81
#  define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
 
82
 
 
83
#  define do_crm_log(level, fmt, args...) qb_log_from_external_source( __func__, __FILE__, fmt, level, __LINE__, 0, ##args)
 
84
 
 
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); \
 
90
        }                                                               \
 
91
        if (crm_is_callsite_active(trace_cs, level, 0)) {            \
 
92
            qb_log_from_external_source(                                \
 
93
                __func__, __FILE__, fmt, level, __LINE__, 0,  ##args);  \
 
94
        }                                                               \
 
95
    } while(0)
 
96
 
 
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); \
 
102
            }                                                           \
 
103
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
 
104
                      core_cs?core_cs->targets:FALSE, TRUE);            \
 
105
        }                                                               \
 
106
    } while(0)
 
107
 
 
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); \
 
113
            }                                                           \
 
114
            crm_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr,   \
 
115
                      core_cs?core_cs->targets:FALSE, TRUE);            \
 
116
            failure_action;                                             \
 
117
        }                                                               \
 
118
    } while(0)
 
119
 
 
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); \
 
124
        }                                                               \
 
125
        if (crm_is_callsite_active(xml_cs, level, 0)) {                  \
 
126
            log_data_element(level, __FILE__, __PRETTY_FUNCTION__, __LINE__, text, xml, 0, TRUE); \
 
127
        }                                                               \
 
128
    } while(0)
 
129
 
 
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); \
 
132
    } while(0)
 
133
 
 
134
#  define do_crm_log_always(level, fmt, args...) qb_log(level, "%s: " fmt, __PRETTY_FUNCTION__ , ##args)
 
135
 
 
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);         \
 
140
    } while(0)
 
141
 
 
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); \
 
147
        }                                                               \
 
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); \
 
150
        }                                                               \
 
151
      } while(0)
 
152
 
 
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)
 
158
 
 
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)
 
161
 
 
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)
 
169
 
 
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__,      \
 
174
            crm_trace_nonlog);                                  \
 
175
        if (digest_cs && digest_cs->targets) {                  \
 
176
            do_crm_log_xml(LOG_TRACE,   text, xml);             \
 
177
        }                                                       \
 
178
    } while(0)
 
179
 
 
180
#  define crm_str(x)    (const char*)(x?x:"<null>")
 
181
 
 
182
#endif