Commit d27a6487 authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[!6] Make logging functions on Logger const

Merge branch 'feature/make-logging-functions-const' into 'master'

ref:staging/dune-logging Santiago had the valid comment that it would be
better to have the logging methods non-const, as otherwise you would have to
make logger member variables mutable to be able to log in const member
functions. It's actually consistent as well, since the logging calls do not
modify the internal state of the logger itself.

See merge request [!6]

  [!6]: gitlab.dune-project.org/staging/dune-logging/merge_requests/6
parents 947f3916 7edc0940
Pipeline #19447 passed with stage
in 1 minute and 12 seconds
......@@ -83,7 +83,7 @@ namespace Dune::Logging {
_backend->_enabled = false;
}
void Logger::handle(LogLevel level, int indent, std::string_view format, fmt::format_args args)
void Logger::handle(LogLevel level, int indent, std::string_view format, fmt::format_args args) const
{
DUNE_LOGGING_CHECK_LOGGER(level > LogLevel::off);
DUNE_LOGGING_CHECK_LOGGER(_backend && "This logger has no backend attached");
......
......@@ -92,7 +92,7 @@ namespace Dune::Logging {
//! Logs the given log message with the default level of the Logger.
template<typename... Args>
void operator()(format_string_view format, Args&&... args)
void operator()(format_string_view format, Args&&... args) const
{
if (_default_level <= _level and _default_level <= LogLevel::DUNE_MAX_LOGLEVEL) {
handle(_default_level,_indent,format,fmt::make_format_args(std::forward<Args>(args)...));
......@@ -101,7 +101,7 @@ namespace Dune::Logging {
//! Logs the given log message.
template<typename... Args>
void operator()(LogLevel level, format_string_view format, Args&&... args)
void operator()(LogLevel level, format_string_view format, Args&&... args) const
{
DUNE_LOGGING_CHECK_LOGGER(level >= LogLevel::off);
DUNE_LOGGING_CHECK_LOGGER(level < LogLevel::all);
......@@ -112,7 +112,7 @@ namespace Dune::Logging {
//! Logs the given log message and requests additional indentation that will be added to the Logger's default indentation.
template<typename... Args>
void operator()(LogLevel level, int indent, format_string_view format, Args&&... args)
void operator()(LogLevel level, int indent, format_string_view format, Args&&... args) const
{
DUNE_LOGGING_CHECK_LOGGER(level >= LogLevel::off);
DUNE_LOGGING_CHECK_LOGGER(level < LogLevel::all);
......@@ -128,7 +128,7 @@ namespace Dune::Logging {
template<typename FS, typename... Args>
std::enable_if_t<is_format_string_v<FS>>
operator()(FS format, Args&&... args)
operator()(FS format, Args&&... args) const
{
// Instantiate the code that performs the compile-time verification of the format message,
// but never run it.
......@@ -143,7 +143,7 @@ namespace Dune::Logging {
template<typename FS, typename... Args>
std::enable_if_t<is_format_string_v<FS>>
operator()(LogLevel level, FS format, Args&&... args)
operator()(LogLevel level, FS format, Args&&... args) const
{
// Instantiate the code that performs the compile-time verification of the format message,
// but never run it.
......@@ -161,7 +161,7 @@ namespace Dune::Logging {
template<typename FS, typename... Args>
std::enable_if_t<is_format_string_v<FS>>
operator()(LogLevel level, int indent, FS format, Args&&... args)
operator()(LogLevel level, int indent, FS format, Args&&... args) const
{
// Instantiate the code that performs the compile-time verification of the format message,
// but never run it.
......@@ -184,21 +184,21 @@ namespace Dune::Logging {
template<typename FS, typename... Args>
std::enable_if_t<not is_format_string_v<FS>>
operator()(FS format, Args&&... args)
operator()(FS format, Args&&... args) const
{
static_assert(not Std::to_true_type_v<FS>,"You need to tag your format string with the user defined literal suffix _fmt");
}
template<typename FS, typename... Args>
std::enable_if_t<not is_format_string_v<FS>>
operator()(LogLevel level, FS format, Args&&... args)
operator()(LogLevel level, FS format, Args&&... args) const
{
static_assert(not Std::to_true_type_v<FS>,"You need to tag your format string with the user defined literal suffix _fmt");
}
template<typename FS, typename... Args>
std::enable_if_t<not is_format_string_v<FS>>
operator()(LogLevel level, int indent, FS format, Args&&... args)
operator()(LogLevel level, int indent, FS format, Args&&... args) const
{
static_assert(not Std::to_true_type_v<FS>,"You need to tag your format string with the user defined literal suffix _fmt");
}
......@@ -207,63 +207,63 @@ namespace Dune::Logging {
//! Logs the given message at LogLevel::critical.
template<typename... Args>
void critical(Args&&... args)
void critical(Args&&... args) const
{
(*this)(LogLevel::critical,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::error.
template<typename... Args>
void error(Args&&... args)
void error(Args&&... args) const
{
(*this)(LogLevel::error,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::warning.
template<typename... Args>
void warning(Args&&... args)
void warning(Args&&... args) const
{
(*this)(LogLevel::warning,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::warning.
template<typename... Args>
void warn(Args&&... args)
void warn(Args&&... args) const
{
(*this)(LogLevel::warning,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::notice.
template<typename... Args>
void notice(Args&&... args)
void notice(Args&&... args) const
{
(*this)(LogLevel::notice,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::info.
template<typename... Args>
void info(Args&&... args)
void info(Args&&... args) const
{
(*this)(LogLevel::info,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::detail.
template<typename... Args>
void detail(Args&&... args)
void detail(Args&&... args) const
{
(*this)(LogLevel::detail,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::debug.
template<typename... Args>
void debug(Args&&... args)
void debug(Args&&... args) const
{
(*this)(LogLevel::debug,std::forward<Args>(args)...);
}
//! Logs the given message at LogLevel::trace.
template<typename... Args>
void trace(Args&&... args)
void trace(Args&&... args) const
{
(*this)(LogLevel::trace,std::forward<Args>(args)...);
}
......@@ -416,7 +416,7 @@ namespace Dune::Logging {
* we don't want to duplicate at every log site, as this would unnecessarily bloat the code and
* make disabled log calls very expensive.
*/
void handle(LogLevel level, int indent, std::string_view format, fmt::format_args args);
void handle(LogLevel level, int indent, std::string_view format, fmt::format_args args) const;
LogLevel _level = LogLevel::all;
int _indent = 0;
......
Supports Markdown
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