Skip to content

Commit

Permalink
Append newline to log and error messages if not already present
Browse files Browse the repository at this point in the history
Also make the indentation of error messages consistent with log ones
  • Loading branch information
giacomofiorin committed Apr 28, 2023
1 parent d8e7d7c commit c0ca08c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/colvarmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,12 +1736,15 @@ std::ostream & colvarmodule::write_traj(std::ostream &os)
void colvarmodule::log(std::string const &message, int min_log_level)
{
if (cvm::log_level() < min_log_level) return;

std::string const trailing_newline = (message.size() > 0) ?
(message[message.size()-1] == '\n' ? "" : "\n") : "";
// allow logging when the module is not fully initialized
size_t const d = (cvm::main() != NULL) ? depth() : 0;
if (d > 0) {
proxy->log((std::string(2*d, ' '))+message);
proxy->log((std::string(2*d, ' ')) + message + trailing_newline);
} else {
proxy->log(message);
proxy->log(message + trailing_newline);
}
}

Expand Down Expand Up @@ -1810,7 +1813,16 @@ void colvarmodule::clear_error()
int colvarmodule::error(std::string const &message, int code)
{
set_error_bits(code);
proxy->error(message);

std::string const trailing_newline = (message.size() > 0) ?
(message[message.size()-1] == '\n' ? "" : "\n") : "";
size_t const d = depth();
if (d > 0) {
proxy->error((std::string(2*d, ' ')) + message + trailing_newline);
} else {
proxy->error(message + trailing_newline);
}

return get_error();
}

Expand Down

0 comments on commit c0ca08c

Please sign in to comment.