TazGraph Project v0.1.0
Loading...
Searching...
No Matches
ConsoleLogger.h
1#pragma once
2
3#include <iostream>
4#include <string>
5#include <ctime>
6
7namespace TazGraphEngine {
9 public:
10 static void log(const std::string& message) {
11 printCurrentTime();
12 std::cout << " " << message << std::endl;
13 }
14
15 static void error(const std::string& errorMessage) {
16 printCurrentTime();
17 std::cerr << " [ERROR] " << errorMessage << std::endl;
18 }
19
20 private:
21 static void printCurrentTime() {
22 std::time_t now = std::time(nullptr);
23 struct tm timeInfo;
24
25 #if defined(_WIN32) || defined(_WIN64)
26 localtime_s(&timeInfo, &now);
27 #else
28 localtime_r(&now, &timeInfo);
29 #endif
30
31 char timestamp[20]; // Sufficient space for the timestamp
32 strftime(timestamp, sizeof(timestamp), "[%Y-%m-%d %H:%M:%S]", &timeInfo);
33
34 std::cout << timestamp;
35 }
36 };
37}
Definition ConsoleLogger.h:8