Skip to content

Commit

Permalink
Use the fmt logging a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Dec 1, 2024
1 parent f94e5b9 commit ecc2e1b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 147 deletions.
83 changes: 42 additions & 41 deletions al/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "alc/device.h"
#include "alnumeric.h"
#include "alspan.h"
#include "alstring.h"
#include "auxeffectslot.h"
#include "buffer.h"
#include "core/except.h"
Expand All @@ -45,6 +44,8 @@ DebugGroup::~DebugGroup() = default;

namespace {

using namespace std::string_view_literals;

static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits");

template<typename T, T ...Vals>
Expand Down Expand Up @@ -145,46 +146,46 @@ constexpr auto GetDebugSeverityEnum(DebugSeverity severity) -> ALenum
}


constexpr auto GetDebugSourceName(DebugSource source) noexcept -> const char*
constexpr auto GetDebugSourceName(DebugSource source) noexcept -> std::string_view
{
switch(source)
{
case DebugSource::API: return "API";
case DebugSource::System: return "Audio System";
case DebugSource::ThirdParty: return "Third Party";
case DebugSource::Application: return "Application";
case DebugSource::Other: return "Other";
case DebugSource::API: return "API"sv;
case DebugSource::System: return "Audio System"sv;
case DebugSource::ThirdParty: return "Third Party"sv;
case DebugSource::Application: return "Application"sv;
case DebugSource::Other: return "Other"sv;
}
return "<invalid source>";
return "<invalid source>"sv;
}

constexpr auto GetDebugTypeName(DebugType type) noexcept -> const char*
constexpr auto GetDebugTypeName(DebugType type) noexcept -> std::string_view
{
switch(type)
{
case DebugType::Error: return "Error";
case DebugType::DeprecatedBehavior: return "Deprecated Behavior";
case DebugType::UndefinedBehavior: return "Undefined Behavior";
case DebugType::Portability: return "Portability";
case DebugType::Performance: return "Performance";
case DebugType::Marker: return "Marker";
case DebugType::PushGroup: return "Push Group";
case DebugType::PopGroup: return "Pop Group";
case DebugType::Other: return "Other";
case DebugType::Error: return "Error"sv;
case DebugType::DeprecatedBehavior: return "Deprecated Behavior"sv;
case DebugType::UndefinedBehavior: return "Undefined Behavior"sv;
case DebugType::Portability: return "Portability"sv;
case DebugType::Performance: return "Performance"sv;
case DebugType::Marker: return "Marker"sv;
case DebugType::PushGroup: return "Push Group"sv;
case DebugType::PopGroup: return "Pop Group"sv;
case DebugType::Other: return "Other"sv;
}
return "<invalid type>";
return "<invalid type>"sv;
}

constexpr auto GetDebugSeverityName(DebugSeverity severity) noexcept -> const char*
constexpr auto GetDebugSeverityName(DebugSeverity severity) noexcept -> std::string_view
{
switch(severity)
{
case DebugSeverity::High: return "High";
case DebugSeverity::Medium: return "Medium";
case DebugSeverity::Low: return "Low";
case DebugSeverity::Notification: return "Notification";
case DebugSeverity::High: return "High"sv;
case DebugSeverity::Medium: return "Medium"sv;
case DebugSeverity::Low: return "Low"sv;
case DebugSeverity::Notification: return "Notification"sv;
}
return "<invalid severity>";
return "<invalid severity>"sv;
}

} // namespace
Expand All @@ -198,8 +199,8 @@ void ALCcontext::sendDebugMessage(std::unique_lock<std::mutex> &debuglock, Debug

if(message.length() >= MaxDebugMessageLength) UNLIKELY
{
ERR("Debug message too long (%zu >= %d):\n-> %.*s\n", message.length(),
MaxDebugMessageLength, al::sizei(message), message.data());
ERRFMT("Debug message too long ({} >= {}):\n-> {}", message.length(),
MaxDebugMessageLength, message);
return;
}

Expand Down Expand Up @@ -233,14 +234,14 @@ void ALCcontext::sendDebugMessage(std::unique_lock<std::mutex> &debuglock, Debug
if(mDebugLog.size() < MaxDebugLoggedMessages)
mDebugLog.emplace_back(source, type, id, severity, message);
else UNLIKELY
ERR("Debug message log overflow. Lost message:\n"
" Source: %s\n"
" Type: %s\n"
" ID: %u\n"
" Severity: %s\n"
" Message: \"%.*s\"\n",
ERRFMT("Debug message log overflow. Lost message:\n"
" Source: {}\n"
" Type: {}\n"
" ID: {}\n"
" Severity: {}\n"
" Message: \"{}\"",
GetDebugSourceName(source), GetDebugTypeName(type), id,
GetDebugSeverityName(severity), al::sizei(message), message.data());
GetDebugSeverityName(severity), message);
}
}

