ifw-core 6.0.0
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1
8#ifndef CORE_PROTOCOL_OPEN62541_LOGGING_H_
9#define CORE_PROTOCOL_OPEN62541_LOGGING_H_
10
11// System headers
12#include <iostream>
13
14// Third party libraries
15#include <fmt/format.h>
16
17#include <log4cplus/logger.h>
18#include <log4cplus/loggingmacros.h>
19#include <log4cplus/logger.h>
20
21#include <ciiLogManager.hpp>
22
23#ifdef UA_ENABLE_AMALGAMATION
24# include <open62541.h>
25#else
26# include <open62541/plugin/log.h>
27# include <open62541/config.h>
28#endif
29
31 static constexpr const char* LOGGER_NAME = "open62541";
32}
33
34static void CustomOpen62541Log(void* log_context,
35 UA_LogLevel level,
36 UA_LogCategory category,
37 const char* msg,
38 va_list args) {
39 //static log4cplus::Logger logger = log4cplus::Logger::getInstance("open62541");
40 static log4cplus::Logger logger = elt::log::CiiLogManager::GetLogger("open62541");
41
42 char buffer[1024] = {};
43 auto buffer_size = sizeof(buffer);
44 auto ret_val = vsnprintf(buffer, buffer_size, msg, args);
45 if (ret_val < 0) {
46 std::cerr << "Logging message to big for the allocated buffer\n";
47 return;
48 }
49
50 if (level == UA_LOGLEVEL_TRACE) {
51 LOG4CPLUS_TRACE(logger, buffer);
52 } else if (level == UA_LOGLEVEL_DEBUG) {
53 LOG4CPLUS_DEBUG(logger, buffer);
54 } else if (level == UA_LOGLEVEL_INFO) {
55 LOG4CPLUS_INFO(logger, buffer);
56 } else if (level == UA_LOGLEVEL_WARNING) {
57 LOG4CPLUS_WARN(logger, buffer);
58 } else if (level == UA_LOGLEVEL_ERROR) {
59 LOG4CPLUS_ERROR(logger, buffer);
60 } else if (level == UA_LOGLEVEL_FATAL) {
61 LOG4CPLUS_FATAL(logger, buffer);
62 }
63}
64
65#if ((UA_OPEN62541_VER_MAJOR * 100 + UA_OPEN62541_VER_MINOR) * 100 + UA_OPEN62541_VER_PATCH) >= 10400
66// TODO this should probably be moved to an unnamed namespace inside
67// protocol/open62541/src/open62541.cpp on the next major release (API
68// breakage)
69[[maybe_unused]] static void CustomOpen62541LogClear(UA_Logger *logContext) {}
70
71[[deprecated("use CustomOpen62541LogClear(UA_Logger*)")]]
72#endif
73[[maybe_unused]] static void CustomOpen62541LogClear(void* logContext) {}
74
75// TODO this should probably be moved to an unnamed namespace inside
76// protocol/open62541/src/open62541.cpp on the next major release (API
77// breakage)
78[[maybe_unused]] static UA_Logger CustomLogger =
79{ CustomOpen62541Log, nullptr, CustomOpen62541LogClear };
80
81#endif // CORE_PROTOCOL_OPEN62541_LOGGING_H_
taskPoll class header file.
Definition iDataChangeHandler.hpp:28