mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 16:18:47 +02:00
「🏗️」 wip: added log debug function with VERBOSE mode
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
server_names = { "localhost", "2B5.local" }
|
||||
host = "localhost"
|
||||
port = 8080
|
||||
log_file = "test.log"
|
||||
|
||||
[server.error_pages]
|
||||
404 = "not_found.html"
|
||||
|
@ -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");
|
||||
} 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;
|
||||
|
Submodule lib/tomlpp updated: d9e507093a...9926aa1530
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/11 12:12:56 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/11 14:56:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -52,12 +52,6 @@ Server::Server(std::string file_name) {
|
||||
std::map<std::string, toml::ANode *> *map;
|
||||
_table = tomlFile->getParsedFile();
|
||||
|
||||
void *val = _table->access("log_file", toml::STRING, found);
|
||||
std::string log_file = "";
|
||||
if (found == true && val != not_nullptr) {
|
||||
std::string log_file = *static_cast<std::string *>(val);
|
||||
}
|
||||
_log = new Logger(log_file);
|
||||
try {
|
||||
_table = _getServerTable();
|
||||
} catch(std::runtime_error &e) {
|
||||
@ -66,6 +60,13 @@ Server::Server(std::string file_name) {
|
||||
delete _log;
|
||||
throw e;
|
||||
}
|
||||
void *val = _table->access("log_file", toml::STRING, found);
|
||||
std::string log_file = "";
|
||||
if (found == true && val != not_nullptr) {
|
||||
std::string log_file = *static_cast<std::string *>(val);
|
||||
std::cout << log_file << std::endl;
|
||||
}
|
||||
_log = new Logger(log_file);
|
||||
|
||||
// host and port parsing
|
||||
void *host = accessValue("host", toml::STRING, _table, _log);
|
||||
|
@ -6,8 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/10 12:18:39 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/03/25 17:10:29 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/11 14:52:21 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,6 +36,6 @@ int main(int ac, char **av) {
|
||||
std::cout << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
(void)conf;
|
||||
conf->getLogger()->info("testtt");
|
||||
delete conf;
|
||||
}
|
||||
|
Reference in New Issue
Block a user