Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Logging finally works
Browse files Browse the repository at this point in the history
  • Loading branch information
brian8544 committed Jun 9, 2023
1 parent cd90b08 commit 71b61b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Main.cpp
Expand Up @@ -79,12 +79,22 @@ void readSettings()
}
}

std::string getCurrentTime() {
time_t now = time(0);
struct tm timeInfo;
localtime_s(&timeInfo, &now);
char buffer[80];
strftime(buffer, sizeof(buffer), "[%d/%m/%Y %H:%M]", &timeInfo);
return buffer;
}

void log(const std::string& message) {
std::ofstream logFile(LOGGING_DIR + "system.log", std::ios::app);
std::ofstream logFile(LOGGING_DIR + "/system.log", std::ios::app);
if (logFile.is_open()) {
logFile << getCurrentTime() << " "; // Add current time before the log message
logFile << message << std::endl;
logFile.close();
std::cout << "Message logged successfully." << std::endl;
//std::cout << "Message logged successfully." << std::endl;
}
else {
std::cerr << "Unable to open log file." << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/settings-dev.conf
@@ -1,3 +1,3 @@
CASCADE_FILE_MAIN = "contrib/cascades/haarcascade_frontalface_alt2.xml"
IMAGE_DIR = "contrib/images"
LOGGING_DIR = "contrib/logs/"
LOGGING_DIR = "contrib/logs"

0 comments on commit 71b61b3

Please sign in to comment.