File indexing completed on 2026-08-17 09:00:18
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_REDIS_LOG_UTILS_HPP
0008 #define BOOST_REDIS_LOG_UTILS_HPP
0009
0010 #include <boost/redis/logger.hpp>
0011
0012 #include <boost/core/ignore_unused.hpp>
0013 #include <boost/system/error_code.hpp>
0014
0015 #include <cstddef>
0016 #include <string>
0017 #include <string_view>
0018 #include <type_traits>
0019
0020 namespace boost::redis::detail {
0021
0022
0023
0024 template <class T>
0025 struct log_traits {
0026
0027 static inline void log(std::string& to, std::string_view value) { to += value; }
0028 };
0029
0030
0031
0032 template <>
0033 struct log_traits<std::size_t> {
0034 static inline void log(std::string& to, std::size_t value) { to += std::to_string(value); }
0035 };
0036
0037 template <>
0038 struct log_traits<system::error_code> {
0039 static inline void log(std::string& to, system::error_code value)
0040 {
0041
0042
0043
0044 to += value.message();
0045 to += " [";
0046 to += value.to_string();
0047 to += ']';
0048 }
0049 };
0050
0051 template <class... Args>
0052 void format_log_args(std::string& to, const Args&... args)
0053 {
0054 auto dummy = {(log_traits<Args>::log(to, args), 0)...};
0055 ignore_unused(dummy);
0056 }
0057
0058
0059
0060
0061 template <class Arg0, class... Rest>
0062 void log(buffered_logger& to, logger::level lvl, const Arg0& arg0, const Rest&... arg_rest)
0063 {
0064
0065 if (to.lgr.lvl < lvl)
0066 return;
0067
0068
0069 if constexpr (sizeof...(Rest) == 0u && std::is_convertible_v<Arg0, std::string_view>) {
0070 to.lgr.fn(lvl, arg0);
0071 } else {
0072 to.buffer.clear();
0073 format_log_args(to.buffer, arg0, arg_rest...);
0074 to.lgr.fn(lvl, to.buffer);
0075 }
0076 }
0077
0078
0079 template <class... Args>
0080 void log_debug(buffered_logger& to, const Args&... args)
0081 {
0082 log(to, logger::level::debug, args...);
0083 }
0084
0085 template <class... Args>
0086 void log_info(buffered_logger& to, const Args&... args)
0087 {
0088 log(to, logger::level::info, args...);
0089 }
0090
0091 template <class... Args>
0092 void log_err(buffered_logger& to, const Args&... args)
0093 {
0094 log(to, logger::level::err, args...);
0095 }
0096
0097 }
0098
0099 #endif