From 88a15924ed7d916b981a5e1ba396f1da139d6c58 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 6 Sep 2016 16:31:29 -0700 Subject: [PATCH] ircd::log: Add console_quiet to suppress log messages to console. --- include/ircd/logger.h | 6 ++++++ ircd/logger.cc | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/ircd/logger.h b/include/ircd/logger.h index 7d6a11382..a2d5253de 100644 --- a/include/ircd/logger.h +++ b/include/ircd/logger.h @@ -99,6 +99,12 @@ void notice(const char *fmt, ...) AFP(1, 2); void info(const char *fmt, ...) AFP(1, 2); void debug(const char *fmt, ...) AFP(1, 2); +struct console_quiet +{ + console_quiet(const bool &showmsg = true); + ~console_quiet(); +}; + void flush(); void close(); void open(); diff --git a/ircd/logger.cc b/ircd/logger.cc index 51c7eabc7..79f1f33d7 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -49,6 +49,10 @@ std::array()> file_out; std::array()> console_out; std::array()> console_err; +// Suppression state (for struct console_quiet) +std::array()> quieted_out; +std::array()> quieted_err; + // Logfile name and device std::array()> fname; std::array()> file; @@ -178,6 +182,23 @@ catch(const std::exception &e) throw; } +log::console_quiet::console_quiet(const bool &showmsg) +{ + if(showmsg) + notice("Log messages are now quieted at the console"); + + std::copy(begin(console_out), end(console_out), begin(quieted_out)); + std::copy(begin(console_err), end(console_err), begin(quieted_err)); + std::fill(begin(console_out), end(console_out), false); + std::fill(begin(console_err), end(console_err), false); +} + +log::console_quiet::~console_quiet() +{ + std::copy(begin(quieted_out), end(quieted_out), begin(console_out)); + std::copy(begin(quieted_err), end(quieted_err), begin(console_err)); +} + void log::debug(const char *const fmt, ...)