root/include/crm/common/logging.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. crm_extended_logging

   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 /**
  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 /* "Extended information" logging support */
  38 #ifdef QB_XS
  39 #  define CRM_XS QB_XS
  40 #  define crm_extended_logging(t, e) qb_log_ctl((t), QB_LOG_CONF_EXTENDED, (e))
  41 #else
  42 #  define CRM_XS "|"
  43 
  44 /* A caller might want to check the return value, so we can't define this as a
  45  * no-op, and we can't simply define it to be 0 because gcc will then complain
  46  * when the value isn't checked.
  47  */
  48 static inline int
  49 crm_extended_logging(int t, int e)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51     return 0;
  52 }
  53 #endif
  54 
  55 extern unsigned int crm_log_level;
  56 extern gboolean crm_config_error;
  57 extern gboolean crm_config_warning;
  58 extern unsigned int crm_trace_nonlog;
  59 
  60 enum xml_log_options
  61 {
  62     xml_log_option_filtered   = 0x0001,
  63     xml_log_option_formatted  = 0x0002,
  64     xml_log_option_text       = 0x0004, /* add this option to dump text into xml */
  65     xml_log_option_diff_plus  = 0x0010,
  66     xml_log_option_diff_minus = 0x0020,
  67     xml_log_option_diff_short = 0x0040,
  68     xml_log_option_diff_all   = 0x0100,
  69     xml_log_option_dirty_add  = 0x1000,
  70     xml_log_option_open       = 0x2000,
  71     xml_log_option_children   = 0x4000,
  72     xml_log_option_close      = 0x8000,
  73 };
  74 
  75 void crm_enable_blackbox(int nsig);
  76 void crm_disable_blackbox(int nsig);
  77 void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite);
  78 
  79 void crm_update_callsites(void);
  80 
  81 void crm_log_deinit(void);
  82 
  83 gboolean crm_log_cli_init(const char *entity);
  84 
  85 void crm_log_preinit(const char *entity, int argc, char **argv);
  86 gboolean crm_log_init(const char *entity, uint8_t level, gboolean daemon,
  87                       gboolean to_stderr, int argc, char **argv, gboolean quiet);
  88 
  89 void crm_log_args(int argc, char **argv);
  90 void crm_log_output_fn(const char *file, const char *function, int line, int level,
  91                        const char *prefix, const char *output);
  92 #  define crm_log_output(level, prefix, output) crm_log_output_fn(__FILE__, __FUNCTION__, __LINE__, level, prefix, output)
  93 
  94 gboolean crm_add_logfile(const char *filename);
  95 
  96 void crm_bump_log_level(int argc, char **argv);
  97 
  98 void crm_enable_stderr(int enable);
  99 
 100 gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags);
 101 
 102 void log_data_element(int log_level, const char *file, const char *function, int line,
 103                       const char *prefix, xmlNode * data, int depth, gboolean formatted);
 104 char *crm_strdup_printf (char const *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
 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 #    define CRM_TRACE_INIT_DATA(name) QB_LOG_INIT_DATA(name)
 120 #endif
 121 
 122 /*!
 123  * \brief Log a message
 124  *
 125  * \param[in] level  Severity at which to log the message
 126  * \param[in] fmt    printf-style format string for message
 127  * \param[in] args   Any arguments needed by format string
 128  */
 129 #  define do_crm_log(level, fmt, args...) \
 130     qb_log_from_external_source(__func__, __FILE__, fmt, level, __LINE__, 0 , ##args)
 131 
 132 /*!
 133  * \brief Log a message that is likely to be filtered out
 134  *
 135  * \param[in] level  Severity at which to log the message
 136  * \param[in] fmt    printf-style format string for message
 137  * \param[in] args   Any arguments needed by format string
 138  */
 139 #  define do_crm_log_unlikely(level, fmt, args...) do {               \
 140         static struct qb_log_callsite *trace_cs = NULL;                 \
 141         if(trace_cs == NULL) {                                          \
 142             trace_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, 0); \
 143         }                                                               \
 144         if (crm_is_callsite_active(trace_cs, level, 0)) {            \
 145             qb_log_from_external_source(                                \
 146                 __func__, __FILE__, fmt, level, __LINE__, 0 , ##args); \
 147         }                                                               \
 148     } while(0)
 149 
 150 #  define CRM_LOG_ASSERT(expr) do {                                     \
 151         if(__unlikely((expr) == FALSE)) {                               \
 152             static struct qb_log_callsite *core_cs = NULL;              \
 153             if(core_cs == NULL) {                                       \
 154                 core_cs = qb_log_callsite_get(__func__, __FILE__, "log-assert", LOG_TRACE, __LINE__, 0); \
 155             }                                                           \
 156             crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr,   \
 157                       core_cs?core_cs->targets:FALSE, TRUE);            \
 158         }                                                               \
 159     } while(0)
 160 
 161 /* 'failure_action' MUST NOT be 'continue' as it will apply to the
 162  * macro's do-while loop
 163  */
 164 #  define CRM_CHECK(expr, failure_action) do {                          \
 165         if(__unlikely((expr) == FALSE)) {                               \
 166             static struct qb_log_callsite *core_cs = NULL;              \
 167             if(core_cs == NULL) {                                       \
 168                 core_cs = qb_log_callsite_get(__func__, __FILE__, "check-assert", LOG_TRACE, __LINE__, 0); \
 169             }                                                           \
 170             crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr,  \
 171                       core_cs?core_cs->targets:FALSE, TRUE);            \
 172             failure_action;                                             \
 173         }                                                               \
 174     } while(0)
 175 
 176 #  define do_crm_log_xml(level, text, xml) do {                       \
 177         static struct qb_log_callsite *xml_cs = NULL;                   \
 178         if(xml_cs == NULL) {                                            \
 179             xml_cs = qb_log_callsite_get(__func__, __FILE__, "xml-blob", level, __LINE__, 0); \
 180         }                                                               \
 181         if (crm_is_callsite_active(xml_cs, level, 0)) {                  \
 182             log_data_element(level, __FILE__, __FUNCTION__, __LINE__, text, xml, 1, xml_log_option_formatted); \
 183         }                                                               \
 184     } while(0)
 185 
 186 /*!
 187  * \brief Log a message as if it came from a different code location
 188  *
 189  * \param[in] level     Severity at which to log the message
 190  * \param[in] file      Source file name to use instead of __FILE__
 191  * \param[in] function  Source function name to use instead of __func__
 192  * \param[in] line      Source line number to use instead of __line__
 193  * \param[in] fmt       printf-style format string for message
 194  * \param[in] args      Any arguments needed by format string
 195  */
 196 #  define do_crm_log_alias(level, file, function, line, fmt, args...) do { \
 197         if(level > 0) {                                                 \
 198             qb_log_from_external_source(function, file, fmt, level, line, 0 , ##args); \
 199         } else {                                                        \
 200             printf(fmt "\n" , ##args);                                    \
 201         }                                                               \
 202     } while(0)
 203 
 204 /*!
 205  * \brief Log a message using constant severity
 206  *
 207  * \param[in] level     Severity at which to log the message
 208  * \param[in] fmt       printf-style format string for message
 209  * \param[in] args      Any arguments needed by format string
 210  *
 211  * \note level and fmt /MUST/ be constants else compilation may fail
 212  */
 213 #  define do_crm_log_always(level, fmt, args...) qb_log(level, fmt , ##args)
 214 
 215 /*!
 216  * \brief Log a system error message
 217  *
 218  * \param[in] level  Severity at which to log the message
 219  * \param[in] fmt    printf-style format string for message
 220  * \param[in] args   Any arguments needed by format string
 221  *
 222  * \note Because crm_perror() adds the system error message and error number
 223  *       onto the end of fmt, that information will become extended information
 224  *       if CRM_XS is used inside fmt and will not show up in syslog.
 225  */
 226 #  define crm_perror(level, fmt, args...) do {                          \
 227         const char *err = strerror(errno);                              \
 228         /* cast to int makes coverity happy when level == 0 */          \
 229         if (level <= (int)crm_log_level) {                              \
 230             fprintf(stderr, fmt ": %s (%d)\n" , ##args, err, errno);    \
 231         }                                                               \
 232         do_crm_log(level, fmt ": %s (%d)" , ##args, err, errno);        \
 233     } while(0)
 234 
 235 #  define crm_log_tag(level, tag, fmt, args...)    do {               \
 236         static struct qb_log_callsite *trace_tag_cs = NULL;                 \
 237         int converted_tag = g_quark_try_string(tag);                   \
 238         if(trace_tag_cs == NULL) {                                          \
 239             trace_tag_cs = qb_log_callsite_get(__func__, __FILE__, fmt, level, __LINE__, converted_tag); \
 240         }                                                               \
 241         if (crm_is_callsite_active(trace_tag_cs, level, converted_tag)) {               \
 242             qb_log_from_external_source(__func__, __FILE__, fmt, level,     \
 243                                         __LINE__, converted_tag , ##args);  \
 244         }                                                               \
 245       } while(0)
 246 
 247 #  define crm_crit(fmt, args...)    qb_logt(LOG_CRIT,    0, fmt , ##args)
 248 #  define crm_err(fmt, args...)     qb_logt(LOG_ERR,     0, fmt , ##args)
 249 #  define crm_warn(fmt, args...)    qb_logt(LOG_WARNING, 0, fmt , ##args)
 250 #  define crm_notice(fmt, args...)  qb_logt(LOG_NOTICE,  0, fmt , ##args)
 251 #  define crm_info(fmt, args...)    qb_logt(LOG_INFO,    0, fmt , ##args)
 252 
 253 #  define crm_debug(fmt, args...)   do_crm_log_unlikely(LOG_DEBUG, fmt , ##args)
 254 #  define crm_trace(fmt, args...)   do_crm_log_unlikely(LOG_TRACE, fmt , ##args)
 255 
 256 #  define crm_log_xml_crit(xml, text)    do_crm_log_xml(LOG_CRIT,    text, xml)
 257 #  define crm_log_xml_err(xml, text)     do_crm_log_xml(LOG_ERR,     text, xml)
 258 #  define crm_log_xml_warn(xml, text)    do_crm_log_xml(LOG_WARNING, text, xml)
 259 #  define crm_log_xml_notice(xml, text)  do_crm_log_xml(LOG_NOTICE,  text, xml)
 260 #  define crm_log_xml_info(xml, text)    do_crm_log_xml(LOG_INFO,    text, xml)
 261 #  define crm_log_xml_debug(xml, text)   do_crm_log_xml(LOG_DEBUG,   text, xml)
 262 #  define crm_log_xml_trace(xml, text)   do_crm_log_xml(LOG_TRACE,   text, xml)
 263 
 264 #  define crm_log_xml_explicit(xml, text)  do {                 \
 265         static struct qb_log_callsite *digest_cs = NULL;        \
 266         digest_cs = qb_log_callsite_get(                        \
 267             __func__, __FILE__, text, LOG_TRACE, __LINE__,      \
 268             crm_trace_nonlog);                                  \
 269         if (digest_cs && digest_cs->targets) {                  \
 270             do_crm_log_xml(LOG_TRACE,   text, xml);             \
 271         }                                                       \
 272     } while(0)
 273 
 274 #  define crm_str(x)    (const char*)(x?x:"<null>")
 275 
 276 #endif

/* [previous][next][first][last][top][bottom][index][help] */