Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** Logger.hpp, Logger declaration
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
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:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
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.
31*/
32
42#ifndef RTYPE_LOGGER_HPP_
43 #define RTYPE_LOGGER_HPP_
44
45 #include "RType/LogLevel.hpp"
46 #include "RType/Error.hpp"
47
48 #include <expected>
49 #include <format>
50 #include <source_location>
51 #include <string>
52 #include <string_view>
53 #include <type_traits>
54 #include <utility>
55
56namespace rtp::log
57{
58 template <typename... Args>
59 struct LogFmt {
60 std::format_string<Args...> fmt;
61 std::source_location loc;
62
63 consteval LogFmt(const char *s,
64 std::source_location l =
65 std::source_location::current())
66 : fmt(s), loc(l)
67 {
68 }
69
70 consteval LogFmt(std::string_view s,
71 std::source_location l =
72 std::source_location::current())
73 : fmt(s), loc(l)
74 {
75 }
76 };
77
84 [[nodiscard]]
85 auto configure(std::string_view logFilePath) noexcept
86 -> std::expected<void, rtp::Error>;
87
94 template <typename... Args>
95 void debug(LogFmt<std::type_identity_t<Args>...> fmt,
96 Args &&...args) noexcept;
97
104 template <typename... Args>
105 void info(LogFmt<std::type_identity_t<Args>...> fmt,
106 Args &&...args) noexcept;
107
114 template <typename... Args>
115 void error(LogFmt<std::type_identity_t<Args>...> fmt,
116 Args &&...args) noexcept;
117
124 template <typename... Args>
125 void warning(LogFmt<std::type_identity_t<Args>...> fmt,
126 Args &&...args) noexcept;
127
134 template <typename... Args>
135 void fatal(LogFmt<std::type_identity_t<Args>...> fmt,
136 Args &&...args) noexcept;
137
139 // Private API
141
142 namespace detail
143 {
144 void logImpl(Level level, std::string_view message,
145 const std::source_location &loc);
146 }
147}
148
149 #include "Logger.tpp"
150
151#endif /* !RTYPE_LOGGER_HPP_ */
Error handling system with categorized error codes.
Log severity levels for the logging system.
void logImpl(Level level, std::string_view message, const std::source_location &loc)
Definition Logger.cpp:137
Level
Severity levels for log messages.
Definition LogLevel.hpp:57
void fatal(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a fatal error message.
auto configure(std::string_view logFilePath) noexcept -> std::expected< void, rtp::Error >
Configure the logger using a configuration file.
Definition Logger.cpp:153
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
void info(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an informational message.
void debug(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a debug message.
consteval LogFmt(const char *s, std::source_location l=std::source_location::current())
Definition Logger.hpp:63
consteval LogFmt(std::string_view s, std::source_location l=std::source_location::current())
Definition Logger.hpp:70
std::source_location loc
Definition Logger.hpp:61
std::format_string< Args... > fmt
Definition Logger.hpp:60