Updated my error log functionality to go to an error.log file instead of to the console.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user