mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Add templated write_message for formatting messages
This new function lives inside include/openmc/error.h and
checks if a message will be written by checking the current
verbosity level prior to formatting the message. This works very
similar to python logging modules and the spdlog project, where
the call to the logging function accepts a formattable message
string and the format arguments separately, e.g.
write_message(1, "Writing data for statepoint {}", point)
The function accepts any number and type of argument after the
format message and passes directly to fmt::format and in-turn to
the non-templated write_message. While this later function does
similar checking with the level and MPI rank, the real goal is the
output function in src/error.cpp which is not currently exposed
through the error header file
Thanks to @paulromano for feedback and suggestions
This commit is contained in:
parent
b6276ea9e4
commit
cf763e2477
1 changed files with 18 additions and 0 deletions
|
|
@ -5,7 +5,10 @@
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "openmc/capi.h"
|
||||
#include "openmc/settings.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNREACHABLE() __builtin_unreachable()
|
||||
|
|
@ -63,6 +66,21 @@ void write_message(const std::stringstream& message, int level)
|
|||
write_message(message.str(), level);
|
||||
}
|
||||
|
||||
template<typename... Params>
|
||||
void write_message(
|
||||
int level, const std::string& message, const Params&... fmt_args)
|
||||
{
|
||||
if (settings::verbosity >= level) {
|
||||
write_message(fmt::format(message, fmt_args...));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Params>
|
||||
void write_message(const std::string& message, const Params&... fmt_args)
|
||||
{
|
||||
write_message(fmt::format(message, fmt_args...));
|
||||
}
|
||||
|
||||
#ifdef OPENMC_MPI
|
||||
extern "C" void abort_mpi(int code);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue