Partition, ...: use libfmt for logging

This commit is contained in:
Max Kellermann
2021-06-24 20:22:48 +02:00
parent 0185d58a2b
commit 6f539cfcd6
44 changed files with 320 additions and 296 deletions

View File

@@ -23,6 +23,7 @@
#include "db/plugins/simple/Directory.hxx"
#include "db/plugins/simple/Song.hxx"
#include "storage/StorageInterface.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "fs/AllocatedPath.hxx"
#include "storage/FileInfo.hxx"
#include "archive/ArchiveList.hxx"
@@ -82,14 +83,14 @@ UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
}
modified = true;
FormatNotice(update_domain, "added %s/%s",
directory.GetPath(), name);
FmtNotice(update_domain, "added {}/{}",
directory.GetPath(), name);
}
} else {
if (!song->UpdateFileInArchive(archive)) {
FormatDebug(update_domain,
"deleting unrecognized file %s/%s",
directory.GetPath(), name);
FmtDebug(update_domain,
"deleting unrecognized file {}/{}",
directory.GetPath(), name);
editor.LockDeleteSong(directory, song);
}
}
@@ -107,8 +108,8 @@ class UpdateArchiveVisitor final : public ArchiveVisitor {
:walk(_walk), archive(_archive), directory(_directory) {}
void VisitArchiveEntry(const char *path_utf8) override {
FormatDebug(update_domain,
"adding archive file: %s", path_utf8);
FmtDebug(update_domain,
"adding archive file: {}", path_utf8);
walk.UpdateArchiveTree(archive, directory, path_utf8);
}
};
@@ -149,7 +150,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, std::string_view name,
return;
}
FormatDebug(update_domain, "archive %s opened", path_fs.c_str());
FmtDebug(update_domain, "archive {} opened", path_fs);
UpdateArchiveVisitor visitor(*this, *file, *directory);
file->Visit(visitor);

View File

