Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
include
ecl
streams
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>
22
#include <ecl/devices/shared_file.hpp>
23
#include <ecl/exceptions/standard_exception.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
)
ecl_throw_decl
(
StandardException
) :
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_ */
ecl
macros.hpp
Macros for ecl streams.
ecl::WriteMode
WriteMode
ecl_throw
#define ecl_throw(exception)
Standard ecl throw exception throw.
Definition:
ecl/exceptions/macros.hpp:74
ecl::LogStream::write_header
bool write_header
Definition:
log_stream.hpp:219
ecl_throw_decl
#define ecl_throw_decl(exception)
Standard ecl throw exception declaration.
Definition:
ecl/exceptions/macros.hpp:64
ecl::LogStream::modes
std::map< int, std::string > modes
Definition:
log_stream.hpp:221
LOC
#define LOC
Stringify the line of code you are at.
Definition:
ecl/errors/macros.hpp:67
ecl::LogStream
A customised textstream for fast, multithreaded logging to file.
Definition:
log_stream.hpp:110
ecl::StandardException
Standard exception type, provides code location and error string.
Definition:
standard_exception.hpp:54
text_stream.hpp
Convenience header for various text streams.
ecl::TextStream
A text streaming interface.
Definition:
text_stream.hpp:94
ecl::LogStream::write_stamp
bool write_stamp
Definition:
log_stream.hpp:220
ecl::LogStream::timestamp
TimeStamp timestamp
Definition:
log_stream.hpp:222
ecl::LogStream::LogStream
LogStream(const std::string &file_name, const WriteMode &mode=New) ecl_throw_decl(StandardException)
Convenience constructor for logstreams.
Definition:
log_stream.hpp:130
ecl_catch
#define ecl_catch(exception)
The catch part of a try-catch macro matching ecl_throw calls.
Definition:
ecl/exceptions/macros.hpp:86
ecl::New
New
ecl::LogStream::LogStream
LogStream()
Default constructor, underlying device must be manually opened.
Definition:
log_stream.hpp:118
ecl::LogStream::~LogStream
virtual ~LogStream()
Definition:
log_stream.hpp:143
ecl_streams_PUBLIC
#define ecl_streams_PUBLIC
Definition:
ecl/streams/macros.hpp:37
ecl_try
#define ecl_try
The try part of a try-catch macro matching ecl_throw calls.
Definition:
ecl/exceptions/macros.hpp:80
xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37