Files
MuditaOS/module-utils/log/log.cpp
Mateusz Grzegorzek def5dbcfa9 [EGD-5908] Fix bug in Logger + add log unit test
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.
2021-03-05 09:06:39 +01:00

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);
}
}