log/level: move level_width query into level unit

This commit is contained in:
Danny Robson 2020-04-21 10:54:10 +10:00
parent b8d0d50c6a
commit 78608c2a61
3 changed files with 34 additions and 31 deletions

View File

@ -136,3 +136,34 @@ cruft::log::log_level (void)
return s_log_level_value;
}
///////////////////////////////////////////////////////////////////////////////
std::size_t
cruft::log::level_width (void)
{
static constexpr
cruft::log::level_t
ALL_LEVELS[] = {
cruft::log::EMERGENCY,
cruft::log::ALERT,
cruft::log::CRITICAL,
cruft::log::ERROR,
cruft::log::WARN,
cruft::log::NOTICE,
cruft::log::INFO,
cruft::log::DEBUG,
};
static std::size_t width = [] {
size_t hi = 0;
for (auto i: ALL_LEVELS)
hi = cruft::max (to_string (i).size (), hi);
return hi;
} ();
return width;
}

View File

@ -77,4 +77,7 @@ namespace cruft::log {
bool needs_break (level_t);
/// Calculate the maximum width, in characters, of all level names.
std::size_t level_width (void);
}

View File

@ -24,37 +24,6 @@
using cruft::log::sink::console;
///////////////////////////////////////////////////////////////////////////////
static std::size_t
level_width (void)
{
static constexpr
cruft::log::level_t
ALL_LEVELS[] = {
cruft::log::EMERGENCY,
cruft::log::ALERT,
cruft::log::CRITICAL,
cruft::log::ERROR,
cruft::log::WARN,
cruft::log::NOTICE,
cruft::log::INFO,
cruft::log::DEBUG,
};
static size_t width = [] {
size_t hi = 0;
for (auto i: ALL_LEVELS)
hi = cruft::max (to_string (i).size (), hi);
return hi;
} ();
return width;
}
///////////////////////////////////////////////////////////////////////////////
static
cruft::term::csi::graphics