15 #include <unordered_map>
18 #include <rapidsmpf/config.hpp>
19 #include <rapidsmpf/utils/misc.hpp>
37 class Logger :
public std::enable_shared_from_this<Logger> {
57 "NONE",
"PRINT",
"WARN",
"INFO",
"DEBUG",
"TRACE"
67 auto index =
static_cast<std::size_t
>(level);
78 [[nodiscard]]
static std::shared_ptr<Logger>
create(
104 virtual ~
Logger() noexcept = default;
142 template <
typename... Args>
144 if (
static_cast<std::uint32_t
>(level_) <
static_cast<std::uint32_t
>(level)) {
147 std::ostringstream ss;
149 do_log(level, std::move(ss));
158 template <
typename... Args>
169 template <
typename... Args>
170 void warn(Args
const&... args) {
180 template <
typename... Args>
181 void info(Args
const&... args) {
191 template <
typename... Args>
202 template <
typename... Args>
221 auto const tid = std::this_thread::get_id();
224 auto const [name, inserted] =
225 thread_id_names.insert({tid, thread_id_names_counter});
227 ++thread_id_names_counter;
244 std::lock_guard<std::mutex> lock(mutex_);
245 std::ostringstream full_log_msg;
247 <<
":" << Clock::now() <<
"] " << ss.str();
248 std::cout << full_log_msg.str() << std::endl;
258 std::uint32_t thread_id_names_counter{0};
261 std::unordered_map<std::thread::id, std::uint32_t> thread_id_names;
A logger base class for handling different levels of log messages.
void set_name(std::string name)
Update the name used in log message prefixes.
void warn(Args const &... args)
Logs a warning message.
virtual void do_log(LOG_LEVEL level, std::ostringstream &&ss)
Handles the logging of a messages.
void trace(Args const &... args)
Logs a trace message.
static std::shared_ptr< Logger > create(LOG_LEVEL level=LOG_LEVEL::WARN, std::string name="unknown")
Create a logger.
void info(Args const &... args)
Logs an informational message.
LOG_LEVEL
Log verbosity levels.
@ INFO
Informational messages.
@ PRINT
General print messages.
static std::shared_ptr< Logger > from_options(config::Options options)
Create a logger from configuration options.
void print(Args const &... args)
Logs a print message.
Logger(LOG_LEVEL level, std::string name)
Constructs a logger.
void debug(Args const &... args)
Logs a debug message.
virtual std::uint32_t get_thread_id()
Returns a unique thread ID for the current thread.
static constexpr char const * level_name(LOG_LEVEL level)
Get the string name of a log level.
void log(LOG_LEVEL level, Args const &... args)
Logs a message using the specified verbosity level.
static constexpr std::array< char const *, 6 > LOG_LEVEL_NAMES
Log level names corresponding to the LOG_LEVEL enum.
LOG_LEVEL verbosity_level() const
Get the verbosity level of the logger.
Manages configuration options for RapidsMPF operations.
RAPIDS Multi-Processor interfaces.