「🏗️」 wip: added log debug function with VERBOSE mode

This commit is contained in:
KeyZox committed 2025-04-11 15:17:32 +02:00
1 parent bb841f90c8
commit b220361474
5 files changed
+46 -23

No files matched your search

+34 -12
View File
@@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
/* Updated: 2025/04/11 11:54:37 by adjoly ### ########.fr */
/* Updated: 2025/04/11 15:09:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,22 +19,44 @@
#include <string>
namespace webserv {
/**
* @brief Used to log debug message
*
* @note Only work if VERBOSE mode is active
*/
static inline void log(std::string emoji, std::string who,
std::string str) {
#ifdef VERBOSE
if (who.empty())
std::cout << "「" << emoji << "」debug: " << str << std::endl;
else
std::cout << "「" << emoji << "」debug(" << who << "): " << str
<< std::endl;
#else
(void)emoji, (void)what, (void)who, (void)str;
#endif
}
class Logger {
public:
Logger(const std::string &fileName) : _fileName(fileName) {
if (fileName.empty())
log("➕", "Logger", "filename constructor called");
if (!fileName.empty()) {
_ttyOnly = true;
else {
} else {
std::cout << "wtfff: " << _fileName << std::endl;
_file.open(fileName.c_str(), std::ios::app);
_ttyOnly = false;
}
if (!_file.is_open() && !_ttyOnly) {
_ttyOnly = true;
warn("could not open log file, going tty only");
if (!_file.is_open() && !_ttyOnly) {
_ttyOnly = true;
warn("could not open log file, going tty only");
} else
_ttyOnly = false;
}
}
Logger(const Logger &other) : _ttyOnly(other._ttyOnly) {
log("➕", "Logger", "copy constructor called");
if (!other._ttyOnly) {
_file.open(other._fileName.c_str(), std::ios::app);
if (!_file.is_open()) {
@@ -46,6 +68,7 @@ class Logger {
// Copy assignment operator
Logger &operator=(const Logger &other) {
log("➕", "Logger", "copy assignment constructor called");
if (this != &other) {
if (_file.is_open()) {
_file.close();
@@ -62,6 +85,7 @@ class Logger {
return *this;
}
~Logger(void) {
log("➖", "Logger", "destructor called");
if (_file.is_open())
_file.close();
}
@@ -90,10 +114,8 @@ class Logger {
protected:
private:
std::string printPogitMsg(const std::string &emoji,
const std::string &type,
const std::string &what,
const std::string &msg) {
std::string printPogitMsg(const std::string &emoji, const std::string &type,
const std::string &what, const std::string &msg) {
std::stringstream os;
#ifdef TTY
(void)emoji;