mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 15:43:34 +08:00
Logger moved to header
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#include <uavcan/protocol/logger.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
const Logger::LogLevel Logger::LevelAboveAll;
|
||||
|
||||
Logger::LogLevel Logger::getExternalSinkLevel() const
|
||||
{
|
||||
return (external_sink_ == NULL) ? LevelAboveAll : external_sink_->getLogLevel();
|
||||
}
|
||||
|
||||
int Logger::init()
|
||||
{
|
||||
const int res = logmsg_pub_.init();
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
return logmsg_pub_.setPriority(TransferPriorityLow); // Fixed priority
|
||||
}
|
||||
|
||||
int Logger::log(const protocol::debug::LogMessage& message)
|
||||
{
|
||||
int retval = 0;
|
||||
if (message.level.value >= getExternalSinkLevel())
|
||||
{
|
||||
external_sink_->log(message);
|
||||
}
|
||||
if (message.level.value >= level_)
|
||||
{
|
||||
retval = logmsg_pub_.broadcast(message);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if UAVCAN_CPP_VERSION < UAVCAN_CPP11
|
||||
|
||||
int Logger::log(LogLevel level, const char* source, const char* text) UAVCAN_NOEXCEPT
|
||||
{
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
try
|
||||
#endif
|
||||
{
|
||||
if (level >= level_ || level >= getExternalSinkLevel())
|
||||
{
|
||||
msg_buf_.level.value = level;
|
||||
msg_buf_.source = source;
|
||||
msg_buf_.text = text;
|
||||
return log(msg_buf_);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
catch (...)
|
||||
{
|
||||
return -ErrFailure;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user