#ifndef FSFW_EXAMPLE_HOSTED_TESTFMT_H #define FSFW_EXAMPLE_HOSTED_TESTFMT_H #include #include #include #include #include #include "fsfw/ipc/MutexFactory.h" #include "fsfw/ipc/MutexGuard.h" #include "fsfw/ipc/MutexIF.h" #include "fsfw/timemanager/Clock.h" void fmtTests(); namespace sif { static std::array PRINT_BUF = {}; static MutexIF* PRINT_MUTEX = MutexFactory::instance()->createMutex(); template void flog(const char* prefix, fmt::color color, fmt::format_string fmt, T&&... args) { MutexGuard mg(PRINT_MUTEX); const auto result = fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, "{} | {}", format(fg(color), prefix), fmt::format(fmt, args...)); *result.out = '\0'; fmt::print("{}", PRINT_BUF.data()); } template void flog_t(const char* prefix, fmt::color color, fmt::format_string fmt, T&&... args) { Clock::TimeOfDay_t logTime; Clock::getDateAndTime(&logTime); flog(prefix, color, "{:02}:{:02}:{:02}.{:03} | {}", logTime.hour, logTime.minute, logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...)); } template void fdebug_t(fmt::format_string fmt, T&&... args) { flog_t("DEBUG", fmt::color::deep_sky_blue, fmt, args...); } template void fdebug(fmt::format_string fmt, T&&... args) { flog("DEBUG", fmt::color::deep_sky_blue, fmt, args...); } template void finfo_t(fmt::format_string fmt, T&&... args) { flog_t("INFO", fmt::color::forest_green, fmt, args...); } template void finfo(fmt::format_string fmt, T&&... args) { flog("INFO", fmt::color::forest_green, fmt, args...); } template void fwarning(fmt::format_string fmt, T&&... args) { flog("WARNING", fmt::color::orange_red, fmt, args...); } template void fwarning_t(fmt::format_string fmt, T&&... args) { flog_t("WARNING", fmt::color::orange_red, fmt, args...); } template void ferror(fmt::format_string fmt, T&&... args) { flog("ERROR", fmt::color::red, fmt, args...); } template void ferror_t(fmt::format_string fmt, T&&... args) { flog_t("ERROR", fmt::color::red, fmt, args...); } } #endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H