helics  3.6.1
LogBuffer.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "gmlc/libguarded/shared_guarded.hpp"
10 #include "nlohmann/json_fwd.hpp"
11 
12 #include <atomic>
13 #include <deque>
14 #include <functional>
15 #include <string>
16 #include <string_view>
17 #include <tuple>
18 
19 namespace helics {
20 
22 class LogBuffer {
23  private:
25  mBuffer{};
26  std::atomic<std::size_t> mMaxSize{0};
27 
28  public:
29  static constexpr std::size_t cDefaultBufferSize{10UL};
30  LogBuffer() = default;
31  explicit LogBuffer(std::size_t maxSize): mMaxSize(maxSize) {}
32  void resize(std::size_t newSize);
33  void enable(bool enable = true);
34  std::size_t capacity() const { return mMaxSize; }
35  std::size_t size() const { return mBuffer.lock()->size(); }
36 
37  void push(int logLevel, std::string_view header, std::string_view message);
38 
39  void
40  process(const std::function<void(int, std::string_view, std::string_view)>& procFunc) const;
41 };
42 
44 void bufferToJson(const LogBuffer& buffer, nlohmann::json& base);
45 
46 } // namespace helics
Definition: application_api/Federate.hpp:27
Definition: LogBuffer.hpp:22
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
void bufferToJson(const LogBuffer &buffer, nlohmann::json &base)
Definition: LogBuffer.cpp:64