From 85106bd9a9fb3be2c574df1a3aed6674e3951465 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 11 Nov 2017 14:48:34 -0500 Subject: [PATCH] chatter: use static function to control timestamping behavior Use a static function instead of embedding side-effects in the constructor of an unrelated class. Signed-off-by: Zygo Blaxell --- include/crucible/chatter.h | 7 ++----- lib/chatter.cc | 15 ++++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/crucible/chatter.h b/include/crucible/chatter.h index e42620e..f00e1e4 100644 --- a/include/crucible/chatter.h +++ b/include/crucible/chatter.h @@ -45,6 +45,8 @@ namespace crucible { template Chatter &operator<<(const T& arg); ~Chatter(); + + static void enable_timestamp(bool prefix_timestamp); }; template @@ -86,11 +88,6 @@ namespace crucible { } }; - class ChatterTimestamp { - public: - ChatterTimestamp(int); - }; - class ChatterBox { string m_file; int m_line; diff --git a/lib/chatter.cc b/lib/chatter.cc index 60dbb61..696c274 100644 --- a/lib/chatter.cc +++ b/lib/chatter.cc @@ -17,7 +17,7 @@ namespace crucible { static shared_ptr> chatter_names; static const char *SPACETAB = " \t"; - static int chatter_prefix_timestamp = 1; + static bool add_prefix_timestamp = true; static void @@ -49,11 +49,17 @@ namespace crucible { { } + void + Chatter::enable_timestamp(bool prefix_timestamp) + { + add_prefix_timestamp = prefix_timestamp; + } + Chatter::~Chatter() { ostringstream header_stream; - if (chatter_prefix_timestamp) { + if (add_prefix_timestamp) { time_t ltime; DIE_IF_MINUS_ONE(time(<ime)); struct tm ltm; @@ -97,11 +103,6 @@ namespace crucible { c.m_oss.str(""); } - ChatterTimestamp::ChatterTimestamp(int prefix_timestamp) - { - chatter_prefix_timestamp = prefix_timestamp; - } - set ChatterBox::s_boxes; set& ChatterBox::all_boxes()