summaryrefslogtreecommitdiff
path: root/src/debug/Log.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-22 18:44:25 +0100
committerVaxry <vaxry@vaxry.net>2024-04-22 18:44:25 +0100
commit012a2802e00a7b34e47c8c1098dc093031044ce9 (patch)
treea72083d065f243a67dabbfaa704f026d501ee655 /src/debug/Log.cpp
parent741c75d907916d760163f910e65186d410e27874 (diff)
Protocols: implement protoLog
Diffstat (limited to 'src/debug/Log.cpp')
-rw-r--r--src/debug/Log.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp
index 66c430d5..32d235e1 100644
--- a/src/debug/Log.cpp
+++ b/src/debug/Log.cpp
@@ -32,3 +32,38 @@ void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) {
if (!disableStdout)
std::cout << output << "\n";
}
+
+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";
+} \ No newline at end of file