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
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
void Debug::init(const std::string& IS) {
|
2024-04-28 23:25:24 +02:00
|
|
|
logFile = IS + (ISDEBUG ? "/hyprlandd.log" : "/hyprland.log");
|
2022-06-03 17:41:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-22 18:50:38 +02:00
|
|
|
void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) {
|
2023-10-15 20:19:07 +02:00
|
|
|
if (level > wlr_log_get_verbosity())
|
|
|
|
return;
|
|
|
|
|
2023-11-14 21:06:04 +01:00
|
|
|
char* outputStr = nullptr;
|
2022-08-22 18:58:29 +02:00
|
|
|
|
|
|
|
vasprintf(&outputStr, fmt, args);
|
|
|
|
|
|
|
|
std::string output = std::string(outputStr);
|
|
|
|
free(outputStr);
|
|
|
|
|
2023-11-14 21:06:04 +01:00
|
|
|
rollingLog += output + "\n";
|
2022-08-22 18:58:29 +02:00
|
|
|
|
2024-02-18 16:00:34 +01:00
|
|
|
if (!disableLogs || !**disableLogs) {
|
2023-11-14 21:06:04 +01:00
|
|
|
std::ofstream ofs;
|
|
|
|
ofs.open(logFile, std::ios::out | std::ios::app);
|
|
|
|
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
|
|
|
}
|
2024-04-22 19:44:25 +02:00
|
|
|
|
|
|
|
void Debug::log(LogLevel level, std::string str) {
|
|
|
|
if (level == TRACE && !trace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (shuttingDown)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case LOG: str = "[LOG] " + str; break;
|
|
|
|
case WARN: str = "[WARN] " + str; break;
|
|
|
|
case ERR: str = "[ERR] " + str; break;
|
|
|
|
case CRIT: str = "[CRITICAL] " + str; break;
|
|
|
|
case INFO: str = "[INFO] " + str; break;
|
|
|
|
case TRACE: str = "[TRACE] " + str; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rollingLog += str + "\n";
|
|
|
|
if (rollingLog.size() > ROLLING_LOG_SIZE)
|
|
|
|
rollingLog = rollingLog.substr(rollingLog.size() - ROLLING_LOG_SIZE);
|
|
|
|
|
|
|
|
if (!disableLogs || !**disableLogs) {
|
|
|
|
// log to a file
|
|
|
|
std::ofstream ofs;
|
|
|
|
ofs.open(logFile, std::ios::out | std::ios::app);
|
|
|
|
ofs << str << "\n";
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// log it to the stdout too.
|
|
|
|
if (!disableStdout)
|
|
|
|
std::cout << str << "\n";
|
|
|
|
}
|