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