summaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 20:50:55 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 20:50:55 +0100
commitde4c836e97a5798a09bcf96fbdf4cbaf29b0dc5e (patch)
treeced2f8201e49f65e2ceecac015ecc3f7f8f9e10a /src/debug
parentf9862eed939c748842c0e9369880848b654f3d5f (diff)
Initial Commit
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/Log.cpp41
-rw-r--r--src/debug/Log.hpp16
2 files changed, 57 insertions, 0 deletions
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 <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);
+}
diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp
new file mode 100644
index 00000000..7dca950f
--- /dev/null
+++ b/src/debug/Log.hpp
@@ -0,0 +1,16 @@
+#pragma once
+#include <string>
+
+#define LOGMESSAGESIZE 1024
+
+enum LogLevel {
+ NONE = -1,
+ LOG = 0,
+ WARN,
+ ERR,
+ CRIT
+};
+
+namespace Debug {
+ void log(LogLevel level, const char* fmt, ...);
+}; \ No newline at end of file