From 12a1c472593a70b2d0d7a3752d4a737784af52c8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 1 Jun 2021 11:07:34 +0200 Subject: [PATCH] Make log_path a variable again. We don't need log_dir() twice afterall. --- src/log.cpp | 40 ++++++++++++++++++++-------------------- src/log.hpp | 2 -- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 6f376c5..4a7a6a1 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -39,29 +39,29 @@ using sev = boost::log::trivial::severity_level; inline static global_variables global; -fs::path log_dir() -{ - fs::path path{helpers::get_env("XDG_STATE_HOME")}; - if (path.empty()) - { - path = helpers::get_env("HOME"); - if (!path.empty()) - { - path /= ".local"; - path /= "state"; - } - } - if (!path.empty()) - { - return path /= "epubgrep"; - } - return fs::path{}; -} - void init() { + const auto log_path{[] + { + fs::path path{helpers::get_env("XDG_STATE_HOME")}; + if (path.empty()) + { + path = helpers::get_env("HOME"); + if (!path.empty()) + { + path /= ".local"; + path /= "state"; + } + } + if (!path.empty()) + { + path /= "epubgrep"; + } + return path / "epubgrep.log"; + }()}; + global.textlog = blog::add_file_log( - keywords::file_name = (log_dir() / "epubgrep.log").c_str(), + keywords::file_name = log_path.c_str(), keywords::format = "%LineID% [%TimeStamp%] " "[%ThreadID%]: [%Severity%] %Message%"); global.textlog->set_filter(blog::trivial::severity >= sev::info); diff --git a/src/log.hpp b/src/log.hpp index 338ed95..64919ba 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -45,8 +45,6 @@ struct global_variables BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT( logger, boost::log::sources::severity_logger_mt) -fs::path log_dir(); - void init(); void init_debug();