src/utilities/core/FileLogSink.cpp
| 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 | #include "FileLogSink.hpp" | ||
| 7 | #include "FileLogSink_Impl.hpp" | ||
| 8 | |||
| 9 | #include "Assert.hpp" | ||
| 10 | |||
| 11 | #include <shared_mutex> | ||
| 12 | |||
| 13 | namespace openstudio { | ||
| 14 | |||
| 15 | namespace detail { | ||
| 16 | |||
| 17 | 3927 | FileLogSink_Impl::FileLogSink_Impl(const openstudio::path& path) | |
| 18 |
4/6✓ Branch 2 taken 3927 times.
✓ Branch 5 taken 3927 times.
✓ Branch 8 taken 3927 times.
✓ Branch 11 taken 3927 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
3927 | : m_path{path}, m_ofs{boost::shared_ptr<openstudio::filesystem::ofstream>(new openstudio::filesystem::ofstream(path))} { |
| 19 |
1/1✓ Branch 2 taken 3927 times.
|
3927 | this->setStream(m_ofs); |
| 20 |
1/1✓ Branch 1 taken 3927 times.
|
3927 | this->enable(); |
| 21 | 3927 | } | |
| 22 | |||
| 23 | 7854 | FileLogSink_Impl::~FileLogSink_Impl() { | |
| 24 | // already called | ||
| 25 | //LogSink_Impl::~LogSink_Impl(); | ||
| 26 | 7854 | } | |
| 27 | |||
| 28 | ✗ | openstudio::path FileLogSink_Impl::path() const { | |
| 29 | ✗ | std::shared_lock l{m_mutex}; | |
| 30 | |||
| 31 | ✗ | return m_path; | |
| 32 | ✗ | } | |
| 33 | |||
| 34 | 17 | std::vector<LogMessage> FileLogSink_Impl::logMessages() const { | |
| 35 |
1/1✓ Branch 1 taken 17 times.
|
17 | openstudio::filesystem::ifstream ifs(m_path); |
| 36 | 17 | std::string line; | |
| 37 | 17 | std::string text; | |
| 38 |
4/4✓ Branch 1 taken 200 times.
✓ Branch 4 taken 200 times.
✓ Branch 6 taken 183 times.
✓ Branch 7 taken 17 times.
|
200 | while (std::getline(ifs, line)) { |
| 39 |
2/2✓ Branch 1 taken 183 times.
✓ Branch 4 taken 183 times.
|
183 | text += line + "\n"; |
| 40 | } | ||
| 41 |
1/1✓ Branch 1 taken 17 times.
|
34 | return LogMessage::parseLogText(text); |
| 42 | 17 | } | |
| 43 | } // namespace detail | ||
| 44 | |||
| 45 |
4/6✓ Branch 1 taken 3927 times.
✓ Branch 4 taken 3927 times.
✓ Branch 7 taken 3927 times.
✓ Branch 11 taken 3927 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
3927 | FileLogSink::FileLogSink(const openstudio::path& path) : LogSink(boost::shared_ptr<detail::FileLogSink_Impl>(new detail::FileLogSink_Impl(path))) { |
| 46 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 3927 times.
✗ Branch 5 not taken.
|
3927 | OS_ASSERT(getImpl<detail::FileLogSink_Impl>()); |
| 47 | 3927 | } | |
| 48 | |||
| 49 | ✗ | openstudio::path FileLogSink::path() const { | |
| 50 | ✗ | return this->getImpl<detail::FileLogSink_Impl>()->path(); | |
| 51 | } | ||
| 52 | |||
| 53 | 17 | std::vector<LogMessage> FileLogSink::logMessages() const { | |
| 54 |
1/1✓ Branch 3 taken 17 times.
|
17 | return this->getImpl<detail::FileLogSink_Impl>()->logMessages(); |
| 55 | } | ||
| 56 | |||
| 57 | } // namespace openstudio | ||
| 58 |