Abstract interface for pluggable logger backends loaded via the Plugin system.
更多...
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
if (logger_backend) {
logger_backend->init("my_app");
}
Pure-virtual interface for a custom logger backend loaded as a dynamic plugin.
定义 logger_plugin_interface.h:90
Type-safe dynamic plugin loader with version verification and lifecycle management.
定义 plugin.h:122
std::shared_ptr< T > load(const std::string &lib_name, uint16_t version_major, uint16_t version_minor, const std::string &dir_name="", const std::deque< std::string > &search_paths=default_search_path(), const std::string &function_name=VLINK_MACRO_STRING_GET(VLINK_PLUGIN_CREATE_FUNC_NAME))
Loads a plugin implementing interface T from a shared library.
定义 plugin.h:281
- Implementing a logger plugin
public:
bool init(std::string_view app_name)
override {
return true;
}
bool log(
int level, std::string_view str)
override {
return true;
}
};
virtual bool init(std::string_view app_name)=0
Initialises the logger backend for the given application name.
virtual bool log(int level, std::string_view str)=0
Writes a single log entry to the backend.
#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