VLink  2.3.0
A high-performance communication middleware
logger_plugin_interface.h 文件参考

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

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

浏览源代码.

类

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

命名空间

 

详细描述

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 records accepted by the Logger file-channel level 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
flush host -> plugin Drains records accepted before the call
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)
*  flush()            ---------->  drain accepted records
*  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!");
backend->flush();
}
Implementation example
class MyLogger : public vlink::LoggerPluginInterface {
public:
bool init(std::string_view app_name) noexcept override { return true; }
bool log(int level, std::string_view str) noexcept override { return write_to_backend(level, str); }
void flush() noexcept override { flush_backend(); }
};
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:406
注解
level mirrors vlink::Logger::Level values. All hooks are non-throwing plugin boundaries.
参见
Plugin, Logger