From a2b80db1ad86834f1ba4c866c509b83b8b1aeab4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 21 May 2018 16:55:10 -0700 Subject: [PATCH] configure.ac/ircd: Add granular configure-time log level control. --- configure.ac | 46 ++++++ include/ircd/logger.h | 316 +++++++++++++++++++++++++++++++----------- 2 files changed, 280 insertions(+), 82 deletions(-) diff --git a/configure.ac b/configure.ac index 81bb96c6a..c6c9e717a 100644 --- a/configure.ac +++ b/configure.ac @@ -204,6 +204,51 @@ AC_ARG_ENABLE(optimize, AC_HELP_STRING([--enable-optimize], [Enable optimization AM_CONDITIONAL([OPTIMIZE], [[[[ "$OPTIMIZE" = "1" ]]]]) +dnl +dnl Explicit log level +dnl + +AC_MSG_CHECKING(whether to explicitly set the logging level ceiling) +AC_ARG_WITH(log-level, AC_HELP_STRING([--with-log-level[[[=INFO]]]], [Explicitly set the log level ceiling]), +[ + AC_MSG_RESULT([yes, enabling log level $withval and below]) + + level=4 + if [[ $withval = "DEBUG" ]]; then + level=7 + elif [[ $withval = "DWARNING" ]]; then + level=6 + elif [[ $withval = "DERROR" ]]; then + level=5 + elif [[ $withval = "INFO" ]]; then + level=4 + elif [[ $withval = "NOTICE" ]]; then + level=3 + elif [[ $withval = "WARNING" ]]; then + level=2 + elif [[ $withval = "ERROR" ]]; then + level=1 + elif [[ $withval = "CRITICAL" ]]; then + level=0 + elif [[ $withval = "-1" ]]; then + level=-1 + fi + + AC_SUBST(LOG_LEVEL, $level) + RB_DEFINE_UNQUOTED([LOG_LEVEL], [$level], [Log messages for user configured level and below.]) +], [ + AM_COND_IF(DEBUG, + [ + AC_MSG_RESULT([no, but debug mode enables all log levels through DEBUG]) + AC_SUBST(LOG_LEVEL, 7) + RB_DEFINE_UNQUOTED([LOG_LEVEL], [7], [Log message level default for DEBUG mode]) + ], [ + AC_MSG_RESULT([no]) + AC_SUBST(LOG_LEVEL, 4) + RB_DEFINE_UNQUOTED([LOG_LEVEL], [4], [Log message level default for release mode]) + ]) +]) + dnl dnl Profiling mode @@ -1492,6 +1537,7 @@ echo "Precompiled headers ............... $build_pch" echo "Developer debug ................... $debug" echo "Developer assert .................. $assert" echo "Optimized build ................... $optimize" +echo "Logging level ..................... $LOG_LEVEL" echo "Installing into ................... $prefix" echo echo "* Ready to build $PACKAGE_NAME" diff --git a/include/ircd/logger.h b/include/ircd/logger.h index dea72de08..b7798c6e2 100644 --- a/include/ircd/logger.h +++ b/include/ircd/logger.h @@ -95,19 +95,51 @@ struct ircd::log::log public: template void operator()(const facility &, const char *const &fmt, args&&...); + #if RB_LOG_LEVEL >= 0 template void critical(const char *const &fmt, args&&...); - template void error(const char *const &fmt, args&&...); - template void warning(const char *const &fmt, args&&...); - template void notice(const char *const &fmt, args&&...); - template void info(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 + void critical(const char *const &fmt, ...); + #endif - #ifdef RB_DEBUG + #if RB_LOG_LEVEL >= 1 + template void error(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 + void error(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 2 + template void warning(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 + void warning(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 3 + template void notice(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 + void notice(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 4 + template void info(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 + void info(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 5 template void derror(const char *const &fmt, args&&...); - template void dwarning(const char *const &fmt, args&&...); - template void debug(const char *const &fmt, args&&...); #else // Required for DCE in gcc 6.3.0 20170519 void derror(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 6 + template void dwarning(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 void dwarning(const char *const &fmt, ...); + #endif + + #if RB_LOG_LEVEL >= 7 + template void debug(const char *const &fmt, args&&...); + #else // Required for DCE in gcc 6.3.0 20170519 void debug(const char *const &fmt, ...); #endif @@ -144,7 +176,7 @@ struct ircd::log::console_quiet ~console_quiet(); }; -#ifdef RB_DEBUG +#if RB_LOG_LEVEL >= 7 struct ircd::log::debug { template @@ -174,37 +206,7 @@ struct ircd::log::debug }; #endif -struct ircd::log::info -{ - template - info(const log &log, const char *const &fmt, args&&... a) - { - vlog(log, facility::INFO, fmt, va_rtti{std::forward(a)...}); - } - - template - info(const char *const &fmt, args&&... a) - { - vlog(general, facility::INFO, fmt, va_rtti{std::forward(a)...}); - } -}; - -struct ircd::log::notice -{ - template - notice(const log &log, const char *const &fmt, args&&... a) - { - vlog(log, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); - } - - template - notice(const char *const &fmt, args&&... a) - { - vlog(general, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); - } -}; - -#ifdef RB_DEBUG +#if RB_LOG_LEVEL >= 6 struct ircd::log::dwarning { template @@ -234,22 +236,7 @@ struct ircd::log::dwarning }; #endif -struct ircd::log::warning -{ - template - warning(const log &log, const char *const &fmt, args&&... a) - { - vlog(log, facility::WARNING, fmt, va_rtti{std::forward(a)...}); - } - - template - warning(const char *const &fmt, args&&... a) - { - vlog(general, facility::WARNING, fmt, va_rtti{std::forward(a)...}); - } -}; - -#ifdef RB_DEBUG +#if RB_LOG_LEVEL >= 5 struct ircd::log::derror { template @@ -279,6 +266,97 @@ struct ircd::log::derror }; #endif +#if RB_LOG_LEVEL >= 4 +struct ircd::log::info +{ + template + info(const log &log, const char *const &fmt, args&&... a) + { + vlog(log, facility::INFO, fmt, va_rtti{std::forward(a)...}); + } + + template + info(const char *const &fmt, args&&... a) + { + vlog(general, facility::INFO, fmt, va_rtti{std::forward(a)...}); + } +}; +#else +struct ircd::log::info +{ + info(const log &, const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } + + info(const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } +}; +#endif + +#if RB_LOG_LEVEL >= 3 +struct ircd::log::notice +{ + template + notice(const log &log, const char *const &fmt, args&&... a) + { + vlog(log, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); + } + + template + notice(const char *const &fmt, args&&... a) + { + vlog(general, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); + } +}; +#else +struct ircd::log::notice +{ + notice(const log &, const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } + + notice(const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } +}; +#endif + +#if RB_LOG_LEVEL >= 2 +struct ircd::log::warning +{ + template + warning(const log &log, const char *const &fmt, args&&... a) + { + vlog(log, facility::WARNING, fmt, va_rtti{std::forward(a)...}); + } + + template + warning(const char *const &fmt, args&&... a) + { + vlog(general, facility::WARNING, fmt, va_rtti{std::forward(a)...}); + } +}; +#else +struct ircd::log::warning +{ + warning(const log &, const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } + + warning(const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } +}; +#endif + +#if RB_LOG_LEVEL >= 1 struct ircd::log::error { template @@ -293,7 +371,22 @@ struct ircd::log::error vlog(general, facility::ERROR, fmt, va_rtti{std::forward(a)...}); } }; +#else +struct ircd::log::error +{ + error(const log &, const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } + error(const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } +}; +#endif + +#if RB_LOG_LEVEL >= 0 struct ircd::log::critical { template @@ -308,8 +401,22 @@ struct ircd::log::critical vlog(general, facility::CRITICAL, fmt, va_rtti{std::forward(a)...}); } }; +#else +struct ircd::log::critical +{ + critical(const log &, const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } -#ifdef RB_DEBUG + critical(const char *const &, ...) + { + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed + } +}; +#endif + +#if RB_LOG_LEVEL >= 7 template void ircd::log::log::debug(const char *const &fmt, @@ -326,23 +433,7 @@ ircd::log::log::debug(const char *const &fmt, } #endif -template -void -ircd::log::log::info(const char *const &fmt, - args&&... a) -{ - operator()(facility::INFO, fmt, va_rtti{std::forward(a)...}); -} - -template -void -ircd::log::log::notice(const char *const &fmt, - args&&... a) -{ - operator()(facility::NOTICE, fmt, va_rtti{std::forward(a)...}); -} - -#ifdef RB_DEBUG +#if RB_LOG_LEVEL >= 6 template void ircd::log::log::dwarning(const char *const &fmt, @@ -359,15 +450,7 @@ ircd::log::log::dwarning(const char *const &fmt, } #endif -template -void -ircd::log::log::warning(const char *const &fmt, - args&&... a) -{ - operator()(facility::WARNING, fmt, va_rtti{std::forward(a)...}); -} - -#ifdef RB_DEBUG +#if RB_LOG_LEVEL >= 5 template void ircd::log::log::derror(const char *const &fmt, @@ -384,6 +467,58 @@ ircd::log::log::derror(const char *const &fmt, } #endif +#if RB_LOG_LEVEL >= 4 +template +void +ircd::log::log::info(const char *const &fmt, + args&&... a) +{ + operator()(facility::INFO, fmt, va_rtti{std::forward(a)...}); +} +#else +inline void +ircd::log::log::info(const char *const &fmt, + ...) +{ + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed +} +#endif + +#if RB_LOG_LEVEL >= 3 +template +void +ircd::log::log::notice(const char *const &fmt, + args&&... a) +{ + operator()(facility::NOTICE, fmt, va_rtti{std::forward(a)...}); +} +#else +inline void +ircd::log::log::notice(const char *const &fmt, + ...) +{ + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed +} +#endif + +#if RB_LOG_LEVEL >= 2 +template +void +ircd::log::log::warning(const char *const &fmt, + args&&... a) +{ + operator()(facility::WARNING, fmt, va_rtti{std::forward(a)...}); +} +#else +inline void +ircd::log::log::warning(const char *const &fmt, + ...) +{ + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed +} +#endif + +#if RB_LOG_LEVEL >= 1 template void ircd::log::log::error(const char *const &fmt, @@ -391,7 +526,16 @@ ircd::log::log::error(const char *const &fmt, { operator()(facility::ERROR, fmt, va_rtti{std::forward(a)...}); } +#else +inline void +ircd::log::log::error(const char *const &fmt, + ...) +{ + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed +} +#endif +#if RB_LOG_LEVEL >= 0 template void ircd::log::log::critical(const char *const &fmt, @@ -399,6 +543,14 @@ ircd::log::log::critical(const char *const &fmt, { operator()(facility::CRITICAL, fmt, va_rtti{std::forward(a)...}); } +#else +inline void +ircd::log::log::critical(const char *const &fmt, + ...) +{ + // Required in gcc 6.3.0 20170519, template param packs are not DCE'ed +} +#endif template void