2** EPITECH PROJECT, 2025
11** Copyright (c) 2025 Robin Toillon
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 * @brief Logger template implementations
36 * @author Robin Toillon
37 * @details Implements the templated logging functions (debug, info,
38 * error, warning, fatal) with format string support and automatic
39 * source location capture.
44 ///////////////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////
50 template <typename... Args>
51 void safeLog(Level level, const std::source_location &loc,
52 std::format_string<Args...> fmt, Args &&...args) noexcept
55 std::string msg = std::format(fmt,
56 std::forward<Args>(args)...);
57 logImpl(level, msg, loc);
60 "LOGGER FORMAT ERROR (OOM?)", loc);
65 ///////////////////////////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////////////////////////
69 template <typename... Args>
70 void debug(LogFmt<std::type_identity_t<Args>...> wrapper,
71 Args &&...args) noexcept
73 detail::safeLog(Level::Debug, wrapper.loc, wrapper.fmt,
74 std::forward<Args>(args)...);
77 template <typename... Args>
78 void info(LogFmt<std::type_identity_t<Args>...> wrapper,
79 Args &&...args) noexcept
81 detail::safeLog(Level::Info, wrapper.loc, wrapper.fmt,
82 std::forward<Args>(args)...);
85 template <typename... Args>
86 void error(LogFmt<std::type_identity_t<Args>...> wrapper,
87 Args &&...args) noexcept
89 detail::safeLog(Level::Error, wrapper.loc, wrapper.fmt,
90 std::forward<Args>(args)...);
93 template <typename... Args>
94 void warning(LogFmt<std::type_identity_t<Args>...> wrapper,
95 Args &&...args) noexcept
97 detail::safeLog(Level::Warning, wrapper.loc, wrapper.fmt,
98 std::forward<Args>(args)...);
101 template <typename... Args>
102 void fatal(LogFmt<std::type_identity_t<Args>...> wrapper,
103 Args &&...args) noexcept
105 detail::safeLog(Level::Fatal, wrapper.loc, wrapper.fmt,
106 std::forward<Args>(args)...);