winss
log_stream_wrapper.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2017 Morgan Stanley
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIB_WINSS_LOG_LOG_STREAM_WRAPPER_HPP_
18 #define LIB_WINSS_LOG_LOG_STREAM_WRAPPER_HPP_
19 
20 #include <filesystem>
21 #include <fstream>
22 #include <string>
23 
24 namespace fs = std::experimental::filesystem;
25 
26 namespace winss {
31  private:
32  bool eof = false;
34  public:
39  LogStreamReader(const LogStreamReader&) = delete;
40  LogStreamReader(LogStreamReader&&) = delete;
47  virtual bool IsEOF() const;
48 
57  virtual std::string GetLine();
58 
60  LogStreamReader& operator=(const LogStreamReader&) = delete;
63 };
64 
69  private:
70  std::ofstream file_stream;
71 
72  public:
77  LogStreamWriter(const LogStreamWriter&) = delete;
78  LogStreamWriter(LogStreamWriter&&) = delete;
86  virtual bool Open(fs::path log_path);
87 
93  virtual void Write(const std::string& line);
94 
98  virtual void WriteLine();
99 
105  virtual std::streamoff GetPos();
106 
110  virtual void Close();
111 
113  LogStreamWriter& operator=(const LogStreamWriter&) = delete;
116 
120  virtual ~LogStreamWriter();
121 };
122 } // namespace winss
123 
124 #endif // LIB_WINSS_LOG_LOG_STREAM_WRAPPER_HPP_
Definition: case_ignore.hpp:23
A stream writer for writing logs.
Definition: log_stream_wrapper.hpp:68
virtual bool IsEOF() const
Gets the end of file state.
Definition: log_stream_wrapper.cpp:25
LogStreamReader()
Log stream reader constructor.
Definition: log_stream_wrapper.hpp:38
LogStreamReader & operator=(const LogStreamReader &)=delete
No copy.
virtual std::string GetLine()
Blocks for the next log line.
Definition: log_stream_wrapper.cpp:29
A stream reader for reading logs.
Definition: log_stream_wrapper.hpp:30
LogStreamWriter()
Log stream writer constructor.
Definition: log_stream_wrapper.hpp:76