mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-20 15:07:17 -04:00
Because `vsnprintf` return value means: " The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character. If an encoding error occurs, a negative number is returned. " `Logger` crashed when log msg was longer than LOGGER_BUFFER_SIZE. Checking `vsnprintf` return value solves this issue.
38 lines
942 B
C++
38 lines
942 B
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "log.hpp"
|
|
#include "Logger.hpp"
|
|
#include <ticks.hpp>
|
|
|
|
using Log::Logger;
|
|
|
|
int log_Printf(const char *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
const int result = Logger::get().log(Log::Device::DEFAULT, fmt, args);
|
|
va_end(args);
|
|
return result;
|
|
}
|
|
|
|
int log_Log(logger_level level, const char *file, int line, const char *function, const char *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
const int result = Logger::get().log(level, file, line, function, fmt, args);
|
|
va_end(args);
|
|
return result;
|
|
}
|
|
|
|
extern "C"
|
|
{
|
|
void bt_log_custom(const char *file, int line, const char *foo, const char *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
Logger::get().log(LOGTRACE, file, line, foo, fmt, args);
|
|
va_end(args);
|
|
}
|
|
}
|