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/trivial.hpp>
#define LOG BOOST_LOG_SEV
#define LOG(severity) BOOST_LOG_SEV(epubgrep::log::logger::get(), severity)
namespace epubgrep::log
{

View File

@ -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<std::future<int>> 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 &regex : 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);

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)};
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<std::string> 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<std::string> 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<std::string> 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<std::string> 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()