PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
logger.hpp
Go to the documentation of this file.
1 
13 #ifndef PLSSVM_DETAIL_LOGGER_HPP_
14 #define PLSSVM_DETAIL_LOGGER_HPP_
15 #pragma once
16 
17 #include "plssvm/detail/performance_tracker.hpp" // plssvm::detail::is_tracking_entry_v, PLSSVM_DETAIL_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY
18 
19 #include "fmt/chrono.h" // format std::chrono types
20 #include "fmt/format.h" // fmt::format
21 #include "fmt/ostream.h" // format types with an operator<< overload
22 
23 #include <iosfwd> // std::istream, std::ostream
24 #include <iostream> // std::cout
25 #include <string_view> // std::string_view
26 #include <utility> // std::forward
27 
28 namespace plssvm {
29 
33 enum class verbosity_level {
35  quiet = 0b000,
37  libsvm = 0b001,
39  timing = 0b010,
41  full = 0b100
42 };
43 
46 
54 std::ostream &operator<<(std::ostream &out, verbosity_level verb);
55 
64 std::istream &operator>>(std::istream &in, verbosity_level &verb);
65 
80 
95 
96 namespace detail {
97 
108 template <typename... Args>
109 void log(const verbosity_level verb, const std::string_view msg, Args &&...args) {
110  // if the verbosity level is quiet, nothing is logged
111  // otherwise verb must contain the bit-flag set by plssvm::verbosity
113  std::cout << fmt::format(msg, args...);
114  }
115 
116  // if performance tracking has been enabled, add tracking entries
117  ([](auto &&arg) {
118  if constexpr (detail::is_tracking_entry_v<decltype(arg)>) {
119  PLSSVM_DETAIL_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY(std::forward<decltype(arg)>(arg));
120  }
121  }(std::forward<Args>(args)),
122  ...);
123 }
124 
125 } // namespace detail
126 
127 } // namespace plssvm
128 
129 #endif // PLSSVM_DETAIL_LOGGER_HPP_
void log(const verbosity_level verb, const std::string_view msg, Args &&...args)
Definition: logger.hpp:109
constexpr bool is_tracking_entry_v
Definition: performance_tracker.hpp:96
The main namespace containing all public API functions.
Definition: backend_types.hpp:24
verbosity_level verbosity
The verbosity level used in the logging function. My be changed by the user.
verbosity_level
Enum class for all possible verbosity levels.
Definition: logger.hpp:33
std::istream & operator>>(std::istream &in, backend_type &backend)
Use the input-stream in to initialize the backend type.
verbosity_level operator|=(verbosity_level &lhs, verbosity_level rhs)
Bitwise-or to set multiple verbosity levels at once for a logging message.
verbosity_level operator&=(verbosity_level &lhs, verbosity_level rhs)
Bitwise-and to check verbosity levels for a logging message.
verbosity_level operator|(verbosity_level lhs, verbosity_level rhs)
Bitwise-or to set multiple verbosity levels at once for a logging message.
std::ostream & operator<<(std::ostream &out, backend_type backend)
Output the backend to the given output-stream out.
verbosity_level operator&(verbosity_level lhs, verbosity_level rhs)
Bitwise-and to check verbosity levels for a logging message.
Defines a performance tracker which can dump performance information in a YAML file.
#define PLSSVM_DETAIL_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY(entry)
Defines the PLSSVM_DETAIL_PERFORMANCE_TRACKER_ADD_TRACKING_ENTRY macro if PLSSVM_PERFORMANCE_TRACKER_...
Definition: performance_tracker.hpp:245