From 87b7f6c47d8eab8bfe7f126652a88939aac58a6a Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 23 Jun 2023 11:51:45 +1200 Subject: feat: Added time to log --- main.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 72ba368..f6cc6e8 100644 --- a/main.cpp +++ b/main.cpp @@ -41,8 +41,13 @@ using std::pair; using std::vector; std::ofstream yatlog; +std::time_t timeNow; +std::tm *now; +char nowString[80]; -#define log(x) yatlog << x << std::endl +#define log(x) \ + updateTime(); \ + yatlog << nowString << x << std::endl Display* dpy; Window root; @@ -87,6 +92,7 @@ int FFCF(int sID); void detectScreens(); void focusRoot(int root); void handleConfigErrs(vector cfgErrs); +void updateTime(); void configureRequest(XConfigureRequestEvent e); void mapRequest(XMapRequestEvent e); @@ -205,6 +211,12 @@ void handleConfigErrs(vector cfgErrs) } } } +void updateTime() +{ + timeNow = std::time(0); + now = std::localtime(&timeNow); + strftime(nowString, sizeof(nowString), "[%H:%M:%S] ", now); +} //Keybind commands const void exit(const CommandArg* argv) @@ -617,9 +629,13 @@ void mapRequest(XMapRequestEvent e) XWindowAttributes attr; XGetWindowAttributes(dpy, e.window, &attr); if(gotName) + { log("Mapping window: " << name.value); + } else + { log("Mapping window with unknown name (its probably mpv, mpv is annoying)"); + } log("\tWindow ID: " << e.window); Window focusedWindow; @@ -1036,11 +1052,10 @@ int main(int argc, char** argv) //Log yatlog.open(cfg.logFile, std::ios_base::app); + yatlog << "\n" << endl; //Print starting message - auto timeUnformatted = std::chrono::system_clock::now(); - std::time_t time = std::chrono::system_clock::to_time_t(timeUnformatted); - log("\nYAT STARTING: " << std::ctime(&time) << "--------------------------------------"); + log("-------- YATWM STARTING --------"); //Notifications notify_init("YATwm"); -- cgit v1.2.3