diff --git a/conf/lms.conf b/conf/lms.conf index 34ca1c9f..649582e7 100644 --- a/conf/lms.conf +++ b/conf/lms.conf @@ -20,12 +20,15 @@ wt-resources="/usr/share/Wt/resources"; docroot = "/usr/share/lms/docroot/;/resources,/css,/images,/js,/favicon.ico"; approot = "/usr/share/lms/approot"; -# Turn on this option to allow the demo account creation/use -#demo = false; - # Acoustic brainz's root API acousticbrainz-api-url = "https://acousticbrainz.org/api/v1/"; # API api-subsonic = true; +# Logger configuration, see log-config in https://webtoolkit.eu/wt/doc/reference/html/overview.html#config_general +log-config = "* -debug -info:WebRequest"; + +# Turn on this option to allow the demo account creation/use +demo = false; + diff --git a/src/av/AvTranscoder.cpp b/src/av/AvTranscoder.cpp index 1a37cb56..73d55cae 100644 --- a/src/av/AvTranscoder.cpp +++ b/src/av/AvTranscoder.cpp @@ -28,7 +28,7 @@ namespace Av { -#define LMS_LOG_TRANSCODE(sev) LMS_LOG(TRANSCODE, INFO) << "[" << _id << "] - " +#define LMS_LOG_TRANSCODE(sev) LMS_LOG(TRANSCODE, sev) << "[" << _id << "] - " // TODO, parametrize? static const std::vector execNames = @@ -179,7 +179,7 @@ Transcoder::start() args.push_back("pipe:1"); - LMS_LOG_TRANSCODE(INFO) << "Dumping args (" << args.size() << ")"; + LMS_LOG_TRANSCODE(DEBUG) << "Dumping args (" << args.size() << ")"; for (std::string arg : args) LMS_LOG_TRANSCODE(DEBUG) << "Arg = '" << arg << "'"; diff --git a/src/main/main.cpp b/src/main/main.cpp index 89fb3be6..a63b0c47 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -70,6 +70,7 @@ std::vector generateWtConfig(std::string execPath) pt.put("server.application-settings..location", "*"); pt.put("server.application-settings.log-file", wtLogFilePath.string()); + pt.put("server.application-settings.log-config", Config::instance().getString("log-level", "info -info:WebRequest")); pt.put("server.application-settings.behind-reverse-proxy", Config::instance().getBool("behind-reverse-proxy", false)); pt.put("server.application-settings.progressive-bootstrap", true); @@ -115,8 +116,6 @@ int main(int argc, char* argv[]) Wt::WServer server(argv[0]); server.setServerConfiguration (wtServerArgs.size(), const_cast(wtArgv)); - Wt::WServer::instance()->logger().configure("*"); // log everything, TODO configure this - // lib init Image::init(argv[0]); Av::AvInit(); diff --git a/src/scanner/MediaScanner.cpp b/src/scanner/MediaScanner.cpp index 61323d46..59d6f498 100644 --- a/src/scanner/MediaScanner.cpp +++ b/src/scanner/MediaScanner.cpp @@ -242,7 +242,6 @@ MediaScanner::requestImmediateScan() { _ioService.post([=]() { - LMS_LOG(DBUPDATER, INFO) << "Schedule immediate scan"; scheduleScan(); }); } @@ -252,7 +251,6 @@ MediaScanner::requestReschedule() { _ioService.post([=]() { - LMS_LOG(DBUPDATER, INFO) << "Rescheduling scan"; scheduleNextScan(); }); } @@ -274,6 +272,8 @@ MediaScanner::getStatus() void MediaScanner::scheduleNextScan() { + LMS_LOG(DBUPDATER, INFO) << "Scheduling next scan"; + refreshScanSettings(); Wt::WDateTime now = Wt::WLocalDateTime::currentServerDateTime().toUTC(); diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp index 98563177..87c40549 100644 --- a/src/ui/LmsApplication.cpp +++ b/src/ui/LmsApplication.cpp @@ -562,7 +562,7 @@ static std::string escape(std::string str) void LmsApplication::notifyMsg(MsgType type, const Wt::WString& message, std::chrono::milliseconds duration) { - LMS_LOG(UI, INFO) << "Notifying message '" << message.toUTF8() << "' of type '" << msgTypeToString(type); + LMS_LOG(UI, INFO) << "Notifying message '" << message.toUTF8() << "' of type '" << msgTypeToString(type) << "'"; std::ostringstream oss; diff --git a/src/utils/Config.cpp b/src/utils/Config.cpp index 3c39b89f..73566636 100644 --- a/src/utils/Config.cpp +++ b/src/utils/Config.cpp @@ -21,20 +21,8 @@ #include -namespace { +#include "utils/Logger.hpp" -} - -Config::Config() -: _config (nullptr) -{ -} - -Config::~Config() -{ - if (_config) - delete _config; -} Config& Config::instance() @@ -44,21 +32,25 @@ Config::instance() } void -Config::setFile(boost::filesystem::path p) +Config::setFile(const boost::filesystem::path& p) { - if (_config != nullptr) - delete _config; - - _config = new libconfig::Config(); - + _config = std::make_unique(); _config->readFile(p.string().c_str()); } std::string -Config::getString(std::string setting, std::string def) +Config::getString(const std::string& setting, const std::string& def, const std::set& allowedValues) { try { - return _config->lookup(setting); + std::string res {(const char*)_config->lookup(setting)}; + + if (!allowedValues.empty() && allowedValues.find(res) == allowedValues.end()) + { + LMS_LOG(MAIN, ERROR) << "Invalid setting for '" << setting << "', using default value '" << def << "'"; + return def; + } + + return res; } catch (std::exception &e) { @@ -67,7 +59,7 @@ Config::getString(std::string setting, std::string def) } boost::filesystem::path -Config::getPath(std::string setting, boost::filesystem::path path) +Config::getPath(const std::string& setting, const boost::filesystem::path& path) { try { const char* res = _config->lookup(setting); @@ -80,7 +72,7 @@ Config::getPath(std::string setting, boost::filesystem::path path) } unsigned long -Config::getULong(std::string setting, unsigned long def) +Config::getULong(const std::string& setting, unsigned long def) { try { return static_cast(_config->lookup(setting)); @@ -92,7 +84,7 @@ Config::getULong(std::string setting, unsigned long def) } long -Config::getLong(std::string setting, long def) +Config::getLong(const std::string& setting, long def) { try { return _config->lookup(setting); @@ -104,7 +96,7 @@ Config::getLong(std::string setting, long def) } bool -Config::getBool(std::string setting, bool def) +Config::getBool(const std::string& setting, bool def) { try { return _config->lookup(setting); diff --git a/src/utils/Config.hpp b/src/utils/Config.hpp index 799e772a..13473e11 100644 --- a/src/utils/Config.hpp +++ b/src/utils/Config.hpp @@ -18,34 +18,36 @@ */ #pragma once +#include #include #include // Used to get config values from configuration files -class Config +class Config final { public: Config(const Config&) = delete; Config& operator=(const Config&) = delete; + Config(Config&&) = delete; + Config& operator=(Config&&) = delete; static Config& instance(); - void setFile(boost::filesystem::path p); + void setFile(const boost::filesystem::path& p); // Default values are returned in case of setting not found - std::string getString(std::string setting, std::string def = ""); - boost::filesystem::path getPath(std::string setting, boost::filesystem::path def = boost::filesystem::path()); - unsigned long getULong(std::string setting, unsigned long def = 0); - long getLong(std::string setting, long def = 0); - bool getBool(std::string setting, bool def = false); + std::string getString(const std::string& setting, const std::string& def = "", const std::set& allowedValues = {}); + boost::filesystem::path getPath(const std::string& setting, const boost::filesystem::path& def = boost::filesystem::path()); + unsigned long getULong(const std::string& setting, unsigned long def = 0); + long getLong(const std::string& setting, long def = 0); + bool getBool(const std::string& setting, bool def = false); private: - Config(); - ~Config(); + Config() = default; - libconfig::Config *_config; + std::unique_ptr _config; };