From de4c836e97a5798a09bcf96fbdf4cbaf29b0dc5e Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:50:55 +0100 Subject: Initial Commit --- src/debug/Log.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/debug/Log.cpp (limited to 'src/debug/Log.cpp') diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp new file mode 100644 index 00000000..65ba67c4 --- /dev/null +++ b/src/debug/Log.cpp @@ -0,0 +1,41 @@ +#include "Log.hpp" +#include "../defines.hpp" + +#include + +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); +} -- cgit v1.2.3