aboutsummaryrefslogtreecommitdiff
path: root/src/Log.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-13 03:03:11 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitc7740f0e3cbcd9a7233258f22e6168b1cd8853a8 (patch)
tree21292e24cb7c534d27d8a0600a033977312cfffc /src/Log.cpp
parent6099ec04bd0d98b9e75f5b55b1215c94ccf20202 (diff)
Fix add data operation not working correctly
Reminder: do not get reference to hash map value... duh Add thread-safe logging (log is in order now!). Store data immediately to database when WE add it instead of waiting for response from remote peers. TODO: Test with multiple peers (not only localhost)
Diffstat (limited to 'src/Log.cpp')
-rw-r--r--src/Log.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Log.cpp b/src/Log.cpp
new file mode 100644
index 0000000..5d77d73
--- /dev/null
+++ b/src/Log.cpp
@@ -0,0 +1,40 @@
+#include "../include/Log.hpp"
+#include <cstdarg>
+#include <mutex>
+
+static std::mutex mutexDebug;
+
+namespace odhtdb
+{
+ // TODO: Add color (if output is tty)?
+
+ void Log::debug(const char *fmt, ...)
+ {
+ std::lock_guard<std::mutex> lock(mutexDebug);
+ va_list args;
+ va_start(args, fmt);
+ fputs("Debug: ", stdout);
+ vfprintf(stdout, fmt, args);
+ va_end(args);
+ }
+
+ void Log::warn(const char *fmt, ...)
+ {
+ std::lock_guard<std::mutex> lock(mutexDebug);
+ va_list args;
+ va_start(args, fmt);
+ fputs("Warning: ", stdout);
+ vfprintf(stdout, fmt, args);
+ va_end(args);
+ }
+
+ void Log::error(const char *fmt, ...)
+ {
+ std::lock_guard<std::mutex> lock(mutexDebug);
+ va_list args;
+ va_start(args, fmt);
+ fputs("Error: ", stderr);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ }
+}