Expand Down Expand Up @@ -290,7 +291,7 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}


Expand Down Expand Up @@ -391,7 +392,7 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}


Expand Down Expand Up @@ -436,7 +437,7 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}

FORCE_ALIGN DECL_FUNCEXT(void, alPopDebugGroup,EXT)
Expand All @@ -459,7 +460,7 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}


Expand Down Expand Up @@ -521,7 +522,7 @@ catch(al::base_exception&) {
return 0;
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
return 0;
}

Expand Down Expand Up @@ -552,7 +553,7 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}

FORCE_ALIGN DECL_FUNCEXT5(void, alGetObjectLabel,EXT, ALenum,identifier, ALuint,name, ALsizei,bufSize, ALsizei*,length, ALchar*,label)
Expand Down Expand Up @@ -622,5 +623,5 @@ try {
catch(al::base_exception&) {
}
catch(std::exception &e) {
ERR("Caught exception: %s\n", e.what());
ERRFMT("Caught exception: {}", e.what());
}
5 changes: 2 additions & 3 deletions al/eax/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cassert>
#include <exception>

#include "alstring.h"
#include "core/logging.h"


Expand All @@ -18,9 +17,9 @@ void eax_log_exception(std::string_view message) noexcept
std::rethrow_exception(exception_ptr);
}
catch(const std::exception& ex) {
ERR("%.*s %s\n", al::sizei(message), message.data(), ex.what());
ERRFMT("{} {}", message, ex.what());
}
catch(...) {
ERR("%.*s %s\n", al::sizei(message), message.data(), "Generic exception.");
ERRFMT("{} {}", message, "Generic exception.");
}
}
45 changes: 20 additions & 25 deletions alc/alconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void LoadConfigFromFile(std::istream &f)
auto endpos = buffer.find(']', 1);
if(endpos == 1 || endpos == std::string::npos)
{
ERR(" config parse error: bad line \"%s\"\n", buffer.c_str());
ERRFMT(" config parse error: bad line \"{}\"", buffer);
continue;
}
if(buffer[endpos+1] != '\0')
Expand All @@ -164,7 +164,7 @@ void LoadConfigFromFile(std::istream &f)

if(last < buffer.size() && buffer[last] != '#')
{
ERR(" config parse error: bad line \"%s\"\n", buffer.c_str());
ERRFMT(" config parse error: bad line \"{}\"", buffer);
continue;
}
}
Expand Down Expand Up @@ -234,15 +234,15 @@ void LoadConfigFromFile(std::istream &f)
auto sep = buffer.find('=');
if(sep == std::string::npos)
{
ERR(" config parse error: malformed option line: \"%s\"\n", buffer.c_str());
ERRFMT(" config parse error: malformed option line: \"{}\"", buffer);
continue;
}
auto keypart = std::string_view{buffer}.substr(0, sep++);
while(!keypart.empty() && std::isspace(keypart.back()))
keypart.remove_suffix(1);
if(keypart.empty())
{
ERR(" config parse error: malformed option line: \"%s\"\n", buffer.c_str());
ERRFMT(" config parse error: malformed option line: \"{}\"", buffer);
continue;
}
auto valpart = std::string_view{buffer}.substr(sep);
Expand All @@ -259,7 +259,7 @@ void LoadConfigFromFile(std::istream &f)

if(valpart.size() > size_t{std::numeric_limits<int>::max()})
{
ERR(" config parse error: value too long in line \"%s\"\n", buffer.c_str());
ERRFMT(" config parse error: value too long in line \"{}\"", buffer);
continue;
}
if(valpart.size() > 1)
Expand All @@ -272,7 +272,7 @@ void LoadConfigFromFile(std::istream &f)
}
}

