VLink  2.0.0
A high-performance communication middleware
logger_plugin_interface.h File Reference

Abstract contract for shared-library logger backends loaded via the VLink 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

class  vlink::LoggerPluginInterface
 Pure-virtual interface that every shared-library logger backend implements. More...
 

Namespaces

 

Detailed Description

Abstract contract for shared-library logger backends loaded via the VLink Plugin system.

A logger plugin is a shared library that exports a factory through VLINK_PLUGIN_DECLARE and embeds VLINK_PLUGIN_REGISTER inside its concrete subclass. At runtime the host application uses vlink::Plugin::load<LoggerPluginInterface> to construct an instance and forwards every log record to its log method.

Plugin contract
Hook Direction Contract
VLINK_PLUGIN_REGISTER inside the class Injects get_plugin_id() (ID = demangled name)
VLINK_PLUGIN_DECLARE translation unit Exposes the factory and the version metadata
init host -> plugin Called once after construction with the app name
log host -> plugin Called per record after passing level filters
Destructor host -> plugin Called when the host releases the plugin handle
Lifecycle
*  host                          plugin
*  ----                          ------
*  Plugin::load<...> ----------> factory creates instance
*  init(app_name)    ---------->  initialise backend
*  log(level, msg)   ---------->  forward to backend     (repeated)
*  Plugin destroy    ---------->  destroy instance
* 
Loading example
auto backend = plugin.load<vlink::LoggerPluginInterface>("my_logger_plugin", 1, 0);
if (backend) {
backend->init("my_app");
backend->log(vlink::Logger::kInfo, "Hello from plugin!");
}
Implementation example
class MyLogger : public vlink::LoggerPluginInterface {
public:
bool init(std::string_view app_name) override { return true; }
bool log(int level, std::string_view str) override { return write_to_backend(level, str); }
};
VLINK_PLUGIN_DECLARE(MyLogger, 1, 0)
#define VLINK_PLUGIN_DECLARE(ImplementType, VersionMajor, VersionMinor)
Emits the extern "C" construction and destruction entry points exported by a plugin module.
Definition: plugin.h:387
Note
level mirrors vlink::Logger::Level values. Both methods must avoid throwing across the plugin boundary; thrown exceptions there cause undefined behaviour.
See also
Plugin, Logger