GnuCash 038f90a+
Loading...
Searching...
No Matches
Public Member Functions
Logger Class Reference

messages for later display to the user. More...

Public Member Functions

void info (const char *message)
 
void warn (const char *message)
 
void error (const char *message)
 
void clear ()
 
bool has_errors ()
 
bool has_warnings ()
 
void write_log (std::stringstream &stream, LogMsgType type)
 
void infos (std::stringstream &stream)
 
void warnings (std::stringstream &stream)
 
void errors (std::stringstream &stream)
 
std::string report ()
 Compose all of the logged messages into a bullet list, errors first, then warnings, infos last.
 

Detailed Description

messages for later display to the user.

Proveds 3 categories: error, warning, and info.

Functions are simple accessors and setters unless noted.

Definition at line 452 of file assistant-stock-transaction.cpp.

Member Function Documentation

◆ clear()

void Logger::clear ( )
inline

Definition at line 459 of file assistant-stock-transaction.cpp.

459{ m_log.clear(); }

◆ error()

void Logger::error ( const char *  message)
inline

Definition at line 458 of file assistant-stock-transaction.cpp.

458{ m_log.emplace_back(LogMsgType::error, message); }

◆ errors()

void Logger::errors ( std::stringstream &  stream)
inline

Definition at line 465 of file assistant-stock-transaction.cpp.

465{ return write_log(stream, LogMsgType::error); }

◆ has_errors()

bool Logger::has_errors ( )

Definition at line 493 of file assistant-stock-transaction.cpp.

494{
495 return std::any_of(m_log.begin(), m_log.end(),
496 [](auto& msg){ return msg.type() == LogMsgType::error;
497 });
498}

◆ has_warnings()

bool Logger::has_warnings ( )

Definition at line 485 of file assistant-stock-transaction.cpp.

486{
487 return std::any_of(m_log.begin(), m_log.end(),
488 [](auto& msg){ return msg.type() == LogMsgType::warning;
489 });
490}

◆ info()

void Logger::info ( const char *  message)
inline

Definition at line 456 of file assistant-stock-transaction.cpp.

456{ m_log.emplace_back(LogMsgType::info, message); }

◆ infos()

void Logger::infos ( std::stringstream &  stream)
inline

Definition at line 463 of file assistant-stock-transaction.cpp.

463{ return write_log(stream, LogMsgType::info); }

◆ report()

std::string Logger::report ( )

Compose all of the logged messages into a bullet list, errors first, then warnings, infos last.

Returns
std::string containing the messages.

Definition at line 501 of file assistant-stock-transaction.cpp.

502{
503 std::stringstream summary;
504 if (!has_errors())
505 {
506 summary << _("No errors found. Click Apply to create transaction.");
507 infos(summary);
508 }
509 else
510 {
511 summary << _("The following errors must be fixed:");
512 errors(summary);
513 }
514 if (has_warnings())
515 {
516 summary << "\n\n" << _("The following warnings exist:");
517 warnings(summary);
518 }
519 return summary.str();
520}

◆ warn()

void Logger::warn ( const char *  message)
inline

Definition at line 457 of file assistant-stock-transaction.cpp.

457{ m_log.emplace_back(LogMsgType::warning, message); }

◆ warnings()

void Logger::warnings ( std::stringstream &  stream)
inline

Definition at line 464 of file assistant-stock-transaction.cpp.

464{ return write_log(stream, LogMsgType::warning); }

◆ write_log()

void Logger::write_log ( std::stringstream &  stream,
LogMsgType  type 
)

Definition at line 475 of file assistant-stock-transaction.cpp.

476{
477 std::for_each(m_log.begin(), m_log.end(),
478 [&](auto& msg){
479 if (msg.type() == type)
480 stream << "\n * " << msg.message();
481 });
482}

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