diff options
author | Yuri Gorshenin <y@maps.me> | 2017-06-07 13:23:52 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2017-06-07 13:38:49 +0300 |
commit | 305d6987a8904f53d885583c02e3ec68081c6ab3 (patch) | |
tree | 3263bfa20cdbccf9f80f88fed14add809c208a82 | |
parent | b422634baba22b7d412514153e039966df3d2fed (diff) |
Review fixes.
-rw-r--r-- | base/logging.cpp | 25 | ||||
-rw-r--r-- | base/logging.hpp | 11 |
2 files changed, 18 insertions, 18 deletions
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 <algorithm> #include <cassert> +#include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <mutex> #include <sstream> -#include <vector> using namespace std; @@ -43,11 +43,12 @@ bool FromString(string const & s, LogLevel & level) return true; } -vector<string> const & GetLogLevelNames() +array<char const *, NUM_LOG_LEVELS> const & GetLogLevelNames() { // If you're going to modify the behavior of the function, please, // check validity of LogHelper ctor. - static vector<string> const kNames = {{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}}; + static array<char const *, NUM_LOG_LEVELS> 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<char const *, NUM_LOG_LEVELS> m_names; + array<size_t, NUM_LOG_LEVELS> 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 <array> #include <atomic> #include <string> @@ -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<std::string> const & GetLogLevelNames(); +std::array<char const *, NUM_LOG_LEVELS> const & GetLogLevelNames(); using AtomicLogLevel = std::atomic<LogLevel>; 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) |