From c35434e745f849302179992ee5f0b9fb90a1661c Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 31 May 2021 22:43:30 +0200 Subject: [PATCH] Simplify LOG macro. We only have one logger, no need to specify it every time. --- src/log.hpp | 2 +- src/main.cpp | 17 ++++++++--------- src/zip.cpp | 17 +++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/log.hpp b/src/log.hpp index b84af35..dee7886 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -21,7 +21,7 @@ #include #include -#define LOG BOOST_LOG_SEV +#define LOG(severity) BOOST_LOG_SEV(epubgrep::log::logger::get(), severity) namespace epubgrep::log { diff --git a/src/main.cpp b/src/main.cpp index f0e6e74..8b5d448 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,8 +66,7 @@ int main(int argc, char *argv[]) std::cerr.imbue(std::locale()); log::init(); - auto &lg{log::logger::get()}; - LOG(lg, log::sev::info) << "epubgrep " << version << " started."; + LOG(log::sev::info) << "epubgrep " << version << " started."; options::options opts; try @@ -76,7 +75,7 @@ int main(int argc, char *argv[]) } catch (std::exception &e) { // Exceptions we can't recover from or ones we don't know. - LOG(lg, log::sev::fatal) + LOG(log::sev::fatal) << e.what() << translate(" (while parsing options)"); return EXIT_FAILURE; } @@ -114,7 +113,7 @@ int main(int argc, char *argv[]) continue; } - LOG(lg, log::sev::error) + LOG(log::sev::error) << format(translate("Could not open {0:s}: {1:s}").str(), e.path1(), e.what()); return_code = EXIT_FAILURE; @@ -134,8 +133,8 @@ int main(int argc, char *argv[]) vector> futurepool; auto search_file{ - [&opts, &matches_all, &mutex_matches_all, &search_settings, - &lg](const fs::path &filepath) + [&opts, &matches_all, &mutex_matches_all, + &search_settings](const fs::path &filepath) { for (const auto ®ex : opts.regexp) { @@ -150,16 +149,16 @@ int main(int argc, char *argv[]) { if (opts.ignore_archive_errors && e.code == 1) { // File is probably not an EPUB. - LOG(lg, log::sev::info) << e.what(); + LOG(log::sev::info) << e.what(); return EXIT_SUCCESS; } - LOG(lg, log::sev::error) << e.what(); + LOG(log::sev::error) << e.what(); return EXIT_FAILURE; } catch (const std::ifstream::failure &e) { - LOG(lg, log::sev::error) + LOG(log::sev::error) << std::strerror(errno) << format(translate(" (while opening {0:s})").str(), filepath); diff --git a/src/zip.cpp b/src/zip.cpp index 0407631..4e9153a 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -52,7 +52,7 @@ std::vector list(const fs::path &filepath) const auto *in_epub_filepath{archive_entry_pathname_utf8(entry)}; if (in_epub_filepath == nullptr) { // If the encoding is broken, we skip the file. - LOG(log::logger::get(), log::sev::warning) + LOG(log::sev::warning) << format(translate("File in {0:s} is damaged. " "Skipping in-EPUB file.\n") .str() @@ -72,7 +72,6 @@ std::vector list(const fs::path &filepath) std::string read_file(const fs::path &filepath, std::string_view entry_path) { auto *zipfile{open_file(filepath)}; - auto &lg{log::logger::get()}; struct archive_entry *entry{}; while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK) @@ -80,7 +79,7 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path) const auto *path{archive_entry_pathname_utf8(entry)}; if (path == nullptr) { // If the encoding is broken, we skip the file. - LOG(lg, log::sev::warning) + LOG(log::sev::warning) << format(translate("File in {0:s} is damaged. " "Skipping in-EPUB file.\n") .str() @@ -122,7 +121,7 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path) throw exception{e}; } - LOG(lg, log::sev::warning) + LOG(log::sev::warning) << format(translate("{0:s} not found in {1:s}.").str(), entry_path, filepath.string()) << '\n'; @@ -167,10 +166,8 @@ void close_file(struct archive *zipfile, const fs::path &filepath) std::vector list_spine(const fs::path &filepath) { - auto &lg{log::logger::get()}; - const fs::path opf_file_path{ - [&filepath, &lg] + [&filepath] { pugi::xml_document xml; const std::string container{ @@ -184,7 +181,7 @@ std::vector list_spine(const fs::path &filepath) .attribute("full-path") .value(); } - LOG(lg, log::sev::error) << result.description() << '\n'; + LOG(log::sev::error) << result.description() << '\n'; return ""; }()}; @@ -225,13 +222,13 @@ std::vector list_spine(const fs::path &filepath) } else { - LOG(lg, log::sev::error) << "XML: " << result.description() << '\n'; + LOG(log::sev::error) << "XML: " << result.description() << '\n'; } } if (opf_file_path.empty() || spine_filepaths.empty()) { - LOG(lg, log::sev::error) + LOG(log::sev::error) << format(translate("{0:s} is damaged. Could not read spine. " "Skipping file.\n") .str()