From 5a0a9989e4ce64ce2b8b6a94b44446b04b62c7da Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 19 Dec 2018 12:52:08 -0800 Subject: [PATCH] ircd::log: Rename facility to level. --- include/ircd/db/database/database.h | 4 +- include/ircd/logger.h | 76 +++++----- ircd/db.cc | 98 ++++++------- ircd/js.cc | 6 +- ircd/logger.cc | 212 ++++++++++++++-------------- ircd/resource.cc | 12 +- modules/console.cc | 28 ++-- 7 files changed, 218 insertions(+), 218 deletions(-) diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index 4592a64b7..de1ed9c48 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -30,7 +30,7 @@ namespace ircd::db size_t file_count(const database &); size_t bytes(const database &); options getopt(const database &); - log::facility loglevel(const database &); + log::level loglevel(const database &); // Property information interface using prop_int = uint64_t; @@ -44,7 +44,7 @@ namespace ircd::db rocksdb::Cache *cache(database &); // Control panel - void loglevel(database &, const log::facility &); + void loglevel(database &, const log::level &); void setopt(database &, const string_view &key, const string_view &val); void fdeletions(database &, const bool &enable, const bool &force = false); uint64_t checkpoint(database &); diff --git a/include/ircd/logger.h b/include/ircd/logger.h index 2d8ca0868..bdcb73ad1 100644 --- a/include/ircd/logger.h +++ b/include/ircd/logger.h @@ -11,7 +11,7 @@ #pragma once #define HAVE_IRCD_LOGGER_H -// windows.h #define conflicts with our facility +// windows.h #define conflicts with our level #ifdef HAVE_WINDOWS_H #undef ERROR #endif @@ -24,7 +24,7 @@ namespace ircd /// Logging system namespace ircd::log { - enum facility :int; + enum level :int; struct log; struct vlog; struct logf; @@ -43,8 +43,8 @@ namespace ircd::log extern log star; // "*", '*' extern log general; // "ircd", 'G' - string_view reflect(const facility &); - facility reflect(const string_view &); + string_view reflect(const level &); + level reflect(const string_view &); // The mask is the list of named loggers to allow; an empty mask disallows // all loggers. An empty unmask allows all loggers. An unmask of a logger @@ -54,9 +54,9 @@ namespace ircd::log void console_mask(const vector_view & = {}); // This suite adjusts the output for an entire level. - bool console_enabled(const facility &); - void console_disable(const facility &); - void console_enable(const facility &); + bool console_enabled(const level &); + void console_disable(const level &); + void console_enable(const level &); void console_disable(); void console_enable(); @@ -68,7 +68,7 @@ namespace ircd::log void fini(); } -enum ircd::log::facility +enum ircd::log::level :int { CRITICAL = 0, ///< Catastrophic/unrecoverable; program is in a compromised state. @@ -96,7 +96,7 @@ struct ircd::log::log bool fmasked {true}; // currently in the file mask (enabled) public: - template void operator()(const facility &, const string_view &fmt, args&&...); + template void operator()(const level &, const string_view &fmt, args&&...); #if RB_LOG_LEVEL >= 0 template void critical(const string_view &fmt, args&&...); @@ -155,21 +155,21 @@ struct ircd::log::log struct ircd::log::vlog { - vlog(const log &log, const facility &, const string_view &fmt, const va_rtti &ap); + vlog(const log &log, const level &, const string_view &fmt, const va_rtti &ap); }; struct ircd::log::logf { template - logf(const log &log, const facility &facility, const string_view &fmt, args&&... a) + logf(const log &log, const level &level, const string_view &fmt, args&&... a) { - vlog(log, facility, fmt, va_rtti{std::forward(a)...}); + vlog(log, level, fmt, va_rtti{std::forward(a)...}); } }; struct ircd::log::mark { - mark(const facility &, const string_view &msg = {}); + mark(const level &, const string_view &msg = {}); mark(const string_view &msg = {}); }; @@ -185,13 +185,13 @@ struct ircd::log::debug template debug(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::DEBUG, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::DEBUG, fmt, va_rtti{std::forward(a)...}); } template debug(const string_view &fmt, args&&... a) { - vlog(general, facility::DEBUG, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::DEBUG, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -215,13 +215,13 @@ struct ircd::log::dwarning template dwarning(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::DWARNING, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::DWARNING, fmt, va_rtti{std::forward(a)...}); } template dwarning(const string_view &fmt, args&&... a) { - vlog(general, facility::DWARNING, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::DWARNING, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -245,13 +245,13 @@ struct ircd::log::derror template derror(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::DERROR, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::DERROR, fmt, va_rtti{std::forward(a)...}); } template derror(const string_view &fmt, args&&... a) { - vlog(general, facility::DERROR, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::DERROR, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -275,13 +275,13 @@ struct ircd::log::info template info(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::INFO, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::INFO, fmt, va_rtti{std::forward(a)...}); } template info(const string_view &fmt, args&&... a) { - vlog(general, facility::INFO, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::INFO, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -305,13 +305,13 @@ struct ircd::log::notice template notice(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::NOTICE, fmt, va_rtti{std::forward(a)...}); } template notice(const string_view &fmt, args&&... a) { - vlog(general, facility::NOTICE, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::NOTICE, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -335,13 +335,13 @@ struct ircd::log::warning template warning(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::WARNING, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::WARNING, fmt, va_rtti{std::forward(a)...}); } template warning(const string_view &fmt, args&&... a) { - vlog(general, facility::WARNING, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::WARNING, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -365,13 +365,13 @@ struct ircd::log::error template error(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::ERROR, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::ERROR, fmt, va_rtti{std::forward(a)...}); } template error(const string_view &fmt, args&&... a) { - vlog(general, facility::ERROR, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::ERROR, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -395,13 +395,13 @@ struct ircd::log::critical template critical(const log &log, const string_view &fmt, args&&... a) { - vlog(log, facility::CRITICAL, fmt, va_rtti{std::forward(a)...}); + vlog(log, level::CRITICAL, fmt, va_rtti{std::forward(a)...}); } template critical(const string_view &fmt, args&&... a) { - vlog(general, facility::CRITICAL, fmt, va_rtti{std::forward(a)...}); + vlog(general, level::CRITICAL, fmt, va_rtti{std::forward(a)...}); } }; #else @@ -425,7 +425,7 @@ void ircd::log::log::debug(const string_view &fmt, args&&... a) { - operator()(facility::DEBUG, fmt, va_rtti{std::forward(a)...}); + operator()(level::DEBUG, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -442,7 +442,7 @@ void ircd::log::log::dwarning(const string_view &fmt, args&&... a) { - operator()(facility::DWARNING, fmt, va_rtti{std::forward(a)...}); + operator()(level::DWARNING, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -459,7 +459,7 @@ void ircd::log::log::derror(const string_view &fmt, args&&... a) { - operator()(facility::DERROR, fmt, va_rtti{std::forward(a)...}); + operator()(level::DERROR, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -476,7 +476,7 @@ void ircd::log::log::info(const string_view &fmt, args&&... a) { - operator()(facility::INFO, fmt, va_rtti{std::forward(a)...}); + operator()(level::INFO, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -493,7 +493,7 @@ void ircd::log::log::notice(const string_view &fmt, args&&... a) { - operator()(facility::NOTICE, fmt, va_rtti{std::forward(a)...}); + operator()(level::NOTICE, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -510,7 +510,7 @@ void ircd::log::log::warning(const string_view &fmt, args&&... a) { - operator()(facility::WARNING, fmt, va_rtti{std::forward(a)...}); + operator()(level::WARNING, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -527,7 +527,7 @@ void ircd::log::log::error(const string_view &fmt, args&&... a) { - operator()(facility::ERROR, fmt, va_rtti{std::forward(a)...}); + operator()(level::ERROR, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -544,7 +544,7 @@ void ircd::log::log::critical(const string_view &fmt, args&&... a) { - operator()(facility::CRITICAL, fmt, va_rtti{std::forward(a)...}); + operator()(level::CRITICAL, fmt, va_rtti{std::forward(a)...}); } #else inline void @@ -557,7 +557,7 @@ ircd::log::log::critical(const string_view &fmt, template void -ircd::log::log::operator()(const facility &f, +ircd::log::log::operator()(const level &f, const string_view &fmt, args&&... a) { diff --git a/ircd/db.cc b/ircd/db.cc index fc206d308..11cabeaa9 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -552,14 +552,14 @@ ircd::db::bgcancel(database &d, property(d, rocksdb::DB::Properties::kBackgroundErrors) }; - const auto facility + const auto level { - errors? log::facility::ERROR : log::facility::DEBUG + errors? log::level::ERROR : log::level::DEBUG }; log::logf { - log, facility, + log, level, "'%s': Canceled all background work; errors:%lu", name(d), errors @@ -647,14 +647,14 @@ ircd::db::setopt(database &d, }; } -/// Set the rdb logging level by translating our ircd::log::facility to the +/// Set the rdb logging level by translating our ircd::log::level to the /// RocksDB enum. This translation is a reasonable convenience, as both /// enums are similar enough. void ircd::db::loglevel(database &d, - const ircd::log::facility &fac) + const ircd::log::level &fac) { - using ircd::log::facility; + using ircd::log::level; rocksdb::InfoLogLevel lev { @@ -663,24 +663,24 @@ ircd::db::loglevel(database &d, switch(fac) { - case facility::CRITICAL: lev = rocksdb::FATAL_LEVEL; break; - case facility::ERROR: lev = rocksdb::ERROR_LEVEL; break; - case facility::WARNING: - case facility::NOTICE: lev = rocksdb::WARN_LEVEL; break; - case facility::INFO: lev = rocksdb::INFO_LEVEL; break; - case facility::DERROR: - case facility::DWARNING: - case facility::DEBUG: lev = rocksdb::DEBUG_LEVEL; break; - case facility::_NUM_: assert(0); break; + case level::CRITICAL: lev = rocksdb::FATAL_LEVEL; break; + case level::ERROR: lev = rocksdb::ERROR_LEVEL; break; + case level::WARNING: + case level::NOTICE: lev = rocksdb::WARN_LEVEL; break; + case level::INFO: lev = rocksdb::INFO_LEVEL; break; + case level::DERROR: + case level::DWARNING: + case level::DEBUG: lev = rocksdb::DEBUG_LEVEL; break; + case level::_NUM_: assert(0); break; } d.logger->SetInfoLogLevel(lev); } -/// Set the rdb logging level by translating our ircd::log::facility to the +/// Set the rdb logging level by translating our ircd::log::level to the /// RocksDB enum. This translation is a reasonable convenience, as both /// enums are similar enough. -ircd::log::facility +ircd::log::level ircd::db::loglevel(const database &d) { const auto &level @@ -695,11 +695,11 @@ ircd::db::loglevel(const database &d) assert(0); case rocksdb::HEADER_LEVEL: - case rocksdb::FATAL_LEVEL: return log::facility::CRITICAL; - case rocksdb::ERROR_LEVEL: return log::facility::ERROR; - case rocksdb::WARN_LEVEL: return log::facility::WARNING; - case rocksdb::INFO_LEVEL: return log::facility::INFO; - case rocksdb::DEBUG_LEVEL: return log::facility::DEBUG; + case rocksdb::FATAL_LEVEL: return log::level::CRITICAL; + case rocksdb::ERROR_LEVEL: return log::level::ERROR; + case rocksdb::WARN_LEVEL: return log::level::WARNING; + case rocksdb::INFO_LEVEL: return log::level::INFO; + case rocksdb::DEBUG_LEVEL: return log::level::DEBUG; } } @@ -2049,7 +2049,7 @@ noexcept } static -ircd::log::facility +ircd::log::level translate(const rocksdb::InfoLogLevel &level) { switch(level) @@ -2057,13 +2057,13 @@ translate(const rocksdb::InfoLogLevel &level) // Treat all infomational messages from rocksdb as debug here for now. // We can clean them up and make better reports for our users eventually. default: - case rocksdb::InfoLogLevel::DEBUG_LEVEL: return ircd::log::facility::DEBUG; - case rocksdb::InfoLogLevel::INFO_LEVEL: return ircd::log::facility::DEBUG; + case rocksdb::InfoLogLevel::DEBUG_LEVEL: return ircd::log::level::DEBUG; + case rocksdb::InfoLogLevel::INFO_LEVEL: return ircd::log::level::DEBUG; - case rocksdb::InfoLogLevel::WARN_LEVEL: return ircd::log::facility::WARNING; - case rocksdb::InfoLogLevel::ERROR_LEVEL: return ircd::log::facility::ERROR; - case rocksdb::InfoLogLevel::FATAL_LEVEL: return ircd::log::facility::CRITICAL; - case rocksdb::InfoLogLevel::HEADER_LEVEL: return ircd::log::facility::NOTICE; + case rocksdb::InfoLogLevel::WARN_LEVEL: return ircd::log::level::WARNING; + case rocksdb::InfoLogLevel::ERROR_LEVEL: return ircd::log::level::ERROR; + case rocksdb::InfoLogLevel::FATAL_LEVEL: return ircd::log::level::CRITICAL; + case rocksdb::InfoLogLevel::HEADER_LEVEL: return ircd::log::level::NOTICE; } } @@ -2599,16 +2599,16 @@ ircd::db::database::events::OnCompactionCompleted(rocksdb::DB *const db, const rocksdb::CompactionJobInfo &info) noexcept { - const log::facility facility + const log::level level { info.status == rocksdb::Status::OK()? - log::facility::INFO: - log::facility::ERROR + log::level::INFO: + log::level::ERROR }; log::logf { - log, facility, + log, level, "'%s': %d compacted '%s' ctx:%lu level[in:%d out:%d] files[in:%zu out:%zu] reason:%d #%d: %s", d->name, info.job_id, @@ -2630,16 +2630,16 @@ void ircd::db::database::events::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &info) noexcept { - const log::facility facility + const log::level level { info.status == rocksdb::Status::OK()? - log::facility::DEBUG: - log::facility::ERROR + log::level::DEBUG: + log::level::ERROR }; log::logf { - log, facility, + log, level, "'%s': %d table file delete [%s][%s] #%d: %s", d->name, info.job_id, @@ -2654,16 +2654,16 @@ void ircd::db::database::events::OnTableFileCreated(const rocksdb::TableFileCreationInfo &info) noexcept { - const log::facility facility + const log::level level { info.status == rocksdb::Status::OK()? - log::facility::DEBUG: - log::facility::ERROR + log::level::DEBUG: + log::level::ERROR }; log::logf { - log, facility, + log, level, "'%s': %d table file closed [%s][%s] '%s' #%d: %s", d->name, info.job_id, @@ -2758,11 +2758,11 @@ noexcept false }; - const log::facility fac + const log::level fac { ignore? - log::facility::DERROR: - log::facility::ERROR + log::level::DERROR: + log::level::ERROR }; log::logf @@ -6313,18 +6313,18 @@ try } catch(const std::system_error &e) { - // Set the facility to downplay some errors which the user shouldn't + // Set the level to downplay some errors which the user shouldn't // be alerted to with a log message under normal operations. - const log::facility facility + const log::level level { is(e.code(), std::errc::no_such_file_or_directory)? - log::facility::DERROR: - log::facility::ERROR + log::level::DERROR: + log::level::ERROR }; log::logf { - log, facility, "'%s': opening seqfile:%p `%s' (%d) :%s", + log, level, "'%s': opening seqfile:%p `%s' (%d) :%s", d->name, this, name, diff --git a/ircd/js.cc b/ircd/js.cc index 57de3f485..df4a23775 100644 --- a/ircd/js.cc +++ b/ircd/js.cc @@ -17,7 +17,7 @@ #define IRCD_JS_FIX // This was only ever defined for the SpiderMonkey headers and some of our hacks, -// but we need to undef it to not step on the log facility log::DEBUG. +// but we need to undef it to not step on the log level log::DEBUG. // Use JS_DEBUG as an analog instead. #undef DEBUG @@ -3426,13 +3426,13 @@ ircd::js::context::handle_error(JSContext *const cx, noexcept try { assert(report); - const log::facility facility + const log::level level { JSREPORT_IS_WARNING(report->flags)? log::WARNING: log::DEBUG }; - log(facility, "context(%p): %s", + log(level, "context(%p): %s", (const void *)cx, debug(*report).c_str()); diff --git a/ircd/logger.cc b/ircd/logger.cc index 02b11d365..a6bb0a167 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -16,21 +16,21 @@ namespace ircd::log { struct confs; - extern const std::array()> default_ansi; - extern std::array()> confs; + extern const std::array()> default_ansi; + extern std::array()> confs; - std::array()> file; - std::array()> console_quiet_stdout; - std::array()> console_quiet_stderr; + std::array()> file; + std::array()> console_quiet_stdout; + std::array()> console_quiet_stderr; std::ostream &out_console{std::cout}; std::ostream &err_console{std::cerr}; static std::string dir_path(); - static std::string file_path(const facility &); + static std::string file_path(const level &); static void mkdir(); - static void open(const facility &); + static void open(const level &); } struct ircd::log::confs @@ -47,7 +47,7 @@ void ircd::log::init() { if(!ircd::debugmode) - console_disable(facility::DEBUG); + console_disable(level::DEBUG); mkdir(); } @@ -76,37 +76,37 @@ ircd::log::mkdir() void ircd::log::open() { - for_each([](const facility &fac) + for_each([](const level &lev) { - const auto &conf(confs.at(fac)); + const auto &conf(confs.at(lev)); if(!bool(conf.file_enable)) return; - if(file[fac].is_open()) - file[fac].close(); + if(file[lev].is_open()) + file[lev].close(); - file[fac].clear(); - file[fac].exceptions(std::ios::badbit | std::ios::failbit); - open(fac); + file[lev].clear(); + file[lev].exceptions(std::ios::badbit | std::ios::failbit); + open(lev); }); } void ircd::log::close() { - for_each([](const facility &fac) + for_each([](const level &lev) { - if(file[fac].is_open()) - file[fac].close(); + if(file[lev].is_open()) + file[lev].close(); }); } void ircd::log::flush() { - for_each([](const facility &fac) + for_each([](const level &lev) { - file[fac].flush(); + file[lev].flush(); }); std::flush(out_console); @@ -114,23 +114,23 @@ ircd::log::flush() } void -ircd::log::open(const facility &fac) +ircd::log::open(const level &lev) try { const auto &mode(std::ios::app); - const auto &path(file_path(fac)); - file[fac].open(path.c_str(), mode); + const auto &path(file_path(lev)); + file[lev].open(path.c_str(), mode); } catch(const std::exception &e) { fprintf(stderr, "!!! Opening log file [%s] failed: %s", - file_path(fac).c_str(), + file_path(lev).c_str(), e.what()); throw; } std::string -ircd::log::file_path(const facility &fac) +ircd::log::file_path(const level &lev) { const std::string base { @@ -139,7 +139,7 @@ ircd::log::file_path(const facility &fac) const string_view parts[] { - base, reflect(fac) + base, reflect(lev) }; return fs::make_path(parts); @@ -159,43 +159,43 @@ ircd::log::dir_path() void ircd::log::console_enable() { - for_each([](const facility &fac) + for_each([](const level &lev) { - console_enable(fac); + console_enable(lev); }); } void ircd::log::console_disable() { - for_each([](const facility &fac) + for_each([](const level &lev) { - console_disable(fac); + console_disable(lev); }); } void -ircd::log::console_enable(const facility &fac) +ircd::log::console_enable(const level &lev) { - if(console_quiet_stdout[fac]) - console_quiet_stdout[fac]--; + if(console_quiet_stdout[lev]) + console_quiet_stdout[lev]--; - if(console_quiet_stderr[fac]) - console_quiet_stderr[fac]--; + if(console_quiet_stderr[lev]) + console_quiet_stderr[lev]--; } void -ircd::log::console_disable(const facility &fac) +ircd::log::console_disable(const level &lev) { - console_quiet_stdout[fac]++; - console_quiet_stderr[fac]++; + console_quiet_stdout[lev]++; + console_quiet_stderr[lev]++; } bool -ircd::log::console_enabled(const facility &fac) +ircd::log::console_enabled(const level &lev) { - return !console_quiet_stdout[fac] || - !console_quiet_stderr[fac]; + return !console_quiet_stdout[lev] || + !console_quiet_stderr[lev]; } void @@ -235,17 +235,17 @@ ircd::log::console_quiet::~console_quiet() ircd::log::mark::mark(const string_view &msg) { - for_each([&msg] - (const auto &fac) + for_each([&msg] + (const auto &lev) { - mark(fac, msg); + mark(lev, msg); }); } -ircd::log::mark::mark(const facility &fac, +ircd::log::mark::mark(const level &lev, const string_view &msg) { - vlog(star, fac, "%s", msg); + vlog(star, lev, "%s", msg); } // @@ -346,8 +346,8 @@ ircd::log::log::log(const string_view &name, namespace ircd::log { static void check(std::ostream &) noexcept; - static void slog(const log &, const facility &, const window_buffer::closure &) noexcept; - static void vlog_threadsafe(const log &, const facility &, const string_view &fmt, const va_rtti &ap); + static void slog(const log &, const level &, const window_buffer::closure &) noexcept; + static void vlog_threadsafe(const log &, const level &, const string_view &fmt, const va_rtti &ap); } decltype(ircd::log::star) @@ -368,7 +368,7 @@ ircd::log::general /// main IRCd event loop which is running on the main thread. void ircd::log::vlog_threadsafe(const log &log, - const facility &fac, + const level &lev, const string_view &fmt, const va_rtti &ap) { @@ -380,14 +380,14 @@ ircd::log::vlog_threadsafe(const log &log, // The pointer to the logger is copied to the main thread. auto *const logp{&log}; - ircd::post([fac, str(std::move(str)), logp] + ircd::post([lev, str(std::move(str)), logp] { // If that named logger was destroyed while this closure was // travelling to the main thread then we just discard this message. if(!log::exists(logp)) return; - slog(*logp, fac, [&str](const mutable_buffer &out) -> size_t + slog(*logp, lev, [&str](const mutable_buffer &out) -> size_t { return copy(out, string_view{str}); }); @@ -395,17 +395,17 @@ ircd::log::vlog_threadsafe(const log &log, } ircd::log::vlog::vlog(const log &log, - const facility &fac, + const level &lev, const string_view &fmt, const va_rtti &ap) { if(!is_main_thread()) { - vlog_threadsafe(log, fac, fmt, ap); + vlog_threadsafe(log, lev, fmt, ap); return; } - slog(log, fac, [&fmt, &ap](const mutable_buffer &out) -> size_t + slog(log, lev, [&fmt, &ap](const mutable_buffer &out) -> size_t { return fmt::vsprintf(out, fmt, ap); }); @@ -416,17 +416,17 @@ namespace ircd::log // linkage for slog() reentrance assertion bool entered; - static bool can_skip(const log &, const facility &); + static bool can_skip(const log &, const level &); } void ircd::log::slog(const log &log, - const facility &fac, + const level &lev, const window_buffer::closure &closure) noexcept { - const auto &conf(confs.at(fac)); - if(can_skip(log, fac)) + const auto &conf(confs.at(lev)); + if(can_skip(log, lev)) return; // Have to be on the main thread to call slog(). @@ -455,7 +455,7 @@ noexcept << string_view{conf.console_ansi} << std::setw(8) << std::right - << reflect(fac) + << reflect(lev) << (string_view{conf.console_ansi}? "\033[0m " : " ") // << (log.snote? log.snote : '-') << std::setw(9) @@ -492,14 +492,14 @@ noexcept }}; // copy to std::cerr - if(log.cmasked && bool(conf.console_stderr) && !console_quiet_stderr[fac]) + if(log.cmasked && bool(conf.console_stderr) && !console_quiet_stderr[lev]) { err_console.clear(); write(err_console); } // copy to std::cout - if(log.cmasked && bool(conf.console_stdout) && !console_quiet_stdout[fac]) + if(log.cmasked && bool(conf.console_stdout) && !console_quiet_stdout[lev]) { out_console.clear(); write(out_console); @@ -508,28 +508,28 @@ noexcept } // copy to file - if(log.fmasked && file[fac].is_open()) + if(log.fmasked && file[lev].is_open()) { - file[fac].clear(); - write(file[fac]); + file[lev].clear(); + write(file[lev]); if(conf.file_flush) - std::flush(file[fac]); + std::flush(file[lev]); } } bool ircd::log::can_skip(const log &log, - const facility &fac) + const level &lev) { - const auto &conf(confs.at(fac)); + const auto &conf(confs.at(lev)); // When all of these conditions are true there is no possible log output // so we can bail real quick. - if(!file[fac].is_open() && !bool(conf.console_stdout) && !bool(conf.console_stderr)) + if(!file[lev].is_open() && !bool(conf.console_stdout) && !bool(conf.console_stderr)) return true; // Same for this set of conditions... - if((!file[fac].is_open() || !log.fmasked) && (!log.cmasked || !console_enabled(fac))) + if((!file[lev].is_open() || !log.fmasked) && (!log.cmasked || !console_enabled(lev))) return true; return false; @@ -565,43 +565,43 @@ catch(const std::exception &e) ircd::terminate(); } -ircd::log::facility +ircd::log::level ircd::log::reflect(const string_view &f) { - if(f == "CRITICAL") return facility::CRITICAL; - if(f == "ERROR") return facility::ERROR; - if(f == "DERROR") return facility::DERROR; - if(f == "DWARNING") return facility::DWARNING; - if(f == "WARNING") return facility::WARNING; - if(f == "NOTICE") return facility::NOTICE; - if(f == "INFO") return facility::INFO; - if(f == "DEBUG") return facility::DEBUG; + if(f == "CRITICAL") return level::CRITICAL; + if(f == "ERROR") return level::ERROR; + if(f == "DERROR") return level::DERROR; + if(f == "DWARNING") return level::DWARNING; + if(f == "WARNING") return level::WARNING; + if(f == "NOTICE") return level::NOTICE; + if(f == "INFO") return level::INFO; + if(f == "DEBUG") return level::DEBUG; throw ircd::error { - "'%s' is not a recognized log facility", f + "'%s' is not a recognized log level", f }; } ircd::string_view -ircd::log::reflect(const facility &f) +ircd::log::reflect(const level &f) { switch(f) { - case facility::CRITICAL: return "CRITICAL"; - case facility::ERROR: return "ERROR"; - case facility::DERROR: return "ERROR"; - case facility::WARNING: return "WARNING"; - case facility::DWARNING: return "WARNING"; - case facility::INFO: return "INFO"; - case facility::NOTICE: return "NOTICE"; - case facility::DEBUG: return "DEBUG"; - case facility::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here + case level::CRITICAL: return "CRITICAL"; + case level::ERROR: return "ERROR"; + case level::DERROR: return "ERROR"; + case level::WARNING: return "WARNING"; + case level::DWARNING: return "WARNING"; + case level::INFO: return "INFO"; + case level::NOTICE: return "NOTICE"; + case level::DEBUG: return "DEBUG"; + case level::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here }; throw assertive { - "'%d' is not a recognized log facility", int(f) + "'%d' is not a recognized log level", int(f) }; } @@ -676,8 +676,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.critical.console.ansi" }, - { "default", default_ansi.at(facility::CRITICAL) }, + { "name", "ircd.log.critical.console.ansi" }, + { "default", default_ansi.at(level::CRITICAL) }, } }, @@ -715,8 +715,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.error.console.ansi" }, - { "default", default_ansi.at(facility::ERROR) }, + { "name", "ircd.log.error.console.ansi" }, + { "default", default_ansi.at(level::ERROR) }, } }, @@ -754,8 +754,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.warning.console.ansi" }, - { "default", default_ansi.at(facility::WARNING) }, + { "name", "ircd.log.warning.console.ansi" }, + { "default", default_ansi.at(level::WARNING) }, } }, @@ -793,8 +793,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.notice.console.ansi" }, - { "default", default_ansi.at(facility::NOTICE) }, + { "name", "ircd.log.notice.console.ansi" }, + { "default", default_ansi.at(level::NOTICE) }, } }, @@ -832,8 +832,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.info.console.ansi" }, - { "default", default_ansi.at(facility::INFO) }, + { "name", "ircd.log.info.console.ansi" }, + { "default", default_ansi.at(level::INFO) }, } }, @@ -871,8 +871,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.derror.console.ansi" }, - { "default", default_ansi.at(facility::DERROR) }, + { "name", "ircd.log.derror.console.ansi" }, + { "default", default_ansi.at(level::DERROR) }, } }, @@ -910,8 +910,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.dwarning.console.ansi" }, - { "default", default_ansi.at(facility::DWARNING) }, + { "name", "ircd.log.dwarning.console.ansi" }, + { "default", default_ansi.at(level::DWARNING) }, } }, @@ -949,8 +949,8 @@ ircd::log::confs // console ansi { - { "name", "ircd.log.debug.console.ansi" }, - { "default", default_ansi.at(facility::DEBUG) }, + { "name", "ircd.log.debug.console.ansi" }, + { "default", default_ansi.at(level::DEBUG) }, } } }}; diff --git a/ircd/resource.cc b/ircd/resource.cc index ef67a61b1..163e23018 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -1100,20 +1100,20 @@ ircd::resource::response::response(client &client, }; #ifdef RB_DEBUG - const log::facility facility + const log::level level { ushort(code) >= 200 && ushort(code) < 300? - log::facility::DEBUG: + log::level::DEBUG: ushort(code) >= 300 && ushort(code) < 400? - log::facility::DWARNING: + log::level::DWARNING: ushort(code) >= 400 && ushort(code) < 500? - log::facility::DERROR: - log::facility::ERROR + log::level::DERROR: + log::level::ERROR }; log::logf { - log, facility, + log, level, "%s HTTP %d `%s' %s in %ld$us; %s content-length:%s", client.loghead(), uint(code), diff --git a/modules/console.cc b/modules/console.cc index da0da076a..8f9b48f66 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -491,13 +491,13 @@ console_cmd__log__level(opt &out, const string_view &line) if(!param.count()) { - for(int i(0); i < num_of(); ++i) + for(int i(0); i < num_of(); ++i) if(i > RB_LOG_LEVEL) - out << "[\033[1;40m-\033[0m]: " << reflect(log::facility(i)) << std::endl; - else if(console_enabled(log::facility(i))) - out << "[\033[1;42m+\033[0m]: " << reflect(log::facility(i)) << std::endl; + out << "[\033[1;40m-\033[0m]: " << reflect(log::level(i)) << std::endl; + else if(console_enabled(log::level(i))) + out << "[\033[1;42m+\033[0m]: " << reflect(log::level(i)) << std::endl; else - out << "[\033[1;41m-\033[0m]: " << reflect(log::facility(i)) << std::endl; + out << "[\033[1;41m-\033[0m]: " << reflect(log::level(i)) << std::endl; return true; } @@ -507,18 +507,18 @@ console_cmd__log__level(opt &out, const string_view &line) param.at(0) }; - for(int i(0); i < num_of(); ++i) + for(int i(0); i < num_of(); ++i) if(i > RB_LOG_LEVEL) { - out << "[\033[1;40m-\033[0m]: " << reflect(log::facility(i)) << std::endl; + out << "[\033[1;40m-\033[0m]: " << reflect(log::level(i)) << std::endl; } else if(i <= level) { - console_enable(log::facility(i)); - out << "[\033[1;42m+\033[0m]: " << reflect(log::facility(i)) << std::endl; + console_enable(log::level(i)); + out << "[\033[1;42m+\033[0m]: " << reflect(log::level(i)) << std::endl; } else { - console_disable(log::facility(i)); - out << "[\033[1;41m-\033[0m]: " << reflect(log::facility(i)) << std::endl; + console_disable(log::level(i)); + out << "[\033[1;41m-\033[0m]: " << reflect(log::level(i)) << std::endl; } return true; @@ -1541,15 +1541,15 @@ try return true; } - const log::facility &fac + const log::level &lev { log::reflect(param.at("level")) }; - loglevel(database, fac); + loglevel(database, lev); out << "set logging level of '" << name(database) << "'" - << " database to '" << reflect(fac) << "'" + << " database to '" << reflect(lev) << "'" << std::endl; return true;