GCC Code Coverage Report


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

src/utilities/core/LogSink.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_HPP
7 #define UTILITIES_CORE_LOGSINK_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "LogMessage.hpp"
12
13 #include <boost/regex.hpp>
14 #include <boost/shared_ptr.hpp>
15
16 #include <ostream>
17 #include <thread>
18
19 namespace openstudio {
20
21 class Logger;
22
23 namespace detail {
24 class LogSink_Impl;
25 } // namespace detail
26
27 /// LogSink is a class for managing sinks for log messages, e.g. files, streams, etc.
28 class UTILITIES_API LogSink
29 {
30 public:
31 /// is the sink enabled
32 bool isEnabled() const;
33
34 /// enable the sink
35 void enable();
36
37 /// disable the sink
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 useWorkflowGemFormatter(bool use, bool include_channel = true);
77
78 void setFormatter(const boost::log::formatter& fmter);
79
80 protected:
81 friend class Logger;
82
83 // does not register in the global logger
84 LogSink();
85
86 // does not register in the global logger
87 LogSink(const boost::shared_ptr<detail::LogSink_Impl>& impl);
88
89 // must be set in the constructor
90 void setStream(boost::shared_ptr<std::ostream> os);
91
92 // for adding cout and cerr sinks to logger
93 boost::shared_ptr<LogSinkBackend> sink() const;
94
95 // get the impl
96 template <typename T>
97 7118 boost::shared_ptr<T> getImpl() const {
98 7118 return boost::dynamic_pointer_cast<T>(m_impl);
99 }
100
101 private:
102 boost::shared_ptr<detail::LogSink_Impl> m_impl;
103 };
104
105 } // namespace openstudio
106
107 #endif // UTILITIES_CORE_LOGSINK_HPP
108