mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::log: Give log::log the instance list w/ construction checks.
This commit is contained in:
parent
c30531a77e
commit
ca138a4338
2 changed files with 34 additions and 6 deletions
|
@ -67,7 +67,13 @@ enum ircd::log::facility
|
||||||
_NUM_
|
_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
|
struct ircd::log::log
|
||||||
|
:instance_list<log>
|
||||||
{
|
{
|
||||||
string_view name;
|
string_view name;
|
||||||
char snote;
|
char snote;
|
||||||
|
@ -91,8 +97,7 @@ struct ircd::log::log
|
||||||
void debug(const char *const &fmt, ...);
|
void debug(const char *const &fmt, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log(const string_view &name, const char &snote);
|
log(const string_view &name, const char &snote = '\0');
|
||||||
log(const string_view &name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::log::vlog
|
struct ircd::log::vlog
|
||||||
|
|
|
@ -235,16 +235,39 @@ ircd::log::mark::mark(const facility &fac,
|
||||||
// log
|
// log
|
||||||
//
|
//
|
||||||
|
|
||||||
ircd::log::log::log(const string_view &name)
|
/// Linkage for list of named loggers.
|
||||||
:log{name, '\0'}
|
template<>
|
||||||
{
|
decltype(ircd::instance_list<ircd::log::log>::list)
|
||||||
}
|
ircd::instance_list<ircd::log::log>::list
|
||||||
|
{};
|
||||||
|
|
||||||
ircd::log::log::log(const string_view &name,
|
ircd::log::log::log(const string_view &name,
|
||||||
const char &snote)
|
const char &snote)
|
||||||
:name{name}
|
:name{name}
|
||||||
,snote{snote}
|
,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
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue