config: Add 1 and update 10 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 1m33s
Build-Test-Publish / build (linux/arm64) (push) Successful in 2m45s
Build-Test-Publish / create-manifest (push) Successful in 13s

This commit is contained in:
j842
2025-08-16 13:08:05 +12:00
parent baa215e762
commit 38a3a7a478
11 changed files with 156 additions and 35 deletions

View File

@@ -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;
}
}