2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2021-10-13 16:08:48 +02:00
|
|
|
#include "Log.hxx"
|
|
|
|
#include "lib/fmt/ExceptionFormatter.hxx"
|
2016-11-10 12:58:26 +01:00
|
|
|
#include "util/Domain.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
|
2021-06-23 21:55:08 +02:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2016-11-10 12:58:26 +01:00
|
|
|
static constexpr Domain exception_domain("exception");
|
|
|
|
|
2021-06-23 21:55:08 +02:00
|
|
|
void
|
|
|
|
LogVFmt(LogLevel level, const Domain &domain,
|
|
|
|
fmt::string_view format_str, fmt::format_args args) noexcept
|
|
|
|
{
|
|
|
|
fmt::memory_buffer buffer;
|
2021-06-25 17:32:11 +02:00
|
|
|
#if FMT_VERSION >= 80000
|
|
|
|
fmt::vformat_to(std::back_inserter(buffer), format_str, args);
|
|
|
|
#else
|
2021-06-23 21:55:08 +02:00
|
|
|
fmt::vformat_to(buffer, format_str, args);
|
2021-06-25 17:32:11 +02:00
|
|
|
#endif
|
2021-06-23 21:55:08 +02:00
|
|
|
Log(level, domain, {buffer.data(), buffer.size()});
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:09:40 +02:00
|
|
|
void
|
2019-05-23 12:23:28 +02:00
|
|
|
Log(LogLevel level, const std::exception_ptr &ep) noexcept
|
2016-09-09 19:09:40 +02:00
|
|
|
{
|
2021-10-13 16:08:48 +02:00
|
|
|
Log(level, exception_domain, GetFullMessage(ep));
|
2016-09-09 19:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-05-23 12:23:28 +02:00
|
|
|
Log(LogLevel level, const std::exception_ptr &ep, const char *msg) noexcept
|
2016-09-09 19:09:40 +02:00
|
|
|
{
|
2021-10-13 16:08:48 +02:00
|
|
|
LogFmt(level, exception_domain, "{}: {}", msg, ep);
|
2006-08-01 06:18:53 +02:00
|
|
|
}
|