mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-01 18:39:03 -05:00
Fixes and optimizations in logger: * fixed possible buffer overflow when logging logs over line buffer size; * reduced max log line length to 2048; * moved pubsetbuf before file opening; * log file stream buffer created once in logger ctor; * updatet UTs; * additional minor cleanup.
25 lines
598 B
C++
25 lines
598 B
C++
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#pragma once
|
|
|
|
#include "StringCircularBuffer.hpp"
|
|
|
|
class LoggerBuffer : public StringCircularBuffer
|
|
{
|
|
public:
|
|
explicit LoggerBuffer(size_t size) : StringCircularBuffer(size)
|
|
{}
|
|
|
|
[[nodiscard]] std::optional<std::string> get();
|
|
void put(const std::string &logMsg);
|
|
void put(std::string &&logMsg);
|
|
|
|
static constexpr auto lostBytesMessage = "bytes were lost.";
|
|
|
|
private:
|
|
void updateNumOfLostBytes();
|
|
|
|
size_t numOfLostBytes{0};
|
|
};
|