config: Add 1 and update 10 files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "config.hpp"
|
||||
#include "logger.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
@@ -11,17 +12,17 @@ namespace simple_object_storage {
|
||||
bool load_config(const std::string& config_path, ServerConfig& config) {
|
||||
try {
|
||||
if (config_path.empty()) {
|
||||
std::cerr << "Config path is empty" << std::endl;
|
||||
LOG_ERROR("Config path is empty");
|
||||
return false;
|
||||
}
|
||||
if (!std::filesystem::exists(config_path)) {
|
||||
std::cerr << "Config file does not exist: " << config_path << std::endl;
|
||||
LOG_ERROR("Config file does not exist: {}", config_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream file(config_path);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Failed to open config file: " << config_path << std::endl;
|
||||
LOG_ERROR("Failed to open config file: {}", config_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,11 +79,22 @@ bool load_config(const std::string& config_path, ServerConfig& config) {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse logging configuration
|
||||
if (j.contains("logging")) {
|
||||
const auto& logging = j["logging"];
|
||||
if (logging.contains("log_file_path")) {
|
||||
config.log_file_path = logging["log_file_path"].get<std::string>();
|
||||
}
|
||||
if (logging.contains("log_level")) {
|
||||
config.log_level = logging["log_level"].get<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
// Line number accuracy improved
|
||||
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error parsing config file: " << e.what() << std::endl;
|
||||
LOG_ERROR("Error parsing config file: {}", e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user