VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
logger_plugin_interface.h 文件参考

Abstract interface for pluggable logger backends loaded via the Plugin system. 更多...

#include <string_view>
#include "./plugin.h"
logger_plugin_interface.h 的引用(Include)关系图:

浏览该文件的源代码.

 Pure-virtual interface for a custom logger backend loaded as a dynamic plugin. 更多...

命名空间

详细描述

Abstract interface for pluggable logger backends loaded via the Plugin system.

LoggerPluginInterface defines the contract that every custom logger plugin must implement. A plugin is a shared library (.so / .dll) that exports a factory function registered via the VLINK_PLUGIN_REGISTER macro and compiled with VLINK_PLUGIN_DECLARE.

Plugin registration
Each implementing class must embed VLINK_PLUGIN_REGISTER(LoggerPluginInterface) and provide a corresponding VLINK_PLUGIN_DECLARE in its translation unit so the Plugin loader can create and destroy instances dynamically.
Loading a logger plugin
auto logger_backend = plugin.load<vlink::LoggerPluginInterface>("my_logger_plugin.so");
if (logger_backend) {
logger_backend->init("my_app");
logger_backend->log(vlink::Logger::kInfo, "Hello from plugin!");
}
Implementing a logger plugin
class MyLogger : public vlink::LoggerPluginInterface {
public:
bool init(std::string_view app_name) override {
// initialise your logging backend
return true;
}
bool log(int level, std::string_view str) override {
// forward to your backend
return true;
}
};
#define VLINK_PLUGIN_DECLARE(ImplementType, VersionMajor, VersionMinor)
Declares a plugin creation and destruction interface.
定义 plugin.h:380
注解
  • The level parameter passed to log() corresponds to vlink::Logger::Level values.
  • Both methods should be implemented to be non-throwing; exceptions escaping a plugin boundary may cause undefined behaviour.
参见
Plugin, Logger