21#include <source_location>
23#ifndef HIGHMAP_ENABLE_LOGS
24#define HIGHMAP_ENABLE_LOGS 1
27#ifndef HIGHMAP_LOG_LEVEL_WIDTH
28#define HIGHMAP_LOG_LEVEL_WIDTH 5
31#ifndef HIGHMAP_LOG_FILE_WIDTH
32#define HIGHMAP_LOG_FILE_WIDTH 24
38#if !HIGHMAP_ENABLE_LOGS
40template <
typename... Args>
inline void trace([[maybe_unused]] Args &&...args)
44template <
typename... Args>
inline void info([[maybe_unused]] Args &&...args)
48template <
typename... Args>
inline void warn([[maybe_unused]] Args &&...args)
52template <
typename... Args>
inline void error([[maybe_unused]] Args &&...args)
60 std::format_string<Args...>
fmt;
61 std::source_location
loc;
64 requires std::constructible_from<std::format_string<Args...>,
const S &>
67 const std::source_location &l = std::source_location::current())
98 const size_t pos = path.find_last_of(
"/\\");
99 return (pos == std::string_view::npos) ? path : path.substr(pos + 1);
104 if (width == 0)
return std::string(str);
105 if (str.length() > width)
107 if (width <= 3)
return std::string(str.substr(0, width));
108 return std::string(str.substr(0, width - 3)) +
"...";
110 std::string res(str);
111 res.append(width - str.length(),
' ');
116 std::string_view msg,
117 const std::source_location &loc)
122 out <<
"hmap " <<
"["
126 HIGHMAP_LOG_FILE_WIDTH)
127 <<
":" << loc.line() <<
"] " << msg << std::endl;
136template <
typename... Args>
140 std::string msg = std::vformat(fl.fmt.get(), std::make_format_args(args...));
145 std::string_view message,
146 const std::source_location &loc = std::source_location::current())
151template <
typename... Args>
152inline void trace(
const std::source_location &loc,
153 std::format_string<Args...> fmt,
156 std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
160inline void trace(
const std::source_location &loc, std::string_view message)
169template <
typename... Args>
173 std::string msg = std::vformat(fl.fmt.get(), std::make_format_args(args...));
178 std::string_view message,
179 const std::source_location &loc = std::source_location::current())
184template <
typename... Args>
185inline void info(
const std::source_location &loc,
186 std::format_string<Args...> fmt,
189 std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
193inline void info(
const std::source_location &loc, std::string_view message)
202template <
typename... Args>
206 std::string msg = std::vformat(fl.fmt.get(), std::make_format_args(args...));
211 std::string_view message,
212 const std::source_location &loc = std::source_location::current())
217template <
typename... Args>
218inline void warn(
const std::source_location &loc,
219 std::format_string<Args...> fmt,
222 std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
226inline void warn(
const std::source_location &loc, std::string_view message)
235template <
typename... Args>
239 std::string msg = std::vformat(fl.fmt.get(), std::make_format_args(args...));
244 std::string_view message,
245 const std::source_location &loc = std::source_location::current())
250template <
typename... Args>
251inline void error(
const std::source_location &loc,
252 std::format_string<Args...> fmt,
255 std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
259inline void error(
const std::source_location &loc, std::string_view message)
void log_impl(Level level, std::string_view msg, const std::source_location &loc)
Definition logger.hpp:115
std::string format_fixed_width(std::string_view str, size_t width)
Definition logger.hpp:102
constexpr std::string_view get_filename(std::string_view path)
Definition logger.hpp:96
Level
Definition logger.hpp:77
const char * level_to_string(Level level)
Definition logger.hpp:84
void info(Args &&...args)
Definition logger.hpp:44
void warn(Args &&...args)
Definition logger.hpp:48
void trace(Args &&...args)
Definition logger.hpp:40
void error(Args &&...args)
Definition logger.hpp:52