aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2023-09-10 15:51:03 +0200
committerJan200101 <sentrycraft123@gmail.com>2023-09-10 15:51:03 +0200
commit35f1402ad5d7f142bb3932238422188455bbb9df (patch)
treeb41a8fbb7abcf7af09779779cd99ccb54369cc2b /src/internal
downloadSouthRPC-35f1402ad5d7f142bb3932238422188455bbb9df.tar.gz
SouthRPC-35f1402ad5d7f142bb3932238422188455bbb9df.zip
create base code
from this a lot can be branched
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/logging.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/internal/logging.h b/src/internal/logging.h
new file mode 100644
index 0000000..ad6de6b
--- /dev/null
+++ b/src/internal/logging.h
@@ -0,0 +1,45 @@
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#include <iostream>
+
+#include "plugin.h"
+#include "spdlog/sinks/base_sink.h"
+
+using spdlog_base_sink = spdlog::sinks::base_sink<std::mutex>;
+
+class PluginSink : public spdlog_base_sink
+{
+public:
+
+ PluginSink(loggerfunc_t logger): spdlog_base_sink()
+ {
+ this->ns_logger_ = logger;
+ }
+
+ void sink_it_(const spdlog::details::log_msg& in_msg) override
+ {
+ LogMsg msg{};
+ std::string payload(in_msg.payload.data(), in_msg.payload.size());
+ msg.level = (int)in_msg.level;
+ msg.msg = payload.c_str();
+ msg.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(in_msg.time.time_since_epoch()).count();
+ msg.source.file = in_msg.source.filename;
+ msg.source.func = in_msg.source.funcname;
+ msg.source.line = in_msg.source.line;
+ this->ns_logger_(&msg);
+ }
+
+ void flush_() override
+ {
+ std::cout << std::flush;
+ }
+
+protected:
+ loggerfunc_t ns_logger_;
+
+ // sink log level - default is all
+ spdlog::level_t level_{ spdlog::level::trace };
+};
+
+#endif \ No newline at end of file