#include "IOHelper.h" #include #include namespace loggerlib { void IOHelper::dump(const std::string& location, const std::string& content, const std::string& fileName) { std::filesystem::directory_entry directory(location); if (directory.exists()) { if (directory.is_directory()) { std::string path; if (fileName.empty()) { time_t now = time(nullptr); struct tm *timeLoc = localtime(&now); std::string timestamp = std::to_string(timeLoc->tm_year + 1900) + "_" + std::to_string(timeLoc->tm_mon + 1) + "_" + std::to_string(timeLoc->tm_mday) + "T" + std::to_string(timeLoc->tm_hour) + "_" + std::to_string(timeLoc->tm_min) + "_" + std::to_string(timeLoc->tm_sec) + "Z.json"; path = location + "/" + timestamp; } else { path = location + "/" + fileName; } std::ofstream file(path, std::ios::out | std::ios::trunc); file << content << std::endl; file.close(); } else { std::ofstream file(location, std::ios::out | std::ios::trunc); file << content << std::endl; file.close(); } directory.refresh(); } else { std::filesystem::create_directory(location); dump(location, content, fileName); } } }