From 305d6987a8904f53d885583c02e3ec68081c6ab3 Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Wed, 7 Jun 2017 13:23:52 +0300 Subject: Review fixes. --- base/logging.cpp | 25 +++++++++++-------------- base/logging.hpp | 11 +++++++---- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'base') diff --git a/base/logging.cpp b/base/logging.cpp index ae1415458b..d71ed783f7 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -9,13 +9,13 @@ #include #include +#include #include #include #include #include #include #include -#include using namespace std; @@ -43,11 +43,12 @@ bool FromString(string const & s, LogLevel & level) return true; } -vector const & GetLogLevelNames() +array const & GetLogLevelNames() { // If you're going to modify the behavior of the function, please, // check validity of LogHelper ctor. - static vector const kNames = {{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}}; + static array const kNames = { + {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}}; return kNames; } @@ -66,22 +67,18 @@ class LogHelper my::Timer m_timer; - char const * m_names[5]; - size_t m_lens[5]; + array m_names; + array m_lens; public: LogHelper() : m_threadsCount(0) { // This code highly depends on the fact that GetLogLevelNames() - // always returns the same constant vector of strings. - auto const & names = GetLogLevelNames(); - - assert(names.size() == 5); - for (size_t i = 0; i < 5; ++i) - { - m_names[i] = names[i].c_str(); - m_lens[i] = names[i].size(); - } + // always returns the same constant array of strings. + + m_names = GetLogLevelNames(); + for (size_t i = 0; i < m_lens.size(); ++i) + m_lens[i] = strlen(m_names[i]); } void WriteProlog(ostream & s, LogLevel level) diff --git a/base/logging.hpp b/base/logging.hpp index 45022db662..163041e0fb 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -4,6 +4,7 @@ #include "base/internal/message.hpp" #include "base/src_point.hpp" +#include #include #include @@ -15,12 +16,14 @@ enum LogLevel LINFO, LWARNING, LERROR, - LCRITICAL + LCRITICAL, + + NUM_LOG_LEVELS }; std::string ToString(LogLevel level); bool FromString(std::string const & s, LogLevel & level); -std::vector const & GetLogLevelNames(); +std::array const & GetLogLevelNames(); using AtomicLogLevel = std::atomic; using LogMessageFn = void (*)(LogLevel level, SrcPoint const &, std::string const &); @@ -73,7 +76,7 @@ using ::my::LCRITICAL; #define LOG(level, msg) \ do \ { \ - if (!((level) < ::my::g_LogLevel)) \ + if ((level) >= ::my::g_LogLevel) \ ::my::LogMessage(level, SRC(), ::my::impl::Message msg); \ } while (false) @@ -81,6 +84,6 @@ using ::my::LCRITICAL; #define LOG_SHORT(level, msg) \ do \ { \ - if (!((level) < ::my::g_LogLevel)) \ + if ((level) >= ::my::g_LogLevel) \ ::my::LogMessage(level, my::SrcPoint(), ::my::impl::Message msg); \ } while (false) -- cgit v1.2.3