0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd::log: Give log::log the instance list w/ construction checks.

This commit is contained in:
Jason Volk 2018-04-23 14:48:48 -07:00
parent c30531a77e
commit ca138a4338
2 changed files with 34 additions and 6 deletions

View file

@ -67,7 +67,13 @@ enum ircd::log::facility
_NUM_
};
/// A named logger. Create an instance of this to help categorize log messages.
/// All messages sent to this logger will be prefixed with the given name.
/// Admins will use this to create masks to filter log messages. Instances
/// of this class are registered with instance_list for de-confliction and
/// iteration, so the recommended duration of this class is static.
struct ircd::log::log
:instance_list<log>
{
string_view name;
char snote;
@ -91,8 +97,7 @@ struct ircd::log::log
void debug(const char *const &fmt, ...);
#endif
log(const string_view &name, const char &snote);
log(const string_view &name);
log(const string_view &name, const char &snote = '\0');
};
struct ircd::log::vlog

View file

@ -235,16 +235,39 @@ ircd::log::mark::mark(const facility &fac,
// log
//
ircd::log::log::log(const string_view &name)
:log{name, '\0'}
{
}
/// Linkage for list of named loggers.
template<>
decltype(ircd::instance_list<ircd::log::log>::list)
ircd::instance_list<ircd::log::log>::list
{};
ircd::log::log::log(const string_view &name,
const char &snote)
:name{name}
,snote{snote}
{
for(const auto *const &other : list)
{
if(other == this)
continue;
if(other->name == name)
throw ircd::error
{
"Logger with name '%s' already exists at %p",
name,
other
};
if(snote != '\0' && other->snote == snote)
throw ircd::error
{
"Logger with snote '%c' is '%s' and already exists at %p",
snote,
name,
other
};
}
}
//