4 #include <boost/chrono.hpp>
65 Log(std::ostream &_ostream = std::cout,
int _verbosity =
standard,
66 bool _show_clock =
false,
int _indent_space = 2);
73 template <
int _required_verbosity = standard>
75 _add<_required_verbosity>(
"Calculate", what);
78 template <
int _required_verbosity = standard>
80 _add<_required_verbosity>(
"Construct", what);
83 template <
int _required_verbosity = standard>
85 _add<_required_verbosity>(
"Generate", what);
88 template <
int _required_verbosity = standard>
89 void set(
const std::string &what) {
90 _add<_required_verbosity>(
"Set", what);
93 template <
int _required_verbosity = standard>
94 void check(
const std::string &what) {
95 _add<_required_verbosity>(
"Check", what);
98 template <
int _required_verbosity = standard>
100 _add<_required_verbosity>(
"Results", what);
103 template <
int _required_verbosity = standard>
104 void read(
const std::string &what) {
105 _add<_required_verbosity>(
"Read", what);
108 template <
int _required_verbosity = standard>
109 void write(
const std::string &what) {
110 _add<_required_verbosity>(
"Write", what);
113 template <
int _required_verbosity = standard>
114 void begin(
const std::string &what) {
115 _add<_required_verbosity>(
"Begin", what);
118 template <
int _required_verbosity = standard>
119 void end(
const std::string &what) {
120 _add<_required_verbosity>(
"End", what);
123 template <
int _required_verbosity = standard>
125 _add<_required_verbosity>(
"Warning", what);
128 template <
int _required_verbosity = standard>
129 void error(
const std::string &what) {
130 _add<_required_verbosity>(
"Error", what);
133 template <
int _required_verbosity = standard>
135 _add<_required_verbosity>(
"Compiling", what);
138 template <
int _required_verbosity = standard>
140 static_assert(_required_verbosity >=
none && _required_verbosity <=
debug,
141 "CASM::Log _required_verbosity must be <= 100");
143 begin_section<_required_verbosity>();
151 template <
int _required_verbosity = standard>
152 void custom(
const std::string &type,
const std::string &what) {
153 _add<_required_verbosity>(type, what);
157 template <
int _required_verbosity = standard>
187 begin_section<none>();
220 template <
int _required_verbosity>
222 static_assert(_required_verbosity >=
none && _required_verbosity <=
debug,
223 "CASM::Log _required_verbosity must be <= 100");
228 void reset(std::ostream &_ostream = std::cout);
244 Log &
verbatim(std::string text,
bool indent_first_line =
true);
249 template <
typename OutputIterator>
251 std::string sep =
"- ");
255 template <
typename T>
260 operator std::ostream &();
295 template <
typename T>
297 std::stringstream ss;
308 template <
int _required_verbosity = standard>
309 void _add(
const std::string &type,
const std::string &what) {
310 static_assert(_required_verbosity >=
none && _required_verbosity <=
debug,
311 "CASM::Log _required_verbosity must be <= 100");
313 begin_section<_required_verbosity>();
376 template <
typename OutputIterator>
379 int n_indent_spaces = sep.size();
381 bool indent_first_line =
false;
382 for (
auto it =
begin; it !=
end; ++it) {
384 std::stringstream ss;
387 verbatim(ss.str(), indent_first_line);
393 template <
typename T>
396 static_cast<std::ostream &
>(
log) << msg_details;
406 explicit FixedLog(std::ostream &_ostream);
415 static Log log{std::cout};
420 static Log log{std::cerr};
439 static std::ostream nullout{
nullptr};
455 :
Log(
std::cout, _verbosity, _show_clock) {
459 std::ostringstream &
ss() {
return m_ss; };
461 const std::ostringstream &
ss()
const {
return m_ss; };
507 bool _show_clock =
false)
508 :
m_ss_log(_verbosity, _show_clock),
std::set< std::string > & s
A Log whose underlying ostream* cannot be reset.
FixedLog(std::ostream &_ostream)
FixedLog(FixedLog const &)=delete
FixedLog & operator=(FixedLog const &RHS)=delete
boost::chrono::steady_clock::time_point m_lap_start_time
void read(const std::string &what)
void custom(const std::string &type, const std::string &what)
bool m_print
Whether to print.
static std::string invalid_verbosity_msg(std::string s)
void _print_justified_line(std::vector< std::string > &line, int curr_width)
std::string indent_str() const
void _add(const std::string &type, const std::string &what)
void end_section()
End a section.
Log(std::ostream &_ostream=std::cout, int _verbosity=standard, bool _show_clock=false, int _indent_space=2)
Construct a Log.
void set_verbosity(int _verbosity)
void _print_center_justified_line(std::vector< std::string > &line, int curr_width)
void check(const std::string &what)
void custom(const std::string &what)
void results(const std::string &what)
boost::chrono::steady_clock::time_point m_start_time
JustificationType justification()
void compiling(const std::string &what)
void begin_section()
Begin a section, without header.
Log & subsection()
Create a subsection.
friend Log & operator<<(Log &log, const T &msg_details)
int m_verbosity
If m_verbosity >= required verbosity, then print.
void set(const std::string &what)
void decrease_indent_spaces(int n)
void begin(const std::string &what)
void generate(const std::string &what)
Log & verbatim(std::string text, bool indent_first_line=true)
Print verbatim, but with indentation (optional on first line)
void calculate(const std::string &what)
JustificationType m_justification
void warning(const std::string &what)
void reset(std::ostream &_ostream=std::cout)
int m_indent_space
indent_str = m_indent_space*m_indent_level + m_indent_spaces
void error(const std::string &what)
void increase_indent_spaces(int n)
Log & paragraph(std::string text)
Print indented paragraph with wrapping at Log::width()
void _print_full_justified_line(std::vector< std::string > &line, int curr_width)
std::vector< int > m_required_verbosity
Log & verbatim_list(OutputIterator begin, OutputIterator end, std::string sep="- ")
Print a list.
void set_width(int width)
void set_justification(JustificationType justification)
Log & indent(const T &t)
Same as verbatim, but uses stringstream to convert to string first.
void construct(const std::string &what)
static const int standard
static std::pair< bool, int > verbosity_level(std::string s)
Read verbosity level from a string.
void _print_right_justified_line(std::vector< std::string > &line, int curr_width)
void _print_left_justified_line(std::vector< std::string > &line, int curr_width)
void write(const std::string &what)
void end(const std::string &what)
std::ostringstream & ss()
OStringStreamLog(int _verbosity=standard, bool _show_clock=false)
Construct a StringStreamLog.
const std::ostringstream & ss() const
ScopedLogging(Log &new_log, Log &new_err_log)
ScopedStringStreamLogging(int _verbosity=Log::standard, bool _show_clock=false)
Construct scoped StringStreamLog.
std::ostringstream & ss()
std::unique_ptr< ScopedLogging > m_logging
std::ostringstream & err_ss()
const std::ostringstream & err_ss() const
OStringStreamLog m_ss_log
~ScopedStringStreamLogging()
OStringStreamLog m_ss_err_log
const std::ostringstream & ss() const
#define ABSTRACT_CLONEABLE(T)
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
virtual void print(Log &log) const override
virtual void print(Log &log) const =0
virtual void print(Log &log) const override