diff --git a/webserv/log/FileChannel.cpp b/webserv/log/FileChannel.cpp index 4e96d8e..a22c8e3 100644 --- a/webserv/log/FileChannel.cpp +++ b/webserv/log/FileChannel.cpp @@ -3,10 +3,11 @@ #include #include +#include #include -FileChannel::FileChannel(const std::string &filename, LogLevel logLevel) - : Channel(logLevel), filename_(filename), fileStream_(filename, std::ios::trunc) +FileChannel::FileChannel(const std::string &filename, std::ios_base::openmode mode, LogLevel logLevel) + : Channel(logLevel), filename_(filename), fileStream_(filename, mode) { if (!fileStream_.is_open()) { diff --git a/webserv/log/FileChannel.hpp b/webserv/log/FileChannel.hpp index 4e83936..bd2a8fd 100644 --- a/webserv/log/FileChannel.hpp +++ b/webserv/log/FileChannel.hpp @@ -10,7 +10,7 @@ class FileChannel : public Channel { public: - FileChannel(const std::string &filename, LogLevel logLevel = LogLevel::LOGLVL_TRACE); + FileChannel(const std::string &filename, std::ios_base::openmode mode, LogLevel logLevel = LogLevel::LOGLVL_TRACE); FileChannel(const FileChannel &other) = delete; FileChannel(const FileChannel &&other) = delete; diff --git a/webserv/log/Log.cpp b/webserv/log/Log.cpp index 840dc7c..fa3c1c1 100644 --- a/webserv/log/Log.cpp +++ b/webserv/log/Log.cpp @@ -30,7 +30,7 @@ void Log::setStdoutChannel(LogLevel logLevel) } } -void Log::setFileChannel(const std::string &filename, LogLevel logLevel) +void Log::setFileChannel(const std::string &filename, std::ios_base::openmode mode, LogLevel logLevel) { Log &log = getInstance(); if (log.channels_.contains("file")) @@ -39,7 +39,7 @@ void Log::setFileChannel(const std::string &filename, LogLevel logLevel) } try { - log.channels_.insert({"file", std::unique_ptr(new FileChannel(filename, logLevel))}); + log.channels_.insert({"file", std::unique_ptr(new FileChannel(filename, mode, logLevel))}); } catch (const std::exception &e) { diff --git a/webserv/log/Log.hpp b/webserv/log/Log.hpp index c623b80..9ae46ec 100644 --- a/webserv/log/Log.hpp +++ b/webserv/log/Log.hpp @@ -28,9 +28,9 @@ class Log Log &operator=(const Log &other) = delete; Log &&operator=(const Log &&other) = delete; - static void setFileChannel(const std::string &filename, LogLevel logLevel = LogLevel::LOGLVL_TRACE); + static void setFileChannel(const std::string &filename, std::ios_base::openmode mode = std::ios_base::app, LogLevel logLevel = LogLevel::LOGLVL_TRACE); static void setStdoutChannel(LogLevel logLevel = LogLevel::LOGLVL_TRACE); - + void log(LogLevel level, const std::string &message, const std::string &channel = "stdout", const std::map &context = {}); diff --git a/webserv/main.cpp b/webserv/main.cpp index db763c1..5b3d4a6 100644 --- a/webserv/main.cpp +++ b/webserv/main.cpp @@ -16,8 +16,9 @@ int main(int argc, char **argv) std::cerr << "Usage: " << argv[0] << " \n"; // NOLINT return 1; } - Log::setFileChannel("webserv.log", LogLevel::LOGLVL_WARN); - Log::setStdoutChannel(LogLevel::LOGLVL_TRACE); + Log::setFileChannel("webserv.log", std::ios_base::app, LogLevel::LOGLVL_TRACE); + Log::setStdoutChannel(LogLevel::LOGLVL_INFO); + LOG_INFO("\n======================\nStarting webserv...\n======================\n"); ConfigManager::getInstance().init(argv[1]); // NOLINT Server server(ConfigManager::getInstance()); server.start();