Skip to content

Commit

Permalink
Make our use of fmt library work with C++20
Browse files Browse the repository at this point in the history
See also fab6473
  • Loading branch information
joto committed Sep 17, 2024
1 parent 86594bf commit e23dab3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/gen/gen-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class gen_base_t

std::string context();

template <typename... ARGS>
void log_gen(ARGS... args)
template <typename... TArgs>
void log_gen(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
if (m_debug) {
log_debug(args...);
log_debug(format_str, std::forward<TArgs>(args)...);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gen/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void write_to_debug_log(params_t const &params, char const *message)
if (!get_logger().debug_enabled()) {
return;
}
log_debug(message);
log_debug("{}", message);
for (auto const &[key, value] : params) {
log_debug(" {}={}", key, to_string(value));
}
Expand Down
29 changes: 15 additions & 14 deletions src/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ enum class log_level
class logger
{
public:
template <typename S, typename... TArgs>
template <typename... TArgs>
void log(log_level with_level, char const *prefix,
fmt::text_style const &style, S const &format_str, TArgs &&...args)
fmt::text_style const &style,
fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
if (with_level < m_current_level) {
return;
Expand Down Expand Up @@ -109,37 +110,37 @@ class logger

logger &get_logger() noexcept;

template <typename S, typename... TArgs>
void log_debug(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_debug(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
get_logger().log(log_level::debug, nullptr, {}, format_str,
std::forward<TArgs>(args)...);
}

template <typename S, typename... TArgs>
void log_info(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_info(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
get_logger().log(log_level::info, nullptr, {}, format_str,
std::forward<TArgs>(args)...);
}

template <typename S, typename... TArgs>
void log_warn(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_warn(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
get_logger().log(log_level::warn, "WARNING", fg(fmt::color::red),
format_str, std::forward<TArgs>(args)...);
}

template <typename S, typename... TArgs>
void log_error(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_error(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
get_logger().log(log_level::error, "ERROR",
fmt::emphasis::bold | fg(fmt::color::red), format_str,
std::forward<TArgs>(args)...);
}

template <typename S, typename... TArgs>
void log_sql(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_sql(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
auto &logger = get_logger();
if (logger.log_sql()) {
Expand All @@ -148,8 +149,8 @@ void log_sql(S const &format_str, TArgs &&... args)
}
}

template <typename S, typename... TArgs>
void log_sql_data(S const &format_str, TArgs &&... args)
template <typename... TArgs>
void log_sql_data(fmt::format_string<TArgs...> format_str, TArgs &&...args)
{
auto &logger = get_logger();
if (logger.log_sql_data()) {
Expand Down

0 comments on commit e23dab3

Please sign in to comment.