TRACE(" setting '%s' = '%.*s'\n", fullKey.c_str(), al::sizei(valpart), valpart.data());
TRACEFMT(" setting '{}' = '{}'", fullKey, valpart);

/* Check if we already have this option set */
auto find_key = [&fullKey](const ConfigEntry &entry) -> bool
Expand Down Expand Up @@ -315,7 +315,7 @@ auto GetConfigValue(const std::string_view devName, const std::string_view block
[&key](const ConfigEntry &entry) -> bool { return entry.key == key; });
if(iter != ConfOpts.cend())
{
TRACE("Found option %s = \"%s\"\n", key.c_str(), iter->value.c_str());
TRACEFMT("Found option {} = \"{}\"", key, iter->value);
if(!iter->value.empty())
return iter->value;
return emptyString;
Expand Down Expand Up @@ -353,8 +353,7 @@ void ReadALConfig()
path = fs::path{buffer};
path /= L"alsoft.ini";

TRACE("Loading config %s...\n",
reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -365,15 +364,15 @@ void ReadALConfig()
if(!path.empty())
{
path /= L"alsoft.ini";
TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}

if(auto confpath = al::getenv(L"ALSOFT_CONF"))
{
path = *confpath;
TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -386,7 +385,7 @@ void ReadALConfig()
namespace fs = std::filesystem;
fs::path path{"/etc/openal/alsoft.conf"};

TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);

Expand All @@ -411,14 +410,12 @@ void ReadALConfig()
}

if(!path.is_absolute())
WARN("Ignoring XDG config dir: %s\n",
reinterpret_cast<const char*>(path.u8string().c_str()));
WARNFMT("Ignoring XDG config dir: {}", al::u8_as_char(path.u8string()));
else
{
path /= "alsoft.conf";

TRACE("Loading config %s...\n",
reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -445,7 +442,7 @@ void ReadALConfig()
path = *homedir;
path /= ".alsoftrc";

TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -466,7 +463,7 @@ void ReadALConfig()
}
if(!path.empty())
{
TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -476,14 +473,14 @@ void ReadALConfig()
{
path /= "alsoft.conf";

TRACE("Loading config %s...\n", reinterpret_cast<const char*>(path.u8string().c_str()));
TRACEFMT("Loading config {}...", al::u8_as_char(path.u8string()));
if(std::ifstream f{path}; f.is_open())
LoadConfigFromFile(f);
}

if(auto confname = al::getenv("ALSOFT_CONF"))
{
TRACE("Loading config %s...\n", confname->c_str());
TRACEFMT("Loading config {}...", *confname);
if(std::ifstream f{*confname}; f.is_open())
LoadConfigFromFile(f);
}
Expand All @@ -505,7 +502,7 @@ auto ConfigValueInt(const std::string_view devName, const std::string_view block
return static_cast<int>(std::stol(val, nullptr, 0));
}
catch(std::exception&) {
WARN("Option is not an int: %.*s = %s\n", al::sizei(keyName), keyName.data(), val.c_str());
WARNFMT("Option is not an int: {} = {}", keyName, val);
}

return std::nullopt;
Expand All @@ -518,8 +515,7 @@ auto ConfigValueUInt(const std::string_view devName, const std::string_view bloc
return static_cast<unsigned int>(std::stoul(val, nullptr, 0));
}
catch(std::exception&) {
WARN("Option is not an unsigned int: %.*s = %s\n", al::sizei(keyName), keyName.data(),
val.c_str());
WARNFMT("Option is not an unsigned int: {} = {}", keyName, val);
}
return std::nullopt;
}
Expand All @@ -531,8 +527,7 @@ auto ConfigValueFloat(const std::string_view devName, const std::string_view blo
return std::stof(val);
}
catch(std::exception&) {
WARN("Option is not a float: %.*s = %s\n", al::sizei(keyName), keyName.data(),
val.c_str());
WARNFMT("Option is not a float: {} = {}", keyName, val);
}
return std::nullopt;
}
Expand Down
Loading

0 comments on commit ecc2e1b

Please sign in to comment.