GnuCash c935c2f+
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 449 of file assistant-stock-transaction.cpp.

Member Function Documentation

◆ clear()

void Logger::clear ( )
inline

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

456{ m_log.clear(); }

◆ error()

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

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

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

◆ errors()

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

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

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

◆ has_errors()

bool Logger::has_errors ( )

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

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

◆ has_warnings()

bool Logger::has_warnings ( )

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

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

◆ info()

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

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

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

◆ infos()

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

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

460{ 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 498 of file assistant-stock-transaction.cpp.

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

◆ warn()

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

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

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

◆ warnings()

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

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

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

◆ write_log()

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

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

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

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