From 0d612039ed4c16c5dc0234bc243a631f6e7173b8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 29 Dec 2017 16:58:23 +0100 Subject: [PATCH] Hadrons: prettier Grid logging (non-intrusive) --- extras/Hadrons/Application.cc | 1 + extras/Hadrons/Global.cc | 15 +++++++++++++++ extras/Hadrons/Global.hpp | 2 ++ extras/Hadrons/HadronsXmlRun.cc | 6 ------ extras/Hadrons/HadronsXmlSchedule.cc | 6 ------ lib/log/Log.h | 9 ++++++++- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 6d5d6776..7ba98ade 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -42,6 +42,7 @@ using namespace Hadrons; // constructors //////////////////////////////////////////////////////////////// Application::Application(void) { + initLogger(); LOG(Message) << "Modules available:" << std::endl; auto list = ModuleFactory::getInstance().getBuilderList(); for (auto &m: list) diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index fc41424c..942a4243 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -38,6 +38,21 @@ HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); +void Hadrons::initLogger(void) +{ + auto w = std::string("Hadrons").length(); + GridLogError.setTopWidth(w); + GridLogWarning.setTopWidth(w); + GridLogMessage.setTopWidth(w); + GridLogIterative.setTopWidth(w); + GridLogDebug.setTopWidth(w); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); +} + // type utilities ////////////////////////////////////////////////////////////// constexpr unsigned int maxNameSize = 1024u; diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index c68edafd..274e1934 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -112,6 +112,8 @@ extern HadronsLogger HadronsLogMessage; extern HadronsLogger HadronsLogIterative; extern HadronsLogger HadronsLogDebug; +void initLogger(void); + // singleton pattern #define SINGLETON(name)\ public:\ diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index 07eb096e..680f234b 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -54,12 +54,6 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; // execution Application application(parameterFileName); diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc index 6b167690..55f3b231 100644 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -48,12 +48,6 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; // execution Application application; diff --git a/lib/log/Log.h b/lib/log/Log.h index ddff4c1d..011a7250 100644 --- a/lib/log/Log.h +++ b/lib/log/Log.h @@ -86,6 +86,7 @@ protected: Colours &Painter; int active; int timing_mode; + int topWidth{-1}; static int timestamp; std::string name, topName; std::string COLOUR; @@ -124,11 +125,17 @@ public: Reset(); } } + void setTopWidth(const int w) {topWidth = w;} friend std::ostream& operator<< (std::ostream& stream, Logger& log){ if ( log.active ) { - stream << log.background()<< std::left << log.topName << log.background()<< " : "; + stream << log.background()<< std::left; + if (log.topWidth > 0) + { + stream << std::setw(log.topWidth); + } + stream << log.topName << log.background()<< " : "; stream << log.colour() << std::left << log.name << log.background() << " : "; if ( log.timestamp ) { log.StopWatch->Stop();