GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 1 / 0 / 1
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

src/utilities/core/LogSink_Impl.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_CORE_LOGSINK_IMPL_HPP
7 #define UTILITIES_CORE_LOGSINK_IMPL_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "LogMessage.hpp"
12 #include "LogSink.hpp"
13
14 #include <boost/optional.hpp>
15
16 #include <shared_mutex>
17
18 namespace openstudio {
19
20 namespace detail {
21
22 /// LogSink is a class for managing sinks for log messages, e.g. files, streams, etc.
23 class UTILITIES_API LogSink_Impl
24 {
25 public:
26 /// destructor
27 22406 virtual ~LogSink_Impl() = default;
28
29 /// is the sink enabled
30 bool isEnabled() const;
31
32 /// enable the sink
33 // cppcheck-suppress functionConst
34 void enable();
35
36 /// disable the sink
37 // cppcheck-suppress functionConst
38 void disable();
39
40 /// get the logging level
41 boost::optional<LogLevel> logLevel() const;
42
43 /// set the logging level
44 void setLogLevel(LogLevel logLevel);
45
46 /// reset the core logging level
47 void resetLogLevel();
48
49 /// get the regular expression to match log channels
50 boost::optional<boost::regex> channelRegex() const;
51
52 /// set the regular expression to match log channels
53 void setChannelRegex(const boost::regex& channelRegex);
54
55 /// set the regular expression to match log channels
56 void setChannelRegex(const std::string& channelRegex);
57
58 /// reset the regular expression to match log channels
59 void resetChannelRegex();
60
61 /// get if messages are automatically flushed
62 bool autoFlush() const;
63
64 /// set if messages are automatically flushed
65 void setAutoFlush(bool autoFlush);
66
67 /// get the thread id that messages are filtered by
68 std::thread::id threadId() const;
69
70 /// set the thread id that messages are filtered by
71 void setThreadId(std::thread::id threadId);
72
73 /// reset the thread id that messages are filtered by
74 void resetThreadId();
75
76 void setFormatter(const boost::log::formatter& fmter);
77
78 void useWorkflowGemFormatter(bool use, bool include_channel = false);
79
80 protected:
81 friend class openstudio::LogSink;
82
83 // does not register in the global logger
84 LogSink_Impl();
85
86 // must be set in the constructor
87 void setStream(boost::shared_ptr<std::ostream> os);
88
89 // for adding cout and cerr sinks to logger
90 boost::shared_ptr<LogSinkBackend> sink() const;
91
92 mutable std::shared_mutex m_mutex;
93
94 private:
95 void updateFilter(const std::unique_lock<std::shared_mutex>& l);
96
97 boost::optional<LogLevel> m_logLevel;
98 boost::optional<boost::regex> m_channelRegex;
99 bool m_autoFlush = false;
100 std::thread::id m_threadId;
101 boost::shared_ptr<LogSinkBackend> m_sink;
102 boost::log::formatter m_formatter;
103 };
104
105 } // namespace detail
106
107 } // namespace openstudio
108
109 #endif // UTILITIES_CORE_LOGSINK_IMPL_HPP
110