1#include <boost/log/attributes/constant.hpp>
2#include <boost/log/attributes/function.hpp>
3#include <boost/log/attributes/named_scope.hpp>
4#include <boost/log/attributes/timer.hpp>
5#include <boost/log/sources/severity_feature.hpp>
6#include <boost/log/trivial.hpp>
7#include <boost/log/utility/setup/common_attributes.hpp>
24 boost::lock_guard<threading_model>,
25 typename BaseT::open_record_lock,
26 typename BaseT::add_attribute_lock,
27 typename BaseT::remove_attribute_lock>::type;
30 template <
typename ArgsT>
43template <
typename BaseT>
44template <
typename ArgsT>
48 int line_value = args[keywords::line | -1];
57 using boost::log::attributes::constant;
58 boost::log::attribute_set &attrs = BaseT::attributes();
60 [[maybe_unused]]
auto res = BaseT::add_attribute_unlocked(
"Line", constant<int>(line_value));
64 [[maybe_unused]]
auto res = BaseT::add_attribute_unlocked(
"File", constant<std::string>(std::move(file_value)));
68 [[maybe_unused]]
auto res = BaseT::add_attribute_unlocked(
"Function", constant<std::string>(std::move(func_value)));
73 auto &&record = BaseT::open_record_unlocked(args);
78 attrs.erase(
"Function");
80 return std::move(record);
84struct precice_log :
public boost::mpl::quote1<precice_feature> {
88template <
class BaseLogger>
89using BoostLogger = boost::log::sources::basic_composite_logger<
92 boost::log::sources::single_thread_model,
93 boost::log::sources::features<
94 boost::log::sources::severity<boost::log::trivial::severity_level>,
112 namespace attrs = boost::log::attributes;
115 add_attribute(
"preCICE", attrs::constant<bool>(
true));
120 add_attribute(
"Module", attrs::constant<std::string>(
std::string{
module}));
123 add_attribute(
"TimeStamp", attrs::local_clock());
124 add_attribute(
"Runtime", attrs::timer());
125 add_attribute(
"Scope", attrs::named_scope());
150 _impl.swap(other._impl);
154#define PRECICE_LOG_IMPL(lg, sev, loc) \
155 BOOST_LOG_STREAM_WITH_PARAMS((lg), (boost::log::keywords::severity = (sev))(keywords::line = (loc.line))(keywords::file = (loc.file))(keywords::func = (loc.func)))
160 PRECICE_LOG_IMPL(*_impl, boost::log::trivial::severity_level::error, loc) << mess;
168 PRECICE_LOG_IMPL(*_impl, boost::log::trivial::severity_level::warning, loc) << mess;
176 PRECICE_LOG_IMPL(*_impl, boost::log::trivial::severity_level::info, loc) << mess;
184 PRECICE_LOG_IMPL(*_impl, boost::log::trivial::severity_level::debug, loc) << mess;
192 PRECICE_LOG_IMPL(*_impl, boost::log::trivial::severity_level::trace, loc) << mess;
197#undef PRECICE_LOG_IMPL
#define PRECICE_LOG_IMPL(lg, sev, loc)
Convenience macro that automatically passes LogLocation info to the logger.
#define PRECICE_ASSERT(...)
LoggerImpl(std::string_view module)
Registers attributes that don't depend on the LogLocation.
This class provides a lightweight logger.
void warning(LogLocation loc, std::string_view mess) noexcept
void error(LogLocation loc, std::string_view mess) noexcept
Logger & operator=(Logger other)
void debug(LogLocation loc, std::string_view mess) noexcept
void info(LogLocation loc, std::string_view mess) noexcept
void swap(Logger &other) noexcept
Logger(std::string_view module)
~Logger()
This is required for the std::unique_ptr.
std::unique_ptr< LoggerImpl > _impl
Pimpl to the logger implementation.
void trace(LogLocation loc, std::string_view mess) noexcept
A feature that adds LogLocation info to log attributes.
typename BaseT::threading_model threading_model
typename boost::log::strictest_lock< boost::lock_guard< threading_model >, typename BaseT::open_record_lock, typename BaseT::add_attribute_lock, typename BaseT::remove_attribute_lock >::type open_record_lock
boost::log::record open_record_unlocked(ArgsT const &args)
Adds log attributes to the current logger based on the LogLocation info.
typename BaseT::char_type char_type
BOOST_PARAMETER_KEYWORD(line_ns, line)
contains the logging framework.
boost::log::sources::basic_composite_logger< char, BaseLogger, boost::log::sources::single_thread_model, boost::log::sources::features< boost::log::sources::severity< boost::log::trivial::severity_level >, precice_log > > BoostLogger
The boost logger that combines required featrues.
GlobalLoggingConfig & getGlobalLoggingConfig()
Returns the global logging configuration.
Struct used to capture the original location of a log request.
Required by BoostLogger to use precice_feature.