From 76ac576f53b9b782c7b3f8aa241bf4b7fe33d3bf Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 12 Dec 2018 08:47:13 -0800 Subject: [PATCH] ircd::log: Improve reflection related; add reverse reflection. --- include/ircd/logger.h | 5 +++-- ircd/logger.cc | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/ircd/logger.h b/include/ircd/logger.h index 6d1306682..2d8ca0868 100644 --- a/include/ircd/logger.h +++ b/include/ircd/logger.h @@ -25,8 +25,6 @@ namespace ircd namespace ircd::log { enum facility :int; - const char *reflect(const facility &); - struct log; struct vlog; struct logf; @@ -45,6 +43,9 @@ namespace ircd::log extern log star; // "*", '*' extern log general; // "ircd", 'G' + string_view reflect(const facility &); + facility 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 // that wasn't masked has no effect. Provided string_views don't have to diff --git a/ircd/logger.cc b/ircd/logger.cc index c526404ab..23221a7ab 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -562,7 +562,25 @@ catch(const std::exception &e) ircd::terminate(); } -const char * +ircd::log::facility +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; + + throw ircd::error + { + "'%s' is not a recognized log facility", f + }; +} + +ircd::string_view ircd::log::reflect(const facility &f) { switch(f) @@ -578,7 +596,10 @@ ircd::log::reflect(const facility &f) case facility::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here }; - return "??????"; + throw assertive + { + "'%d' is not a recognized log facility", int(f) + }; } const char *