1 /* 2 * Copyright 2015-2021 the Pacemaker project contributors 3 * 4 * The version control history for this file may have further details. 5 * 6 * This source code is licensed under the GNU General Public License version 2 7 * or later (GPLv2+) WITHOUT ANY WARRANTY. 8 */ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #ifndef PCMK__LOGGING_INTERNAL_H 15 # define PCMK__LOGGING_INTERNAL_H 16 17 /*! 18 * \internal 19 * \brief Log a configuration error 20 * 21 * \param[in] fmt printf(3)-style format string 22 * \param[in] ... Arguments for format string 23 */ 24 # define pcmk__config_err(fmt...) do { \ 25 crm_config_error = TRUE; \ 26 crm_err(fmt); \ 27 } while (0) 28 29 /*! 30 * \internal 31 * \brief Log a configuration warning 32 * 33 * \param[in] fmt printf(3)-style format string 34 * \param[in] ... Arguments for format string 35 */ 36 # define pcmk__config_warn(fmt...) do { \ 37 crm_config_warning = TRUE; \ 38 crm_warn(fmt); \ 39 } while (0) 40 41 /*! 42 * \internal 43 * \brief Execute code depending on whether message would be logged 44 * 45 * This is similar to do_crm_log_unlikely() except instead of logging, it either 46 * continues past this statement or executes else_action depending on whether a 47 * message of the given severity would be logged or not. This allows whole 48 * blocks of code to be skipped if tracing or debugging is turned off. 49 * 50 * \param[in] level Severity at which to continue past this statement 51 * \param[in] else_action Code block to execute if severity would not be logged 52 * 53 * \note else_action must not contain a break or continue statement 54 */ 55 # define pcmk__log_else(level, else_action) do { \ 56 static struct qb_log_callsite *trace_cs = NULL; \ 57 \ 58 if (trace_cs == NULL) { \ 59 trace_cs = qb_log_callsite_get(__func__, __FILE__, "log_else", \ 60 level, __LINE__, 0); \ 61 } \ 62 if (!crm_is_callsite_active(trace_cs, level, 0)) { \ 63 else_action; \ 64 } \ 65 } while(0) 66 67 /*! 68 * \internal 69 * \brief Initialize logging for command line tools 70 * 71 * \param[in] name The name of the program 72 * \param[in] verbosity How verbose to be in logging 73 * 74 * \note \p verbosity is not the same as the logging level (LOG_ERR, etc.). 75 */ 76 void pcmk__cli_init_logging(const char *name, unsigned int verbosity); 77 78 int pcmk__add_logfile(const char *filename); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif