5 #ifndef UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED 6 #define UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED 10 #include <uavcan/protocol/debug/LogMessage.hpp> 15 #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) 16 # error UAVCAN_CPP_VERSION 38 virtual LogLevel
getLogLevel()
const {
return protocol::debug::LogLevel::DEBUG; }
44 virtual void log(
const protocol::debug::LogMessage& message) = 0;
67 static LogLevel
getLogLevelAboveAll() {
return (1U << protocol::debug::LogLevel::FieldTypes::value::BitLen) - 1U; }
70 enum { DefaultTxTimeoutMs = 2000 };
99 const int res = logmsg_pub_.
init(priority);
118 int log(
const protocol::debug::LogMessage& message)
121 if (message.level.value >= getExternalSinkLevel())
123 external_sink_->
log(message);
125 if (message.level.value >= level_)
174 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 176 template <
typename... Args>
179 template <
typename... Args>
180 inline int logDebug(
const char* source,
const char* format, Args...
args) UAVCAN_NOEXCEPT
182 return log(protocol::debug::LogLevel::DEBUG, source, format,
args...);
185 template <
typename... Args>
186 inline int logInfo(
const char* source,
const char* format, Args...
args) UAVCAN_NOEXCEPT
188 return log(protocol::debug::LogLevel::INFO, source, format,
args...);
191 template <
typename... Args>
192 inline int logWarning(
const char* source,
const char* format, Args...
args) UAVCAN_NOEXCEPT
194 return log(protocol::debug::LogLevel::WARNING, source, format,
args...);
197 template <
typename... Args>
198 inline int logError(
const char* source,
const char* format, Args...
args) UAVCAN_NOEXCEPT
205 int log(LogLevel level,
const char* source,
const char* text) UAVCAN_NOEXCEPT
207 #if UAVCAN_EXCEPTIONS 211 if (level >= level_ || level >= getExternalSinkLevel())
213 msg_buf_.level.value =
level;
214 msg_buf_.source = source;
215 msg_buf_.text = text;
216 return log(msg_buf_);
220 #if UAVCAN_EXCEPTIONS 228 int logDebug(
const char* source,
const char* text) UAVCAN_NOEXCEPT
230 return log(protocol::debug::LogLevel::DEBUG, source, text);
233 int logInfo(
const char* source,
const char* text) UAVCAN_NOEXCEPT
235 return log(protocol::debug::LogLevel::INFO, source, text);
238 int logWarning(
const char* source,
const char* text) UAVCAN_NOEXCEPT
240 return log(protocol::debug::LogLevel::WARNING, source, text);
243 int logError(
const char* source,
const char* text) UAVCAN_NOEXCEPT
254 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 256 template <
typename... Args>
259 #if UAVCAN_EXCEPTIONS 263 if (
level >= level_ ||
level >= getExternalSinkLevel())
265 msg_buf_.level.value =
level;
266 msg_buf_.source = source;
267 msg_buf_.text.clear();
270 return log(msg_buf_);
274 #if UAVCAN_EXCEPTIONS 286 #endif // UAVCAN_PROTOCOL_LOGGER_HPP_INCLUDED
MonotonicDuration getTxTimeout() const
void setExternalSink(ILogSink *sink)
int logDebug(const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
int logWarning(const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
ILogSink * getExternalSink() const
Publisher< protocol::debug::LogMessage > logmsg_pub_
StorageType< typename protocol::debug::LogLevel::FieldTypes::value >::Type LogLevel
int log(const protocol::debug::LogMessage &message)
MonotonicDuration getTxTimeout() const
static LogLevel getLogLevelAboveAll()
virtual LogLevel getLogLevel() const
void setTxTimeout(MonotonicDuration tx_timeout)
int logError(const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
int logInfo(const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
ILogSink * external_sink_
void setLevel(LogLevel level)
LogLevel getExternalSinkLevel() const
protocol::debug::LogMessage msg_buf_
void setTxTimeout(MonotonicDuration val)
static MonotonicDuration fromMSec(int64_t ms)
virtual void log(const protocol::debug::LogMessage &message)=0
static const TransferPriority Lowest
int init(const TransferPriority priority=TransferPriority::Lowest)
LogLevel getLevel() const
int broadcast(const DataType &message)
ILogSink::LogLevel LogLevel