@@ -75,9 +75,9 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
// shouldn't be necessary but it's there..
song->mtime = info.mtime;
FormatNotice(update_domain, "added %s/%s",
contdir->GetPath(),
song->filename.c_str());
FmtNotice(update_domain, "added {}/{}",
contdir->GetPath(),
song->filename);
{
const ScopeDatabaseLock protect;

View File

@@ -20,9 +20,11 @@
#include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "Service.hxx"
#include "Log.hxx"
#include "UpdateDomain.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "protocol/Ack.hxx" // for class ProtocolError
#include "util/StringCompare.hxx"
#include "Log.hxx"
/**
* Wait this long after the last change before calling
@@ -53,14 +55,15 @@ InotifyQueue::OnDelay() noexcept
throw;
}
} catch (...) {
FormatError(std::current_exception(),
"Failed to enqueue '%s'", uri_utf8);
FmtError(update_domain,
"Failed to enqueue '{}': {}",
uri_utf8, std::current_exception());
queue.pop_front();
continue;
}
FormatDebug(inotify_domain, "updating '%s' job=%u",
uri_utf8, id);
FmtDebug(inotify_domain, "updating '{}' job={}",
uri_utf8, id);
queue.pop_front();
}

View File

@@ -22,6 +22,8 @@
#include "InotifyQueue.hxx"
#include "InotifyDomain.hxx"
#include "ExcludeList.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "lib/fmt/PathFormatter.hxx"
#include "storage/StorageInterface.hxx"
#include "input/InputStream.hxx"
#include "input/Error.hxx"
@@ -223,9 +225,9 @@ try {
ret = inotify_source->Add(child_path_fs.c_str(),
IN_MASK);
} catch (...) {
FormatError(std::current_exception(),
"Failed to register %s",
child_path_fs.c_str());
FmtError(inotify_domain,
"Failed to register %s: {}",
child_path_fs, std::current_exception());
continue;
}

View File

@@ -22,6 +22,7 @@
#include "db/DatabaseLock.hxx"
#include "db/PlaylistVector.hxx"
#include "db/plugins/simple/Directory.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "song/DetachedSong.hxx"
#include "input/InputStream.hxx"
#include "playlist/PlaylistPlugin.hxx"
@@ -49,7 +50,7 @@ UpdateWalk::UpdatePlaylistFile(Directory &parent, std::string_view name,
const auto uri_utf8 = storage.MapUTF8(directory->GetPath());
FormatDebug(update_domain, "scanning playlist '%s'", uri_utf8.c_str());
FmtDebug(update_domain, "scanning playlist '{}'", uri_utf8);
try {
Mutex mutex;
@@ -80,8 +81,9 @@ UpdateWalk::UpdatePlaylistFile(Directory &parent, std::string_view name,
}
}
} catch (...) {
FormatError(std::current_exception(),
"Failed to scan playlist '%s'", uri_utf8.c_str());
FmtError(update_domain,
"Failed to scan playlist '{}': {}",
uri_utf8, std::current_exception());
editor.LockDeleteDirectory(directory);
}
}

View File

@@ -41,7 +41,7 @@ UpdateRemoveService::RunDeferred() noexcept
}
for (const auto &uri : copy) {
FormatNotice(update_domain, "removing %s", uri.c_str());
FmtNotice(update_domain, "removing {}", uri);
listener.OnDatabaseSongRemoved(uri.c_str());
}

View File

@@ -20,6 +20,7 @@
#include "Walk.hxx"
#include "UpdateIO.hxx"
#include "UpdateDomain.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "db/DatabaseLock.hxx"
#include "db/plugins/simple/Directory.hxx"
#include "db/plugins/simple/Song.hxx"
@@ -41,9 +42,9 @@ try {
}
if (!directory_child_access(storage, directory, name, R_OK)) {
FormatError(update_domain,
"no read permissions on %s/%s",
directory.GetPath(), name);
FmtError(update_domain,
"no read permissions on {}/{}",
directory.GetPath(), name);
if (song != nullptr)
editor.LockDeleteSong(directory, song);
@@ -59,14 +60,14 @@ try {
}
if (song == nullptr) {
FormatDebug(update_domain, "reading %s/%s",
directory.GetPath(), name);
FmtDebug(update_domain, "reading {}/{}",
directory.GetPath(), name);
auto new_song = Song::LoadFile(storage, name, directory);
if (!new_song) {
FormatDebug(update_domain,
"ignoring unrecognized file %s/%s",
directory.GetPath(), name);
FmtDebug(update_domain,
"ignoring unrecognized file {}/{}",
directory.GetPath(), name);
return;
}
@@ -76,24 +77,24 @@ try {
}
modified = true;
FormatNotice(update_domain, "added %s/%s",
directory.GetPath(), name);
FmtNotice(update_domain, "added {}/{}",
directory.GetPath(), name);
} else if (info.mtime != song->mtime || walk_discard) {
FormatNotice(update_domain, "updating %s/%s",
directory.GetPath(), name);
FmtNotice(update_domain, "updating {}/{}",
directory.GetPath(), name);
if (!song->UpdateFile(storage)) {
FormatDebug(update_domain,
"deleting unrecognized file %s/%s",
directory.GetPath(), name);
FmtDebug(update_domain,
"deleting unrecognized file {}/{}",
directory.GetPath(), name);
editor.LockDeleteSong(directory, song);
}
modified = true;
}
} catch (...) {
FormatError(std::current_exception(),
"error reading file %s/%s",
directory.GetPath(), name);
FmtError(update_domain,
"error reading file {}/{}: {}",
directory.GetPath(), name, std::current_exception());
}
bool

View File

@@ -223,8 +223,8 @@ try {
if (!UpdateDirectory(*subdir, exclude_list, info))
editor.LockDeleteDirectory(subdir);
} else {
FormatDebug(update_domain,
"%s is not a directory, archive or music", name);
FmtDebug(update_domain,
"{} is not a directory, archive or music", name);
}
} catch (...) {
LogError(std::current_exception());
@@ -520,8 +520,8 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
return false;
if (!info.IsDirectory()) {
FormatError(update_domain, "Not a directory: %s",
storage.MapUTF8("").c_str());
FmtError(update_domain, "Not a directory: {}",
storage.MapUTF8(""));
return false;
}