Browse Source

Use helper function for logging messages

adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
dba711d099
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 2
      src/app/application.cpp
  2. 4
      src/base/http/connection.cpp
  3. 22
      src/base/net/dnsupdater.cpp
  4. 4
      src/base/net/geoipmanager.cpp
  5. 2
      src/base/net/smtp.cpp
  6. 8
      src/base/settingsstorage.cpp
  7. 4
      src/gui/mainwindow.cpp
  8. 9
      src/webui/webui.cpp

2
src/app/application.cpp

@ -471,7 +471,7 @@ void Application::torrentFinished(BitTorrent::Torrent *const torrent)
// Mail notification // Mail notification
if (pref->isMailNotificationEnabled()) if (pref->isMailNotificationEnabled())
{ {
Logger::instance()->addMessage(tr("Torrent: %1, sending mail notification").arg(torrent->name())); LogMsg(tr("Torrent: %1, sending mail notification").arg(torrent->name()));
sendNotificationEmail(torrent); sendNotificationEmail(torrent);
} }
} }

4
src/base/http/connection.cpp

@ -79,7 +79,7 @@ void Connection::read()
const long bufferLimit = RequestParser::MAX_CONTENT_SIZE * 1.1; // some margin for headers const long bufferLimit = RequestParser::MAX_CONTENT_SIZE * 1.1; // some margin for headers
if (m_receivedData.size() > bufferLimit) if (m_receivedData.size() > bufferLimit)
{ {
Logger::instance()->addMessage(tr("Http request size exceeds limitation, closing socket. Limit: %1, IP: %2") LogMsg(tr("Http request size exceeds limitation, closing socket. Limit: %1, IP: %2")
.arg(bufferLimit).arg(m_socket->peerAddress().toString()), Log::WARNING); .arg(bufferLimit).arg(m_socket->peerAddress().toString()), Log::WARNING);
Response resp(413, u"Payload Too Large"_qs); Response resp(413, u"Payload Too Large"_qs);
@ -93,7 +93,7 @@ void Connection::read()
case RequestParser::ParseStatus::BadRequest: case RequestParser::ParseStatus::BadRequest:
{ {
Logger::instance()->addMessage(tr("Bad Http request, closing socket. IP: %1") LogMsg(tr("Bad Http request, closing socket. IP: %1")
.arg(m_socket->peerAddress().toString()), Log::WARNING); .arg(m_socket->peerAddress().toString()), Log::WARNING);
Response resp(400, u"Bad Request"_qs); Response resp(400, u"Bad Request"_qs);

22
src/base/net/dnsupdater.cpp

@ -180,20 +180,19 @@ void DNSUpdater::ipUpdateFinished(const DownloadResult &result)
void DNSUpdater::processIPUpdateReply(const QString &reply) void DNSUpdater::processIPUpdateReply(const QString &reply)
{ {
Logger *const logger = Logger::instance();
qDebug() << Q_FUNC_INFO << reply; qDebug() << Q_FUNC_INFO << reply;
const QString code = reply.split(u' ').first(); const QString code = reply.split(u' ').first();
qDebug() << Q_FUNC_INFO << "Code:" << code; qDebug() << Q_FUNC_INFO << "Code:" << code;
if ((code == u"good") || (code == u"nochg")) if ((code == u"good") || (code == u"nochg"))
{ {
logger->addMessage(tr("Your dynamic DNS was successfully updated."), Log::INFO); LogMsg(tr("Your dynamic DNS was successfully updated."), Log::INFO);
return; return;
} }
if ((code == u"911") || (code == u"dnserr")) if ((code == u"911") || (code == u"dnserr"))
{ {
logger->addMessage(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), Log::CRITICAL);
m_lastIP.clear(); m_lastIP.clear();
// It will retry in 30 minutes because the timer was not stopped // It will retry in 30 minutes because the timer was not stopped
return; return;
@ -204,21 +203,21 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
m_lastIP.clear(); m_lastIP.clear();
if (code == u"nohost") if (code == u"nohost")
{ {
logger->addMessage(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), Log::CRITICAL);
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
return; return;
} }
if (code == u"badauth") if (code == u"badauth")
{ {
logger->addMessage(tr("Dynamic DNS error: Invalid username/password."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: Invalid username/password."), Log::CRITICAL);
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
return; return;
} }
if (code == u"badagent") if (code == u"badagent")
{ {
logger->addMessage(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please submit a bug report at http://bugs.qbittorrent.org."), LogMsg(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please submit a bug report at http://bugs.qbittorrent.org."),
Log::CRITICAL); Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
return; return;
@ -226,7 +225,7 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
if (code == u"!donator") if (code == u"!donator")
{ {
logger->addMessage(tr("Dynamic DNS error: %1 was returned by the service, please submit a bug report at http://bugs.qbittorrent.org.").arg(u"!donator"_qs), LogMsg(tr("Dynamic DNS error: %1 was returned by the service, please submit a bug report at http://bugs.qbittorrent.org.").arg(u"!donator"_qs),
Log::CRITICAL); Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
return; return;
@ -234,7 +233,7 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
if (code == u"abuse") if (code == u"abuse")
{ {
logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
} }
} }
@ -243,7 +242,6 @@ void DNSUpdater::updateCredentials()
{ {
if (m_state == FATAL) return; if (m_state == FATAL) return;
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
Logger *const logger = Logger::instance();
bool change = false; bool change = false;
// Get DNS service information // Get DNS service information
if (m_service != pref->getDynDNSService()) if (m_service != pref->getDynDNSService())
@ -257,7 +255,7 @@ void DNSUpdater::updateCredentials()
const QRegularExpressionMatch domainRegexMatch = QRegularExpression(u"^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"_qs).match(m_domain); const QRegularExpressionMatch domainRegexMatch = QRegularExpression(u"^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"_qs).match(m_domain);
if (!domainRegexMatch.hasMatch()) if (!domainRegexMatch.hasMatch())
{ {
logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL);
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
@ -270,7 +268,7 @@ void DNSUpdater::updateCredentials()
m_username = pref->getDynDNSUsername(); m_username = pref->getDynDNSUsername();
if (m_username.length() < 4) if (m_username.length() < 4)
{ {
logger->addMessage(tr("Dynamic DNS error: supplied username is too short."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: supplied username is too short."), Log::CRITICAL);
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
@ -283,7 +281,7 @@ void DNSUpdater::updateCredentials()
m_password = pref->getDynDNSPassword(); m_password = pref->getDynDNSPassword();
if (m_password.length() < 4) if (m_password.length() < 4)
{ {
logger->addMessage(tr("Dynamic DNS error: supplied password is too short."), Log::CRITICAL); LogMsg(tr("Dynamic DNS error: supplied password is too short."), Log::CRITICAL);
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;

4
src/base/net/geoipmanager.cpp

@ -93,13 +93,13 @@ void GeoIPManager::loadDatabase()
m_geoIPDatabase = GeoIPDatabase::load(filepath, error); m_geoIPDatabase = GeoIPDatabase::load(filepath, error);
if (m_geoIPDatabase) if (m_geoIPDatabase)
{ {
Logger::instance()->addMessage(tr("IP geolocation database loaded. Type: %1. Build time: %2.") LogMsg(tr("IP geolocation database loaded. Type: %1. Build time: %2.")
.arg(m_geoIPDatabase->type(), m_geoIPDatabase->buildEpoch().toString()), .arg(m_geoIPDatabase->type(), m_geoIPDatabase->buildEpoch().toString()),
Log::INFO); Log::INFO);
} }
else else
{ {
Logger::instance()->addMessage(tr("Couldn't load IP geolocation database. Reason: %1").arg(error), Log::WARNING); LogMsg(tr("Couldn't load IP geolocation database. Reason: %1").arg(error), Log::WARNING);
} }
manageDatabaseUpdate(); manageDatabaseUpdate();

2
src/base/net/smtp.cpp

@ -560,7 +560,7 @@ void Smtp::authLogin()
void Smtp::logError(const QString &msg) void Smtp::logError(const QString &msg)
{ {
qDebug() << "Email Notification Error:" << msg; qDebug() << "Email Notification Error:" << msg;
Logger::instance()->addMessage(tr("Email Notification Error: %1").arg(msg), Log::WARNING); LogMsg(tr("Email Notification Error: %1").arg(msg), Log::WARNING);
} }
QString Smtp::getCurrentDateTime() const QString Smtp::getCurrentDateTime() const

8
src/base/settingsstorage.cpp

@ -168,7 +168,7 @@ QVariantHash TransactionalSettings::read() const
// or because the disk was full. In any case the settings weren't transferred // or because the disk was full. In any case the settings weren't transferred
// in their final position. So assume that qbittorrent_new.ini/qbittorrent_new.conf // in their final position. So assume that qbittorrent_new.ini/qbittorrent_new.conf
// contains the most recent settings. // contains the most recent settings.
Logger::instance()->addMessage(QObject::tr("Detected unclean program exit. Using fallback file to restore settings: %1") LogMsg(QObject::tr("Detected unclean program exit. Using fallback file to restore settings: %1")
.arg(newPath.toString()) .arg(newPath.toString())
, Log::WARNING); , Log::WARNING);
@ -244,13 +244,13 @@ Path TransactionalSettings::serialize(const QString &name, const QVariantHash &d
case QSettings::NoError: case QSettings::NoError:
return Path(settings->fileName()); return Path(settings->fileName());
case QSettings::AccessError: case QSettings::AccessError:
Logger::instance()->addMessage(QObject::tr("An access error occurred while trying to write the configuration file."), Log::CRITICAL); LogMsg(QObject::tr("An access error occurred while trying to write the configuration file."), Log::CRITICAL);
break; break;
case QSettings::FormatError: case QSettings::FormatError:
Logger::instance()->addMessage(QObject::tr("A format error occurred while trying to write the configuration file."), Log::CRITICAL); LogMsg(QObject::tr("A format error occurred while trying to write the configuration file."), Log::CRITICAL);
break; break;
default: default:
Logger::instance()->addMessage(QObject::tr("An unknown error occurred while trying to write the configuration file."), Log::CRITICAL); LogMsg(QObject::tr("An unknown error occurred while trying to write the configuration file."), Log::CRITICAL);
break; break;
} }
return {}; return {};

4
src/gui/mainwindow.cpp

@ -1106,7 +1106,7 @@ void MainWindow::notifyOfUpdate(const QString &)
{ {
// Show restart message // Show restart message
m_statusBar->showRestartRequired(); m_statusBar->showRestartRequired();
Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective.") LogMsg(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective.")
, Log::CRITICAL); , Log::CRITICAL);
// Delete the executable watcher // Delete the executable watcher
delete m_executableWatcher; delete m_executableWatcher;
@ -1499,7 +1499,7 @@ void MainWindow::activate()
void MainWindow::optionsSaved() void MainWindow::optionsSaved()
{ {
Logger::instance()->addMessage(tr("Options saved.")); LogMsg(tr("Options saved."));
loadPreferences(); loadPreferences();
} }

9
src/webui/webui.cpp

@ -50,7 +50,6 @@ void WebUI::configure()
{ {
m_isErrored = false; // clear previous error state m_isErrored = false; // clear previous error state
Logger *const logger = Logger::instance();
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
const quint16 oldPort = m_port; const quint16 oldPort = m_port;
@ -100,9 +99,9 @@ void WebUI::configure()
const bool success = m_httpServer->setupHttps(cert, key); const bool success = m_httpServer->setupHttps(cert, key);
if (success) if (success)
logger->addMessage(tr("Web UI: HTTPS setup successful")); LogMsg(tr("Web UI: HTTPS setup successful"));
else else
logger->addMessage(tr("Web UI: HTTPS setup failed, fallback to HTTP"), Log::CRITICAL); LogMsg(tr("Web UI: HTTPS setup failed, fallback to HTTP"), Log::CRITICAL);
} }
else else
{ {
@ -116,13 +115,13 @@ void WebUI::configure()
bool success = m_httpServer->listen(address, m_port); bool success = m_httpServer->listen(address, m_port);
if (success) if (success)
{ {
logger->addMessage(tr("Web UI: Now listening on IP: %1, port: %2").arg(serverAddressString).arg(m_port)); LogMsg(tr("Web UI: Now listening on IP: %1, port: %2").arg(serverAddressString).arg(m_port));
} }
else else
{ {
const QString errorMsg = tr("Web UI: Unable to bind to IP: %1, port: %2. Reason: %3") const QString errorMsg = tr("Web UI: Unable to bind to IP: %1, port: %2. Reason: %3")
.arg(serverAddressString).arg(m_port).arg(m_httpServer->errorString()); .arg(serverAddressString).arg(m_port).arg(m_httpServer->errorString());
logger->addMessage(errorMsg, Log::CRITICAL); LogMsg(errorMsg, Log::CRITICAL);
qCritical() << errorMsg; qCritical() << errorMsg;
m_isErrored = true; m_isErrored = true;

Loading…
Cancel
Save