1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 13:25:45 +02:00

chatter: add option to remove log level prefix

Some projects use only one log level, so there is no need to repeat it
for every line.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2021-04-06 08:21:41 -04:00
parent 45afce72e3
commit 06a46e2736
2 changed files with 15 additions and 2 deletions

View File

@ -50,6 +50,7 @@ namespace crucible {
~Chatter(); ~Chatter();
static void enable_timestamp(bool prefix_timestamp); static void enable_timestamp(bool prefix_timestamp);
static void enable_level(bool prefix_level);
}; };
template <class Argument> template <class Argument>

View File

@ -18,6 +18,7 @@ namespace crucible {
static shared_ptr<set<string>> chatter_names; static shared_ptr<set<string>> chatter_names;
static const char *SPACETAB = " \t"; static const char *SPACETAB = " \t";
static bool add_prefix_timestamp = true; static bool add_prefix_timestamp = true;
static bool add_prefix_level = true;
static static
void void
@ -55,6 +56,12 @@ namespace crucible {
add_prefix_timestamp = prefix_timestamp; add_prefix_timestamp = prefix_timestamp;
} }
void
Chatter::enable_level(bool prefix_level)
{
add_prefix_level = prefix_level;
}
Chatter::~Chatter() Chatter::~Chatter()
{ {
ostringstream header_stream; ostringstream header_stream;
@ -69,12 +76,17 @@ namespace crucible {
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm)); DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm));
header_stream << buf; header_stream << buf;
header_stream << " " << getpid() << "." << crucible::gettid() << "<" << m_loglevel << ">"; header_stream << " " << getpid() << "." << crucible::gettid();
if (add_prefix_level) {
header_stream << "<" << m_loglevel << ">";
}
if (!m_name.empty()) { if (!m_name.empty()) {
header_stream << " " << m_name; header_stream << " " << m_name;
} }
} else { } else {
if (add_prefix_level) {
header_stream << "<" << m_loglevel << ">"; header_stream << "<" << m_loglevel << ">";
}
header_stream << (m_name.empty() ? "thread" : m_name); header_stream << (m_name.empty() ? "thread" : m_name);
header_stream << "[" << crucible::gettid() << "]"; header_stream << "[" << crucible::gettid() << "]";
} }