Simplify LOG macro.
continuous-integration/drone/push Build is passing Details

We only have one logger, no need to specify it every time.
This commit is contained in:
tastytea 2021-05-31 22:43:30 +02:00
parent 5250b2974d
commit c35434e745
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 16 additions and 20 deletions

View File

@ -21,7 +21,7 @@
#include <boost/log/sources/logger.hpp> #include <boost/log/sources/logger.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#define LOG BOOST_LOG_SEV #define LOG(severity) BOOST_LOG_SEV(epubgrep::log::logger::get(), severity)
namespace epubgrep::log namespace epubgrep::log
{ {

View File

@ -66,8 +66,7 @@ int main(int argc, char *argv[])
std::cerr.imbue(std::locale()); std::cerr.imbue(std::locale());
log::init(); log::init();
auto &lg{log::logger::get()}; LOG(log::sev::info) << "epubgrep " << version << " started.";
LOG(lg, log::sev::info) << "epubgrep " << version << " started.";
options::options opts; options::options opts;
try try
@ -76,7 +75,7 @@ int main(int argc, char *argv[])
} }
catch (std::exception &e) catch (std::exception &e)
{ // Exceptions we can't recover from or ones we don't know. { // 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)"); << e.what() << translate(" (while parsing options)");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -114,7 +113,7 @@ int main(int argc, char *argv[])
continue; continue;
} }
LOG(lg, log::sev::error) LOG(log::sev::error)
<< format(translate("Could not open {0:s}: {1:s}").str(), << format(translate("Could not open {0:s}: {1:s}").str(),
e.path1(), e.what()); e.path1(), e.what());
return_code = EXIT_FAILURE; return_code = EXIT_FAILURE;
@ -134,8 +133,8 @@ int main(int argc, char *argv[])
vector<std::future<int>> futurepool; vector<std::future<int>> futurepool;
auto search_file{ auto search_file{
[&opts, &matches_all, &mutex_matches_all, &search_settings, [&opts, &matches_all, &mutex_matches_all,
&lg](const fs::path &filepath) &search_settings](const fs::path &filepath)
{ {
for (const auto &regex : opts.regexp) for (const auto &regex : opts.regexp)
{ {
@ -150,16 +149,16 @@ int main(int argc, char *argv[])
{ {
if (opts.ignore_archive_errors && e.code == 1) if (opts.ignore_archive_errors && e.code == 1)
{ // File is probably not an EPUB. { // File is probably not an EPUB.
LOG(lg, log::sev::info) << e.what(); LOG(log::sev::info) << e.what();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
LOG(lg, log::sev::error) << e.what(); LOG(log::sev::error) << e.what();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch (const std::ifstream::failure &e) catch (const std::ifstream::failure &e)
{ {
LOG(lg, log::sev::error) LOG(log::sev::error)
<< std::strerror(errno) << std::strerror(errno)
<< format(translate(" (while opening {0:s})").str(), << format(translate(" (while opening {0:s})").str(),
filepath); filepath);

View File

@ -52,7 +52,7 @@ std::vector<std::string> list(const fs::path &filepath)
const auto *in_epub_filepath{archive_entry_pathname_utf8(entry)}; const auto *in_epub_filepath{archive_entry_pathname_utf8(entry)};
if (in_epub_filepath == nullptr) if (in_epub_filepath == nullptr)
{ // If the encoding is broken, we skip the file. { // 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. " << format(translate("File in {0:s} is damaged. "
"Skipping in-EPUB file.\n") "Skipping in-EPUB file.\n")
.str() .str()
@ -72,7 +72,6 @@ std::vector<std::string> list(const fs::path &filepath)
std::string read_file(const fs::path &filepath, std::string_view entry_path) std::string read_file(const fs::path &filepath, std::string_view entry_path)
{ {
auto *zipfile{open_file(filepath)}; auto *zipfile{open_file(filepath)};
auto &lg{log::logger::get()};
struct archive_entry *entry{}; struct archive_entry *entry{};
while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK) 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)}; const auto *path{archive_entry_pathname_utf8(entry)};
if (path == nullptr) if (path == nullptr)
{ // If the encoding is broken, we skip the file. { // 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. " << format(translate("File in {0:s} is damaged. "
"Skipping in-EPUB file.\n") "Skipping in-EPUB file.\n")
.str() .str()
@ -122,7 +121,7 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path)
throw exception{e}; throw exception{e};
} }
LOG(lg, log::sev::warning) LOG(log::sev::warning)
<< format(translate("{0:s} not found in {1:s}.").str(), entry_path, << format(translate("{0:s} not found in {1:s}.").str(), entry_path,
filepath.string()) filepath.string())
<< '\n'; << '\n';
@ -167,10 +166,8 @@ void close_file(struct archive *zipfile, const fs::path &filepath)
std::vector<std::string> list_spine(const fs::path &filepath) std::vector<std::string> list_spine(const fs::path &filepath)
{ {
auto &lg{log::logger::get()};
const fs::path opf_file_path{ const fs::path opf_file_path{
[&filepath, &lg] [&filepath]
{ {
pugi::xml_document xml; pugi::xml_document xml;
const std::string container{ const std::string container{
@ -184,7 +181,7 @@ std::vector<std::string> list_spine(const fs::path &filepath)
.attribute("full-path") .attribute("full-path")
.value(); .value();
} }
LOG(lg, log::sev::error) << result.description() << '\n'; LOG(log::sev::error) << result.description() << '\n';
return ""; return "";
}()}; }()};
@ -225,13 +222,13 @@ std::vector<std::string> list_spine(const fs::path &filepath)
} }
else 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()) 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. " << format(translate("{0:s} is damaged. Could not read spine. "
"Skipping file.\n") "Skipping file.\n")
.str() .str()