Files
MuditaOS/module-utils/log/LoggerBuffer.cpp
Mateusz Grzegorzek a60e27fa4b [EGD-4593] Dump logs to file on timeout
- Dump logs to file every 10 sec.
- max file size is 50 MB
  (after reaching it, no more logs will be logged),
- Add `LockGuard` with locking mechanism
  supporting IRQ and use it in `Logger`.
- Fix minor style issues in `Logger`.
- Add `mount_user_lfs_partition.py` script for mounting LFS on Linux FS
  in order to get `MuditaOS.log` file from `user` partition
2021-03-17 16:33:02 +01:00

38 lines
968 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 "LoggerBuffer.hpp"
std::pair<bool, std::string> LoggerBuffer::get()
{
auto [result, logMsg] = StringCircularBuffer::get();
if (!result) {
return {result, logMsg};
}
if (numOfLostBytes > 0) {
logMsg = std::to_string(numOfLostBytes) + " " + lostBytesMessage + "\n" + logMsg;
numOfLostBytes = 0;
}
return {true, logMsg};
}
void LoggerBuffer::put(const std::string &logMsg)
{
updateNumOfLostBytes();
StringCircularBuffer::put(logMsg);
}
void LoggerBuffer::put(std::string &&logMsg)
{
updateNumOfLostBytes();
StringCircularBuffer::put(std::move(logMsg));
}
void LoggerBuffer::updateNumOfLostBytes()
{
if (StringCircularBuffer::isFull()) {
auto [_, lostMsg] = StringCircularBuffer::get();
numOfLostBytes += lostMsg.length();
}
}