/* * utility_seriallogger.hpp * * Created on: Apr 1, 2021 * Author: erki */ #ifndef SKULLC_UTILITY_SERIALLOGGER_HPP_ #define SKULLC_UTILITY_SERIALLOGGER_HPP_ #include #include #include #include "utility_ilogger.hpp" namespace Utility { template class SerialLogger : public ILogger { public: using serial_interface = T; SerialLogger() = delete; explicit SerialLogger(const serial_interface& serial) : serial_(serial) {} void log(const char* format, ...) override { std::va_list args; va_start(args, format); const std::int32_t len = vsnprintf(buffer_.data(), buffer_.size(), format, args); if (len > 0) serial_.transmit(reinterpret_cast(buffer_.data()), len); va_end(args); } private: serial_interface serial_; std::array buffer_; }; }// namespace Utility #endif /* SKULLC_UTILITY_SERIALLOGGER_HPP_ */