summaryrefslogtreecommitdiff
path: root/src/debug/Log.cpp
blob: 98eeebc91a5890ffe82419708e33f5d69489b71e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Log.hpp"
#include "../defines.hpp"
#include "../Compositor.hpp"

#include <fstream>
#include <iostream>

void Debug::init(const std::string& IS) {
    logFile = "/tmp/hypr/" + IS + (ISDEBUG ? "/hyprlandd.log" : "/hyprland.log");
}

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;

    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();

    if (!disableStdout)
        std::cout << output << "\n";
}