PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::io::Logger Class Reference

Prints log to std::cout and also write to the file. More...

#include <io.h>

Collaboration diagram for util::io::Logger:

Public Member Functions

 Logger (LoggerDeck *deck=nullptr)
 Constructor.
 
 ~Logger ()
 Destructor.
 
void log (std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
 Log the message.
 
void log (const std::string &str, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
 Log the message.
 

Data Fields

LoggerDeckd_deck_p
 Pointer to logger deck.
 
std::ofstream d_logFile
 Filestream for logging.
 

Detailed Description

Prints log to std::cout and also write to the file.

Definition at line 251 of file io.h.

Constructor & Destructor Documentation

◆ Logger()

util::io::Logger::Logger ( LoggerDeck deck = nullptr)
inline

Constructor.

Parameters
deckLogger deck

Definition at line 260 of file io.h.

260 : d_deck_p(deck) {
261
262 if (d_deck_p == nullptr)
263 d_deck_p = new LoggerDeck();
264 }
LoggerDeck * d_deck_p
Pointer to logger deck.
Definition io.h:316

References d_deck_p.

◆ ~Logger()

util::io::Logger::~Logger ( )
inline

Destructor.

Definition at line 269 of file io.h.

269 {
270
272 d_logFile.close();
273 }
std::ofstream d_logFile
Filestream for logging.
Definition io.h:319
bool d_printFile
Print to file?
Definition io.h:229

References d_deck_p, d_logFile, and util::io::LoggerDeck::d_printFile.

Member Function Documentation

◆ log() [1/2]

void util::io::Logger::log ( const std::string &  str,
bool  screen_out = false,
int  printMpiRank = print_default_mpi_rank 
)
inline

Log the message.

Parameters
strMessage
screen_outSpecify if it goes to std::cout as well
printMpiRankMPI rank to do log/print. Negative value means all ranks log.

Definition at line 299 of file io.h.

300 {
301
302 if (printMpiRank < 0 or util::parallel::mpiRank() == printMpiRank) {
303 if (d_deck_p->d_printScreen || screen_out)
304 std::cout << str << std::flush;
305
306 // log
307 if (d_deck_p->d_printFile) {
308 d_logFile.open(d_deck_p->d_filename, std::ios_base::app);
309 d_logFile << str;
310 d_logFile.close();
311 }
312 }
313 };
int mpiRank()
get rank (id) of this processor
std::string d_filename
Filename to print log.
Definition io.h:223
bool d_printScreen
Print to std::cout?
Definition io.h:226

References d_deck_p, util::io::LoggerDeck::d_filename, d_logFile, util::io::LoggerDeck::d_printFile, util::io::LoggerDeck::d_printScreen, and util::parallel::mpiRank().

Here is the call graph for this function:

◆ log() [2/2]

void util::io::Logger::log ( std::ostringstream &  oss,
bool  screen_out = false,
int  printMpiRank = print_default_mpi_rank 
)
inline

Log the message.

Parameters
ossMessage
screen_outSpecify if it goes to std::cout as well
printMpiRankMPI rank to do log/print. Negative value means all ranks log.

Definition at line 282 of file io.h.

283 {
284
285 log(oss.str(), screen_out, printMpiRank);
286
287 // reset oss
288 oss.str("");
289 oss.clear();
290 };
void log(std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
Log the message.
Definition io.h:282

References log().

Referenced by util::io::log(), log(), and util::io::log().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ d_deck_p

LoggerDeck* util::io::Logger::d_deck_p

Pointer to logger deck.

Definition at line 316 of file io.h.

Referenced by log(), Logger(), and ~Logger().

◆ d_logFile

std::ofstream util::io::Logger::d_logFile

Filestream for logging.

Definition at line 319 of file io.h.

Referenced by log(), and ~Logger().


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