summaryrefslogtreecommitdiff
path: root/src/debug/Log.cpp
blob: 65ba67c4f2caf7d93a30e7a0b2fc6cb327c7d4f6 (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
36
37
38
39
40
41
#include "Log.hpp"
#include "../defines.hpp"

#include <fstream>

void Debug::log(LogLevel level, const char* fmt, ...) {
    va_list args;
    va_start(args, fmt);

    // log to a file
    const std::string DEBUGPATH = ISDEBUG ? "/tmp/hypr/hyprlandd.log" : "/tmp/hypr/hyprland.log";
    std::ofstream ofs;
    ofs.open(DEBUGPATH, std::ios::out | std::ios::app);

    switch (level) {
        case LOG:
            ofs << "[LOG] ";
            break;
        case WARN:
            ofs << "[WARN] ";
            break;
        case ERR:
            ofs << "[ERR] ";
            break;
        case CRIT:
            ofs << "[CRITICAL] ";
            break;
        default:
            break;
    }

    char buf[LOGMESSAGESIZE] = "";

    vsprintf(buf, fmt, args);

    ofs << buf << "\n";

    ofs.close();

    va_end(args);
}