mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 06:51:08 +01:00
ircd::log: Improve reflection related; add reverse reflection.
This commit is contained in:
parent
f667b73dac
commit
76ac576f53
2 changed files with 26 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Reference in a new issue