Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::test::ScopedLogStorer Class Reference

Log handle for saving messages for testing. More...

#include <ScopedLogStorer.hh>

Public Types

Type aliases
using VecString = std::vector< std::string >
 

Public Member Functions

 ScopedLogStorer (Logger *orig, LogLevel min_level)
 Construct reference to log to temporarily replace.
 
 ScopedLogStorer (Logger *orig)
 Construct reference to log to temporarily replace.
 
 ~ScopedLogStorer ()
 Restore original logger on destruction.
 
 CELER_DEFAULT_MOVE_DELETE_COPY (ScopedLogStorer)
 Prevent copying but allow moving.
 
void operator() (LogProvenance, LogLevel lev, std::string msg)
 Save a log message.
 
bool empty () const
 Whether no messages were stored.
 
VecString const & messages () const
 Get saved messages.
 
VecString const & levels () const
 Get corresponding log levels.
 
void print_expected () const
 
void clear ()
 Clear results.
 
LogLevel level () const
 Get the minimum level being recorded.
 
void level (LogLevel lev)
 Change the level to record.
 

Detailed Description

Log handle for saving messages for testing.

Temporarily replace the given logger with this function. This removes ANSI sequences and replaces pointer-like strings with 0x0.

You can use the CELER_LOG_SCOPED environment variable to print the captured log messages as they are written.

CELER_LOG(info) << "captured";
scoped_log_.print_expected();
EXPECT_TRUE(scoped_log_.empty()) << scoped_log_;
ScopedLogStorer(Logger *orig, LogLevel min_level)
Construct reference to log to temporarily replace.
Definition: ScopedLogStorer.cc:26
Logger & world_logger()
Parallel-enabled logger: print only on "main" process.
Definition: corecel/io/Logger.cc:178
#define CELER_LOG(LEVEL)
Return a LogMessage object for streaming into at the given level.
Definition: corecel/io/Logger.hh:48

The documentation for this class was generated from the following files: