Commit c872eafbe1e1327c9b3b0fee836a83bfc5fb4b51

Authored by Jürgen Knödlseder
1 parent 3545b0ee

Add optional linefeed parameter to GApplication::log_string (#1828)

The optional linefeed parameter allows to terminate the string with (default) or without a linefeed.
include/GApplication.hpp
... ... @@ -84,7 +84,8 @@ public:
84 84 void log_header(void);
85 85 void log_trailer(void);
86 86 void log_string(const GChatter& chatter,
87   - const std::string& string);
  87 + const std::string& string,
  88 + const bool& linefeed = true);
88 89 void log_value(const GChatter& chatter,
89 90 const std::string& name,
90 91 const std::string& value);
... ...
pyext/GApplication.i
... ... @@ -119,8 +119,9 @@ GApplication._log_value = _log_value
119 119 * @brief GApplication C++ class extension
120 120 ***************************************************************************/
121 121 %extend GApplication {
122   - void _log_string(const int& chatter, const std::string& string) {
123   - self->log_string(GChatter(chatter), string);
  122 + void _log_string(const int& chatter, const std::string& string,
  123 + const bool& linefeed = true) {
  124 + self->log_string(GChatter(chatter), string, linefeed);
124 125 }
125 126 void _log_header1(const int& chatter, const std::string& header) {
126 127 self->log_header1(GChatter(chatter), header);
... ...
src/app/GApplication.cpp
... ... @@ -502,11 +502,14 @@ void GApplication::log_trailer(void)
502 502 *
503 503 * @param[in] chatter Minimum required chattiness
504 504 * @param[in] string String
  505 + * @param[in] linefeed Terminate string with linefeed?
505 506 *
506 507 * Writes a string into the log file if chattiness is at least @p chatter.
  508 + * If @p linefeed is true the string is terminated with a linefeed.
507 509 ***************************************************************************/
508 510 void GApplication::log_string(const GChatter& chatter,
509   - const std::string& string)
  511 + const std::string& string,
  512 + const bool& linefeed)
510 513 {
511 514 // Get chattiness of application
512 515 GChatter chattiness = static_cast<GChatter>((&m_pars["chatter"])->integer());
... ... @@ -515,6 +518,9 @@ void GApplication::log_string(const GChatter&amp; chatter,
515 518 // required chattiness
516 519 if (chattiness >= chatter) {
517 520 log << string;
  521 + if (linefeed) {
  522 + log << std::endl;
  523 + }
518 524 }
519 525  
520 526 // Return
... ...
test/test_GApplication.cpp
... ... @@ -382,12 +382,12 @@ void TestGApplication::test_GApplication(void)
382 382  
383 383 // Write something into the logfile and close it
384 384 app1.log_header();
385   - app1.log_string(SILENT, "Silent");
386   - app1.log_string(TERSE, "Terse");
387   - app1.log_string(NORMAL, "Normal");
388   - app1.log_string(EXPLICIT, "Explicit");
389   - app1.log_string(VERBOSE, "Verbose");
390   - app1.log_string(TERSE, "\n");
  385 + app1.log_string(SILENT, "Silent", false);
  386 + app1.log_string(TERSE, "Terse", false);
  387 + app1.log_string(NORMAL, "Normal", false);
  388 + app1.log_string(EXPLICIT, "Explicit", false);
  389 + app1.log_string(VERBOSE, "Verbose", false);
  390 + app1.log_string(TERSE, "");
391 391 app1.log_value(NORMAL, "String parameter", "3.14");
392 392 app1.log_value(NORMAL, "Floating parameter", 3.14);
393 393 app1.log_value(NORMAL, "Integer parameter", 3);
... ...