log_stream.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_STREAMS_LOG_STREAM_HPP_
13 #define ECL_STREAMS_LOG_STREAM_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <map>
20 #include <string>
21 #include <ecl/config/macros.hpp>
24 #include <ecl/time/timestamp.hpp>
25 #include "text_stream.hpp"
26 #include "macros.hpp"
27 
28 /*****************************************************************************
29 ** Macros
30 *****************************************************************************/
31 
43 #define LOG(logStream,mode) \
44  if ( !logStream.isModeEnabled(mode) ) {} \
45  else logStream.log(mode) // << rest of stream input will fill out here
46 
56 #define FLUSH(logStream) \
57  if ( !logStream.isEnabled() ) {} \
58  else { logStream.flush(); }
59 
60 /*****************************************************************************
61 ** Namespaces
62 *****************************************************************************/
63 
64 namespace ecl {
65 
66 /*****************************************************************************
67 ** Interface [LogStream]
68 *****************************************************************************/
110 class ecl_streams_PUBLIC LogStream : public TextStream<SharedFile> {
111 public:
118  LogStream() {};
130  LogStream(const std::string &file_name, const WriteMode &mode = New) :
131  write_header(true),
132  write_stamp(true)
133  {
134  ecl_try {
135  if ( !this->device().open(file_name, mode) ) {
136  error = this->device().error();
137  }
138  } ecl_catch(StandardException &e) {
139  ecl_throw(StandardException(LOC,e));
140  }
141  }
142 
143  virtual ~LogStream() {};
144 
151  void enableHeader();
157  void disableHeader();
164  void enableTimeStamp();
171  void disableTimeStamp();
172 
180  void enableMode(int mode, const std::string header = "");
187  void disableMode(int mode);
194  bool isEnabled();
201  bool isModeEnabled(int mode);
214  LogStream& log(int mode);
215 
216  using TextStream<SharedFile>::operator<<;
217 
218 private:
219  bool write_header;
220  bool write_stamp;
221  std::map<int,std::string> modes;
222  TimeStamp timestamp;
223 
224 };
225 
226 } // namespace ecl
227 
228 #endif /* ECL_STREAMS_LOG_STREAM_HPP_ */
WriteMode
WriteMode
ecl_try
#define ecl_try
ecl::New
New
macros.hpp
Macros for ecl streams.
ecl_streams_PUBLIC
#define ecl_streams_PUBLIC
Definition: macros.hpp:37
LOC
#define LOC
standard_exception.hpp
ecl_catch
#define ecl_catch(exception)
ecl_throw
#define ecl_throw(exception)
text_stream.hpp
Convenience header for various text streams.
macros.hpp
shared_file.hpp
ecl
timestamp.hpp


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:48