Jetpack documentation 1.0.0
Loading...
Searching...
No Matches
Logs.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** jetpack
4** File description:
5** The Logs.hpp
6*/
13#ifndef LOGS_HPP_
14 #define LOGS_HPP_
15
16 #include <exception>
17 #include <string>
18 #include <algorithm>
19 #include <netinet/in.h>
20 #include <sys/socket.h>
21 #include <sys/types.h>
22 #include <arpa/inet.h>
23 #include <unistd.h>
24 #include <poll.h>
25 #include <filesystem>
26 #include <cstdlib>
27 #include <cstring>
28 #include <vector>
29 #include <unordered_map>
30 #include <functional>
31 #include <csignal>
32 #include <fstream>
33 #include <pwd.h>
34 #include <cmath>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <sys/ioctl.h>
38 #include <iomanip>
39 #include <iostream>
40 #include <unordered_set>
41 #include <map>
42 #include <thread>
43 #include <queue>
44 #include <mutex>
45 #include <string_view>
46
47 #define RESET "\033[0m"
48 #define BLACK "\033[0;30m"
49 #define RED "\033[0;31m"
50 #define GREEN "\033[0;32m"
51 #define YELLOW "\033[0;33m"
52 #define BLUE "\033[0;34m"
53 #define MAGENTA "\033[0;35m"
54 #define CYAN "\033[0;36m"
55 #define WHITE "\033[0;37m"
56 #define LIGHT_GREY "\033[0;37m"
57 #define DARK_GREY "\033[0;90m"
58 #define BOLD "\033[1m"
59 #define ITALIC "\033[3m"
60 #define UNDERLINE "\033[4m"
61 #define BLINK "\033[5m"
62 #define REVERSE "\033[7m"
63 #define HIDDEN "\033[8m"
64
65 #define UNUSED __attribute__((unused))
66
67namespace Jetpack::Logs {
73 class Time {
74 public:
79 static std::string getLocalTime();
80 };
81
82
83
84 extern bool debug_mode; /* Debug mode */
85
86
87
93 class Debug {
94 public:
101 Debug(const std::string file = "", const int line = 0, const std::string func = "");
105 ~Debug();
106
107
108
115 static void point(const std::string file, const int line, const std::string func);
116
117
118
124 template <typename T>
125 Debug& operator<<(const T& message) {
126 if (!debug_mode)
127 return *this;
128 std::cout << message;
129 return *this;
130 }
136 Debug& operator<<(std::ostream& (*pf)(std::ostream&));
137 };
138
139
140
146 class Error {
147 public:
154 Error(const std::string file = "", const int line = 0, const std::string func = "");
158 ~Error();
159
160
161
167 template <typename T>
168 Error& operator<<(const T& message) {
169 std::cerr << message;
170 return *this;
171 }
177 Error& operator<<(std::ostream& (*pf)(std::ostream&));
178 };
179
180
181
187 class Warning {
188 public:
195 Warning(const std::string file = "", const int line = 0, const std::string func = "");
199 ~Warning();
200
201
202
208 template <typename T>
209 Warning& operator<<(const T& message) {
210 if (!debug_mode)
211 return *this;
212 std::cerr << message;
213 return *this;
214 }
220 Warning& operator<<(std::ostream& (*pf)(std::ostream&));
221 };
222
223
224
225 /* Logs macros */
226
227 #define DEBUG Jetpack::Logs::Debug(__FILE__, __LINE__, __PRETTY_FUNCTION__)
228 #define DEBUG_CONCAT Jetpack::Logs::Debug()
229 #define POINT Jetpack::Logs::Debug::point(__FILE__, __LINE__, __PRETTY_FUNCTION__)
230 #define ERROR Jetpack::Logs::Error(__FILE__, __LINE__, __PRETTY_FUNCTION__)
231 #define WARNING Jetpack::Logs::Warning(__FILE__, __LINE__, __PRETTY_FUNCTION__)
232}
233
234#endif /* LOGS_HPP_ */
A class for debugging.
Definition Logs.hpp:93
Debug & operator<<(const T &message)
Print a debug message.
Definition Logs.hpp:125
Debug(const std::string file="", const int line=0, const std::string func="")
Constructor of the Debug.
Definition Logs.cpp:41
static void point(const std::string file, const int line, const std::string func)
Print a debug point.
Definition Logs.cpp:76
~Debug()
Destructor of the Debug.
Definition Logs.cpp:63
A class for errors.
Definition Logs.hpp:146
Error & operator<<(const T &message)
Print an error message.
Definition Logs.hpp:168
~Error()
Destructor of the Error.
Definition Logs.cpp:125
Error(const std::string file="", const int line=0, const std::string func="")
Constructor of the Error.
Definition Logs.cpp:108
A class that represents the time.
Definition Logs.hpp:73
static std::string getLocalTime()
Gets the local time.
Definition Logs.cpp:22
A class for warnings.
Definition Logs.hpp:187
Warning & operator<<(const T &message)
Print a warning message.
Definition Logs.hpp:209
~Warning()
Destructor of the Warning.
Definition Logs.cpp:166
Warning(const std::string file="", const int line=0, const std::string func="")
Constructor of the Warning.
Definition Logs.cpp:147