open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
server_logger.cpp
#include <iostream>
#include <string_view>
constexpr std::string_view getLogLevelName(opcua::LogLevel level) {
switch (level) {
return "trace";
return "debug";
return "info";
return "warning";
return "error";
return "fatal";
default:
return "unknown";
}
}
constexpr std::string_view getLogCategoryName(opcua::LogCategory category) {
switch (category) {
return "network";
return "channel";
return "session";
return "server";
return "client";
return "userland";
return "securitypolicy";
default:
return "unknown";
}
}
int main() {
auto logger = [](auto level, auto category, auto msg) {
std::cout << "[" << getLogLevelName(level) << "] "
<< "[" << getLogCategoryName(category) << "] " << msg << std::endl;
};
// Create server configuration and set logger
opcua::ServerConfig config(4840, {});
config.setLogger(logger);
// Construct server with config
opcua::Server server(std::move(config));
// Alternatively, set logger after construction
server.config().setLogger(logger);
server.run();
}
Server configuration.
Definition server.hpp:38
void setLogger(LogFunction func)
High-level server class.
Definition server.hpp:132
static UA_LogCategory category
static UA_LogCategory const char * msg
LogLevel
Log level.
Definition log.hpp:14
LogCategory
Log category.
Definition log.hpp:27