VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
logger_plugin_interface.h File Reference

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

#include <string_view>
#include "./plugin.h"
Include dependency graph for logger_plugin_interface.h:

Go to the source code of this file.

Classes

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

Namespaces

Detailed Description

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.
Definition plugin.h:380
Note
  • 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.
See also
Plugin, Logger