From 2bc7873489c0f4c44b81bef3336cb306297cb538 Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Fri, 27 Dec 2024 01:18:33 -0500 Subject: [PATCH 1/3] Rename LogLevel enum values to use PascalCase; prefix enum class specific values with the enum name. --- src/clp_ffi_js/constants.hpp | 22 +++++++++---------- src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp | 8 +++---- src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp | 2 +- .../ir/UnstructuredIrStreamReader.cpp | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index c49829c5..6d31385d 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -11,26 +11,26 @@ namespace clp_ffi_js { * Enum of known log levels. */ enum class LogLevel : std::uint8_t { - NONE = 0, // This isn't a valid log level. - TRACE, - DEBUG, - INFO, - WARN, - ERROR, - FATAL, - LENGTH, // This isn't a valid log level. + LogLevelNone = 0, // This isn't a valid log level. + Trace, + Debug, + Info, + Warn, + Error, + Fatal, + LogLevelLength, }; -constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::TRACE}; +constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::Trace}; /** * Strings corresponding to `LogLevel`. * * NOTE: These must be kept in sync manually. */ -constexpr std::array +constexpr std::array cLogLevelNames{ "NONE", // This isn't a valid log level. - "TRACE", + "Trace", "DEBUG", "INFO", "WARN", diff --git a/src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp b/src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp index 0bff407c..873428cd 100644 --- a/src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp +++ b/src/clp_ffi_js/ir/StructuredIrUnitHandler.cpp @@ -28,7 +28,7 @@ namespace { * Parses a string to determine the corresponding `LogLevel` enum value. * @param str * @return `LogLevel` enum corresponding to `str` if `str` matches a string in `cLogLevelNames`. - * @return `LogLevel::NONE` otherwise. + * @return `LogLevel::LogLevelNone` otherwise. */ auto parse_log_level(std::string_view str) -> LogLevel; @@ -48,7 +48,7 @@ auto parse_log_level(std::string_view str) -> LogLevel { log_level_name_upper_case ); if (it == cLogLevelNames.end()) { - return LogLevel::NONE; + return LogLevel::LogLevelNone; } return static_cast(std::distance(cLogLevelNames.begin(), it)); @@ -96,7 +96,7 @@ auto StructuredIrUnitHandler::handle_end_of_stream() -> clp::ffi::ir_stream::IRE auto StructuredIrUnitHandler::get_log_level( StructuredLogEvent::NodeIdValuePairs const& id_value_pairs ) const -> LogLevel { - LogLevel log_level{LogLevel::NONE}; + LogLevel log_level{LogLevel::LogLevelNone}; if (false == m_log_level_node_id.has_value()) { return log_level; @@ -113,7 +113,7 @@ auto StructuredIrUnitHandler::get_log_level( } else if (log_level_value.is()) { auto const& log_level_int = log_level_value.get_immutable_view(); if (log_level_int >= clp::enum_to_underlying_type(cValidLogLevelsBeginIdx) - && log_level_int < clp::enum_to_underlying_type(LogLevel::LENGTH)) + && log_level_int < clp::enum_to_underlying_type(LogLevel::LogLevelLength)) { log_level = static_cast(log_level_int); } diff --git a/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp b/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp index bd8b6400..5eaa5e71 100644 --- a/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp +++ b/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp @@ -82,7 +82,7 @@ class StructuredIrUnitHandler { // Methods /** * @param id_value_pairs - * @return `LogLevel::NONE` if `m_log_level_node_id` is unset, the node has no value, or the + * @return `LogLevel::LogLevelNone` if `m_log_level_node_id` is unset, the node has no value, or the * node's value is not an integer or string. * @return `LogLevel` from node with id `m_log_level_node_id` otherwise. */ diff --git a/src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp b/src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp index 22085e02..23309a58 100644 --- a/src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp +++ b/src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp @@ -107,7 +107,7 @@ auto UnstructuredIrStreamReader::deserialize_stream() -> size_t { auto const& logtype = message.get_logtype(); constexpr size_t cLogLevelPositionInMessages{1}; - LogLevel log_level{LogLevel::NONE}; + LogLevel log_level{LogLevel::LogLevelNone}; if (logtype.length() > cLogLevelPositionInMessages) { // NOLINTNEXTLINE(readability-qualified-auto) auto const log_level_name_it{std::find_if( From e1b401853ef66d8fb74dce14f477e11a5906a827 Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Fri, 27 Dec 2024 01:23:18 -0500 Subject: [PATCH 2/3] Fix 100-char overflow. --- src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp b/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp index 5eaa5e71..4c911703 100644 --- a/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp +++ b/src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp @@ -82,8 +82,8 @@ class StructuredIrUnitHandler { // Methods /** * @param id_value_pairs - * @return `LogLevel::LogLevelNone` if `m_log_level_node_id` is unset, the node has no value, or the - * node's value is not an integer or string. + * @return `LogLevel::LogLevelNone` if `m_log_level_node_id` is unset, the node has no value, or + * the node's value is not an integer or string. * @return `LogLevel` from node with id `m_log_level_node_id` otherwise. */ [[nodiscard]] auto get_log_level(StructuredLogEvent::NodeIdValuePairs const& id_value_pairs From f5d61aa0abb8ba53167549adf1c68f7617089a81 Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Fri, 27 Dec 2024 01:24:34 -0500 Subject: [PATCH 3/3] Reverse unintended change in cLogLevelNames. --- src/clp_ffi_js/constants.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clp_ffi_js/constants.hpp b/src/clp_ffi_js/constants.hpp index 6d31385d..b7437019 100644 --- a/src/clp_ffi_js/constants.hpp +++ b/src/clp_ffi_js/constants.hpp @@ -30,7 +30,7 @@ constexpr LogLevel cValidLogLevelsBeginIdx{LogLevel::Trace}; constexpr std::array cLogLevelNames{ "NONE", // This isn't a valid log level. - "Trace", + "TRACE", "DEBUG", "INFO", "WARN",