From 21eab55ffb71fd9c235c04018aaa89439cd52c3c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 10 Dec 2021 23:42:24 +0100 Subject: [PATCH] made logging cheaper --- src/main.cpp | 3 +++ src/utilities/Debug.cpp | 12 ++---------- src/windowManager.cpp | 4 ++++ src/windowManager.hpp | 1 + 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a9f2a67..5afec7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ int main(int argc, char** argv) { const int BARRET = barMainThread(); Debug::log(BARRET == 0 ? LOG : ERR, "Bar exited with code " + std::to_string(BARRET) + "!"); + g_pWindowManager->DebugOfstream.close(); return 0; } @@ -73,6 +74,8 @@ int main(int argc, char** argv) { xcb_disconnect(g_pWindowManager->DisplayConnection); + g_pWindowManager->DebugOfstream.close(); + if (const auto err = xcb_connection_has_error(g_pWindowManager->DisplayConnection); err != 0) { Debug::log(CRIT, "Exiting because of error " + std::to_string(err)); return err; diff --git a/src/utilities/Debug.cpp b/src/utilities/Debug.cpp index 3074dea..5635333 100644 --- a/src/utilities/Debug.cpp +++ b/src/utilities/Debug.cpp @@ -1,5 +1,6 @@ #include "Debug.hpp" #include +#include "../windowManager.hpp" void Debug::log(LogLevel level, std::string msg) { switch (level) @@ -26,14 +27,5 @@ void Debug::log(LogLevel level, std::string msg) { printf((msg + "\n").c_str()); // also log to a file - const char* const ENVHOME = getenv("HOME"); - - const std::string DEBUGPATH = ENVHOME + (std::string) "/.hypr.log"; - std::ofstream ofs; - - ofs.open(DEBUGPATH, std::ios::out | std::ios::app); - - ofs << msg << "\n"; - - ofs.close(); + g_pWindowManager->DebugOfstream << msg << "\n"; } \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index fa75211..5faf696 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -30,6 +30,10 @@ void CWindowManager::createAndOpenAllPipes() { system("cat \" \" > /tmp/hypr/hyprbarout"); system("cat \" \" > /tmp/hypr/hyprbarind"); system("cat \" \" > /tmp/hypr/hyprbaroutd"); + + // open the debug file + const std::string DEBUGPATH = "/tmp/hypr/hypr.log"; + DebugOfstream.open(DEBUGPATH, std::ios::out | std::ios::app); } void CWindowManager::updateRootCursor() { diff --git a/src/windowManager.hpp b/src/windowManager.hpp index deea619..0e40773 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -22,6 +22,7 @@ class CWindowManager { public: + std::ofstream DebugOfstream; xcb_connection_t* DisplayConnection = nullptr; xcb_ewmh_connection_t* EWMHConnection = nullptr; // Bar uses this xcb_screen_t* Screen = nullptr;