Skip to content

Commit

Permalink
will this linter ever be satisfied?
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanwm committed Jul 27, 2024
1 parent eab9410 commit 2d9d90c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions nuTens/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,60 +67,63 @@ const static spdlog::level::level_enum runtimeLogLevel = spdlog::level::off;

#endif

static std::once_flag once;
namespace ntlogging
{
static std::once_flag logLevelOnceFlag;

Check warning on line 72 in nuTens/logging.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

nuTens/logging.hpp:72:23 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'logLevelOnceFlag' is non-const and globally accessible, consider making it const

/// @brief Set up the logger at runtime, should only be invoked once the very
/// first time any of the logging macros below are called
inline void setup_logging()
{
std::call_once(once, []() {
std::call_once(logLevelOnceFlag, []() {
std::cout << ":::::::: INFO: Setting default spdlog logging level to "
<< spdlog::level::to_string_view(runtimeLogLevel).data() << " ::::::::" << std::endl;
spdlog::set_level(runtimeLogLevel);
});
}

// stop the linter being upset at me for using logging macros here, maybe it's right but I like them
// NOLINTBEGIN(*-cppcoreguidelines-macro-usage)
} // namespace ntlogging

/// @brief Trace message that will only be displayed if NT_LOG_LEVEL ==
/// NT_LOG_LEVEL_TRACE
/// @param[in] ... The message to print. This can consist of just a simple
/// string, or a format string and subsequent variables to format.
// NOLINTNEXTLINE
#define NT_TRACE(...) \
setup_logging(); \
ntlogging::setup_logging(); \
SPDLOG_TRACE(__VA_ARGS__)

/// @brief Debug message that will only be displayed if NT_LOG_LEVEL <=
/// NT_LOG_LEVEL_DEBUG
/// @param[in] ... The message to print. This can consist of just a simple
/// string, or a format string and subsequent variables to format.
// NOLINTNEXTLINE
#define NT_DEBUG(...) \
setup_logging(); \
ntlogging::setup_logging(); \
SPDLOG_DEBUG(__VA_ARGS__)

/// @brief Information message that will only be displayed if NT_LOG_LEVEL <=
/// NT_LOG_LEVEL_INFO
/// @param[in] ... The message to print. This can consist of just a simple
/// string, or a format string and subsequent variables to format.
// NOLINTNEXTLINE
#define NT_INFO(...) \
setup_logging(); \
ntlogging::setup_logging(); \
SPDLOG_INFO(__VA_ARGS__)

/// @brief Warning message that will only be displayed if NT_LOG_LEVEL <=
/// NT_LOG_LEVEL_WARNING
/// @param[in] ... The message to print. This can consist of just a simple
/// string, or a format string and subsequent variables to format.
// NOLINTNEXTLINE
#define NT_WARN(...) \
setup_logging(); \
ntlogging::setup_logging(); \
SPDLOG_WARN(__VA_ARGS__)

/// @brief Error message that will only be displayed if NT_LOG_LEVEL <=
/// NT_LOG_LEVEL_ERROR
/// @param[in] ... The message to print. This can consist of just a simple
/// string, or a format string and subsequent variables to format.
// NOLINTNEXTLINE
#define NT_ERROR(...) \
setup_logging(); \
ntlogging::setup_logging(); \
SPDLOG_ERROR(__VA_ARGS__)

// NOLINTEND(*-cppcoreguidelines-macro-usage)

1 comment on commit 2d9d90c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-tidy reports: 3 concern(s)
  • tests/test-utils.hpp:28:9: warning: [cppcoreguidelines-macro-usage]

    function-like macro 'TEST_EXPECTED' used; consider a 'constexpr' template function

    #define TEST_EXPECTED(value, expectation, varName, threshold)                                                          \
            ^
  • nuTens/logging.hpp:72:23: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 'logLevelOnceFlag' is non-const and globally accessible, consider making it const

    static std::once_flag logLevelOnceFlag;
                          ^
  • nuTens/tensors/tensor.hpp:40:5: warning: [modernize-use-using]

    use 'using' instead of 'typedef'

        typedef std::variant<int, std::string> indexType;
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        using indexType = std::variant<int, std::string>

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.