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  }
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 
217 
218 private:
221  std::map<int,std::string> modes;
222  TimeStamp timestamp;
223 
224 };
225 
226 } // namespace ecl
227 
228 #endif /* ECL_STREAMS_LOG_STREAM_HPP_ */
#define ecl_throw(exception)
std::map< int, std::string > modes
Definition: log_stream.hpp:221
#define LOC
A customised textstream for fast, multithreaded logging to file.
Definition: log_stream.hpp:110
LogStream(const std::string &file_name, const WriteMode &mode=New)
Convenience constructor for logstreams.
Definition: log_stream.hpp:130
#define ecl_streams_PUBLIC
Definition: macros.hpp:37
Convenience header for various text streams.
A text streaming interface.
Definition: text_stream.hpp:94
TimeStamp timestamp
Definition: log_stream.hpp:222
#define ecl_catch(exception)
LogStream()
Default constructor, underlying device must be manually opened.
Definition: log_stream.hpp:118
virtual ~LogStream()
Definition: log_stream.hpp:143
#define ecl_try


ecl_streams
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:59:07