19class PrefixCout final : std::streambuf,
public std::ostream
21 std::function< std::string() > prefix_;
23 bool at_line_start_ =
true;
27 std::function< std::string() > prefix = []() {
return ""; },
28 bool only_root = true )
29 : std::ostream( this )
30 , prefix_( std::move( prefix ) )
31 , only_root_( only_root )
48 std::cout << prefix_();
49 at_line_start_ =
false;
52 std::cout.put(
static_cast< char >( ch ) );
57 at_line_start_ =
true;
67 ss <<
"[LOG | rank " << std::setw(
static_cast< int >( std::to_string(
mpi::num_processes() - 1 ).size() ) )
std::ostream subclass to enable logging with prefix and only on root.
Definition logging.hpp:20
int overflow(int ch) override
Definition logging.hpp:34
PrefixCout(std::function< std::string() > prefix=[]() { return "";}, bool only_root=true)
Definition logging.hpp:26
int num_processes()
Definition mpi.hpp:17
MPIRank rank()
Definition mpi.hpp:10
std::string log_prefix()
Definition logging.hpp:64
detail::PrefixCout logall([]() { return detail::log_prefix();}, false)
std::ostream subclass that just logs on any process and adds a timestamp for each line.
std::string current_timestamp()
Get the current timestamp as a string.
Definition timestamp.hpp:10
detail::PrefixCout logroot([]() { return detail::log_prefix();})
std::ostream subclass that just logs on root and adds a timestamp for each line.