Hyprland/src/debug/Log.cpp

36 lines
781 B
C++
Raw Normal View History

2022-03-16 20:50:55 +01:00
#include "Log.hpp"
#include "../defines.hpp"
2022-06-03 17:48:07 +02:00
#include "../Compositor.hpp"
2022-03-16 20:50:55 +01:00
#include <fstream>
2022-03-17 15:53:45 +01:00
#include <iostream>
2022-03-16 20:50:55 +01:00
void Debug::init(const std::string& IS) {
2022-08-26 18:02:07 +02:00
logFile = "/tmp/hypr/" + IS + (ISDEBUG ? "/hyprlandd.log" : "/hyprland.log");
}
2022-08-22 18:50:38 +02:00
void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) {
if (disableLogs && *disableLogs)
return;
if (level > wlr_log_get_verbosity())
return;
char* outputStr = nullptr;
2022-08-22 18:58:29 +02:00
std::ofstream ofs;
ofs.open(logFile, std::ios::out | std::ios::app);
vasprintf(&outputStr, fmt, args);
std::string output = std::string(outputStr);
free(outputStr);
ofs << "[wlr] " << output << "\n";
ofs.close();
2023-03-24 20:38:09 +01:00
if (!disableStdout)
std::cout << output << "\n";
2022-08-22 18:50:38 +02:00
}