From 06a46e2736ffb437866a1a5da64e995f49ad89cb Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 6 Apr 2021 08:21:41 -0400 Subject: [PATCH] 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 --- include/crucible/chatter.h | 1 + lib/chatter.cc | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/crucible/chatter.h b/include/crucible/chatter.h index 44d314f..b491dbf 100644 --- a/include/crucible/chatter.h +++ b/include/crucible/chatter.h @@ -50,6 +50,7 @@ namespace crucible { ~Chatter(); static void enable_timestamp(bool prefix_timestamp); + static void enable_level(bool prefix_level); }; template diff --git a/lib/chatter.cc b/lib/chatter.cc index bd86da8..efa17af 100644 --- a/lib/chatter.cc +++ b/lib/chatter.cc @@ -18,6 +18,7 @@ namespace crucible { static shared_ptr> chatter_names; static const char *SPACETAB = " \t"; static bool add_prefix_timestamp = true; + static bool add_prefix_level = true; static void @@ -55,6 +56,12 @@ namespace crucible { add_prefix_timestamp = prefix_timestamp; } + void + Chatter::enable_level(bool prefix_level) + { + add_prefix_level = prefix_level; + } + Chatter::~Chatter() { ostringstream header_stream; @@ -69,12 +76,17 @@ namespace crucible { DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", <m)); 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()) { header_stream << " " << m_name; } } else { - header_stream << "<" << m_loglevel << ">"; + if (add_prefix_level) { + header_stream << "<" << m_loglevel << ">"; + } header_stream << (m_name.empty() ? "thread" : m_name); header_stream << "[" << crucible::gettid() << "]"; }