helics 3.7.0
Loading...
Searching...
No Matches
LogManager.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7#pragma once
8
14#include "../common/LogBuffer.hpp"
15#include "../helics_enums.h"
16#include "FederateIdExtra.hpp"
17
18#include <atomic>
19#include <functional>
20#include <memory>
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace spdlog {
26class logger;
27}
28
29namespace helics {
30class LogBuffer;
31class helicsCLI11App;
32class LogBuffer;
33class ActionMessage;
34
36 private:
37 std::string logIdentifier;
38 std::atomic<int32_t> maxLogLevel{HELICS_LOG_LEVEL_WARNING};
40 int32_t consoleLogLevel{HELICS_LOG_LEVEL_WARNING};
42 int32_t fileLogLevel{HELICS_LOG_LEVEL_WARNING};
44 std::vector<std::pair<GlobalFederateId, std::int32_t>> remoteTargets;
46 std::shared_ptr<spdlog::logger> consoleLogger;
48 std::shared_ptr<spdlog::logger> fileLogger;
49 std::atomic<bool> initialized{false};
50 mutable LogBuffer mLogBuffer;
52 std::function<void(int, std::string_view, std::string_view)> loggerFunction;
53 std::function<void(ActionMessage&& mm)> mTransmit;
54 std::string logFile;
55
56 public:
58 std::atomic<bool> forceLoggingFlush{false};
59
61
62 void initializeLogging(const std::string& identifier);
63
67 bool sendToLogger(int logLevel,
68 std::string_view header,
69 std::string_view message,
70 bool disableRemote = false) const;
72 void addLoggingCLI(std::shared_ptr<helicsCLI11App>& app);
73
75 void setLogLevel(int32_t level);
80 void setLogLevels(int32_t consoleLevel, int32_t fileLevel);
82 void logFlush();
83
90 std::function<void(int level, std::string_view identifier, std::string_view message)>
91 logFunction);
92
93 void setTransmitCallback(std::function<void(ActionMessage&& mm)> transmit)
94
95 {
96 mTransmit = std::move(transmit);
97 }
98 int getMaxLevel() const { return maxLogLevel.load(); }
99 int getFileLevel() const { return fileLogLevel; }
100 int getConsoleLevel() const { return consoleLogLevel; }
101 void setLoggingFile(std::string_view lfile, const std::string& identifier);
102 LogBuffer& getLogBuffer() { return mLogBuffer; }
103 void updateRemote(GlobalFederateId destination, int level);
104
105 private:
106 void updateMaxLogLevel();
107};
108
109} // namespace helics
Definition ActionMessage.hpp:30
Definition LogBuffer.hpp:22
Definition LogManager.hpp:35
std::atomic< bool > forceLoggingFlush
force the log to flush after every message
Definition LogManager.hpp:58
void logFlush()
Definition LogManager.cpp:215
void setLogLevel(int32_t level)
Definition LogManager.cpp:210
void addLoggingCLI(std::shared_ptr< helicsCLI11App > &app)
Definition LogManager.cpp:155
void setLogLevels(int32_t consoleLevel, int32_t fileLevel)
Definition LogManager.cpp:225
void setLoggerFunction(std::function< void(int level, std::string_view identifier, std::string_view message)> logFunction)
Definition LogManager.cpp:204
bool sendToLogger(int logLevel, std::string_view header, std::string_view message, bool disableRemote=false) const
Definition LogManager.cpp:92
@ HELICS_LOG_LEVEL_WARNING
Definition helics_enums.h:212
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14