2 #include "phonebook.hpp"
3 #include "record_logger.hpp"
4 #include "spdlog/common.h"
5 #include "spdlog/sinks/basic_file_sink.h"
6 #include "spdlog/sinks/stdout_color_sinks.h"
9 #include <spdlog/spdlog.h>
16 using plugin_id_t = std::size_t;
21 const record_header __plugin_start_header{
24 {
"plugin_id",
typeid(plugin_id_t)},
25 {
"plugin_name",
typeid(std::string)},
42 record_logger_->log(
record{__plugin_start_header,
64 : name{std::move(name_)}
67 , gen_guid_{pb->lookup_impl<
gen_guid>()}
68 , id{gen_guid_->get()} { }
70 virtual ~plugin() =
default;
72 [[nodiscard]] std::string get_name() const noexcept {
76 void spdlogger(
const char* log_level) {
84 std::vector<spdlog::sink_ptr> sinks;
85 auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(
"logs/" + name +
".log");
86 auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
87 sinks.push_back(file_sink);
88 sinks.push_back(console_sink);
89 auto plugin_logger = std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
90 plugin_logger->set_level(spdlog::level::from_str(log_level));
91 spdlog::register_logger(plugin_logger);
97 const std::shared_ptr<record_logger> record_logger_;
98 const std::shared_ptr<gen_guid> gen_guid_;
102 #define PLUGIN_MAIN(plugin_class) \
103 extern "C" plugin* this_plugin_factory(phonebook* pb) { \
104 auto* obj = new plugin_class{#plugin_class, pb}; \
This class generates unique IDs.
Definition: record_logger.hpp:262
A service locator for ILLIXR.
Definition: phonebook.hpp:68
A dynamically-loadable plugin for Spindle.
Definition: plugin.hpp:32
virtual void stop()
A method which Spindle calls when it stops the component.
Definition: plugin.hpp:61
virtual void start()
A method which Spindle calls when it starts the component.
Definition: plugin.hpp:41
The ILLIXR logging service for structured records.
Definition: record_logger.hpp:226
This class represents a tuple of fields which get logged by record_logger.
Definition: record_logger.hpp:144
RAC_ERRNO_MSG.
Definition: data_format.hpp:15