Program Listing for File log_stream.hpp
↰ Return to documentation for file (/tmp/ws/src/ecl_core/ecl_streams/include/ecl/streams/log_stream.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef ECL_STREAMS_LOG_STREAM_HPP_
#define ECL_STREAMS_LOG_STREAM_HPP_
/*****************************************************************************
** Includes
*****************************************************************************/
#include <map>
#include <string>
#include <ecl/config/macros.hpp>
#include <ecl/devices/shared_file.hpp>
#include <ecl/exceptions/standard_exception.hpp>
#include <ecl/time/timestamp.hpp>
#include "text_stream.hpp"
#include "macros.hpp"
/*****************************************************************************
** Macros
*****************************************************************************/
#define LOG(logStream,mode) \
if ( !logStream.isModeEnabled(mode) ) {} \
else logStream.log(mode) // << rest of stream input will fill out here
#define FLUSH(logStream) \
if ( !logStream.isEnabled() ) {} \
else { logStream.flush(); }
/*****************************************************************************
** Namespaces
*****************************************************************************/
namespace ecl {
/*****************************************************************************
** Interface [LogStream]
*****************************************************************************/
class ecl_streams_PUBLIC LogStream : public TextStream<SharedFile> {
public:
LogStream() {};
LogStream(const std::string &file_name, const WriteMode &mode = New) :
write_header(true),
write_stamp(true)
{
ecl_try {
if ( !this->device().open(file_name, mode) ) {
error = this->device().error();
}
} ecl_catch(StandardException &e) {
ecl_throw(StandardException(LOC,e));
}
}
virtual ~LogStream() {};
void enableHeader();
void disableHeader();
void enableTimeStamp();
void disableTimeStamp();
void enableMode(int mode, const std::string header = "");
void disableMode(int mode);
bool isEnabled();
bool isModeEnabled(int mode);
LogStream& log(int mode);
using TextStream<SharedFile>::operator<<;
private:
bool write_header;
bool write_stamp;
std::map<int,std::string> modes;
TimeStamp timestamp;
};
} // namespace ecl
#endif /* ECL_STREAMS_LOG_STREAM_HPP_ */