Updated my error log functionality to go to an error.log file instead of to the console.

This commit is contained in:
rapturate
2026-06-09 14:57:38 -04:00
parent 791e0778e3
commit dd34fa55ec
4 changed files with 50 additions and 6 deletions

View File

@@ -2,6 +2,8 @@
#include <iostream>
#include <fstream>
#include <ostream>
#include <chrono>
#include <iomanip>
#include <string>
#include <vector>
#include <regex>
@@ -15,7 +17,16 @@ p_logs::p_logs(std::string log_path) {
}
std::ifstream file(log_path);
if (!file.is_open()) {
std::cerr << "Error loading " << log_path << std::endl;
std::ofstream error_file("error.log", std::ios::app);
if (error_file.is_open()) {
auto now = std::chrono::system_clock::now();
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
error_file << "[" << std::put_time(std::localtime(&now_time), "%Y-%m-%d %H:%M:%S") << "] "
<< "Log file failed to load at: " << log_path << std::endl;
error_file.close();
}
return;
}