Commit ff611e5b authored by Steffen Müthing's avatar Steffen Müthing

[logging] Make logging-internal logger configurable

parent 07d5fd6c
Pipeline #16612 passed with stage
in 16 minutes and 32 seconds
......@@ -188,6 +188,7 @@ namespace Dune::PDELab {
LogLevel unmuted_cerr = LogLevel::all;
std::optional<CollectiveCommunication> comm;
LogMessage::Time startup_time = LogMessage::Clock::now();
Logger logger;
LoggingStreamBuffer cout_buf;
LoggingStreamBuffer cerr_buf;
LoggingStreamBuffer clog_buf;
......@@ -413,13 +414,28 @@ namespace Dune::PDELab {
}
}
// configure internal logger for logging system itself
{
auto level = parseLogLevel(params.get("internal.level","notice"));
auto backend = params.get("internal.backend","logging");
// create default-configured logging backend if necessary
if (backend == "logging" and s.backends.count("logging") == 0)
Logging::registerBackend("logging",s.default_backend->_default_level);
s.logger = logger(backend);
s.logger.setLevel(level);
}
if (params.get("muted",s.comm->rank() > 0))
{
mute();
if (s.comm->size() > 0)
logger().info("Muted console log sinks on MPI ranks > 0"_fmt);
s.logger.info("Muted console log sinks on MPI ranks > 0"_fmt);
}
// from here on out, it is allowed to log messages
if (params.hasKey("redirect"))
{
auto level = parseLogLevel(params["redirect"]);
......@@ -479,7 +495,7 @@ namespace Dune::PDELab {
// We need to manually format the time, as doing so is not constexpr
auto time_string = fmt::format("{:%a %F %T %Z}",local_time);
logger().notice("Logging system initialized at {}"_fmt,time_string);
s.logger.notice("Logging system initialized at {}"_fmt,time_string);
}
void Logging::shutdown()
......@@ -758,7 +774,7 @@ namespace Dune::PDELab {
if (not s.orig_cout_buf)
s.orig_cout_buf = std::cout.rdbuf();
std::cout.rdbuf(&s.cout_buf);
Logging::logger().notice("Redirected std::cout to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
s.logger.info("Redirected std::cout to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
}
void Logging::redirectCerr(std::string_view backend, LogLevel level, bool buffered)
......@@ -771,7 +787,7 @@ namespace Dune::PDELab {
if (not s.orig_cerr_buf)
s.orig_cerr_buf = std::cerr.rdbuf();
std::cerr.rdbuf(&s.cerr_buf);
Logging::logger().notice("Redirected std::cerr to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
s.logger.info("Redirected std::cerr to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
}
void Logging::redirectClog(std::string_view backend, LogLevel level, bool buffered)
......@@ -784,7 +800,7 @@ namespace Dune::PDELab {
if (not s.orig_clog_buf)
s.orig_clog_buf = std::clog.rdbuf();
std::clog.rdbuf(&s.clog_buf);
Logging::logger().notice("Redirected std::clog to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
s.logger.info("Redirected std::clog to backend {} with level {}, buffered: {}"_fmt,backend,level,buffered);
}
void Logging::restoreCout()
......@@ -794,10 +810,10 @@ namespace Dune::PDELab {
{
std::cout.rdbuf(s.orig_cout_buf);
s.orig_cout_buf = nullptr;
Logging::logger().notice("Stopped redirection of std::cout"_fmt);
s.logger.notice("Stopped redirection of std::cout"_fmt);
}
else
Logging::logger().warning("Cannot stop redirection of std::cout, not redirected at the moment"_fmt);
s.logger.info("Cannot stop redirection of std::cout, not redirected at the moment"_fmt);
}
void Logging::restoreCerr()
......@@ -807,10 +823,10 @@ namespace Dune::PDELab {
{
std::cerr.rdbuf(s.orig_cerr_buf);
s.orig_cerr_buf = nullptr;
Logging::logger().notice("Stopped redirection of std::cerr"_fmt);
s.logger.info("Stopped redirection of std::cerr"_fmt);
}
else
Logging::logger().warning("Cannot stop redirection of std::cerr, not redirected at the moment"_fmt);
s.logger.warning("Cannot stop redirection of std::cerr, not redirected at the moment"_fmt);
}
void Logging::restoreClog()
......@@ -820,10 +836,10 @@ namespace Dune::PDELab {
{
std::clog.rdbuf(s.orig_clog_buf);
s.orig_clog_buf = nullptr;
Logging::logger().notice("Stopped redirection of std::clog"_fmt);
s.logger.info("Stopped redirection of std::clog"_fmt);
}
else
Logging::logger().warning("Cannot stop redirection of std::clog, not redirected at the moment"_fmt);
s.logger.warning("Cannot stop redirection of std::clog, not redirected at the moment"_fmt);
}
bool Logging::isCoutRedirected()
......
......@@ -239,9 +239,15 @@ namespace Dune::PDELab {
*
* The logging system itself supports the following configuration keys:
*
* | Key | Description |
* |-------------|----------------------------------------------------------------------------------|
* | muted | Overrides the default behavior of muting all MPI ranks with `comm.rank() > 0` |
* | Key | Description |
* |------------------|------------------------------------------------------------------------------|
* | muted | Overrides the default behavior of muting all MPI ranks with `comm.rank() > 0`|
* | internal.backend | The backend used for internal log messages of the logging system |
* | internal.level | The maximum enabled log level for internal log messages |
*
* If you do not specify configuration for the internal logging, the system defaults to a backend
* called "logger" and a maximum log level of "notice". If the backend does not exist, it will be
* created with its configuration copied from the default backend.
*
* ## Redirection of C++ Standard Streams
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment