Adjust logged messages

This commit is contained in:
Matti Viljanen 2021-04-24 18:27:37 +03:00
parent 591eb3ff10
commit fa7c24568a
No known key found for this signature in database
GPG key ID: CF32A1495158F888
4 changed files with 22 additions and 20 deletions

View file

@ -94,20 +94,14 @@ int main(int argc, char *argv[])
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml")); view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));
view->showFullScreen(); view->showFullScreen();
logV("Launching GUI...");
int retval = app->exec(); int retval = app->exec();
logV("Exiting...");
updater->stop(); updater->stop();
delete updater; delete updater;
delete battery; delete battery;
delete settings; delete settings;
logV("Goodbye!");
delete logger; delete logger;
return retval; return retval;

View file

@ -57,7 +57,7 @@ Settings::~Settings()
mySettings->setValue(sNotificationLowText, notificationLowText); mySettings->setValue(sNotificationLowText, notificationLowText);
mySettings->setValue(sNotificationHighText, notificationHighText); mySettings->setValue(sNotificationHighText, notificationHighText);
mySettings->sync(); mySettings->sync();
logV(QString("Settings saved: %1").arg((mySettings->status() == QSettings::NoError) ? "true" : "false")); logV(QString("Settings saved: %1").arg(mySettings->status() == QSettings::NoError));
} }
// Getters condensed. // Getters condensed.

View file

@ -27,7 +27,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
int logLevel = settings->getLogLevel(); int logLevel = settings->getLogLevel();
logger->debug = (logLevel == 2); logger->debug = (logLevel == 2);
logger->verbose = (logLevel > 1); logger->verbose = (logLevel > 1);
logE(QString("Log level set to %1").arg(logLevel)); logE(QString("Log level set to %1").arg((logLevel == 0 ? "low" : (logLevel == 1 ? "medium" : "high"))));
} }
updateTimer = new QTimer(this); updateTimer = new QTimer(this);
@ -37,20 +37,20 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
// Number: charge percentage, e.g. 42 // Number: charge percentage, e.g. 42
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this); chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
logV("Capacity file: " + chargeFile->fileName()); logE("Capacity file: " + chargeFile->fileName());
// String: charging, discharging, full, empty, unknown (others?) // String: charging, discharging, full, empty, unknown (others?)
stateFile = new QFile("/sys/class/power_supply/battery/status", this); stateFile = new QFile("/sys/class/power_supply/battery/status", this);
logV("Charge state file: " + stateFile->fileName()); logE("Charge state file: " + stateFile->fileName());
// Number: 0 or 1 // Number: 0 or 1
chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this); chargerConnectedFile = new QFile("/sys/class/power_supply/usb/present", this);
logV("Charger status file: " + chargerConnectedFile->fileName()); logE("Charger status file: " + chargerConnectedFile->fileName());
// ENABLE/DISABLE CHARGING // ENABLE/DISABLE CHARGING
QString filename; QString filename;
if(QHostInfo::localHostName().contains("SailfishEmul")) { if(QHostInfo::localHostName().contains("SailfishEmul")) {
logV("Sailfish SDK detected, not using charger control file"); logE("Sailfish SDK detected, not using charger control file");
} }
else { else {
// e.g. for Sony Xperia XA2 // e.g. for Sony Xperia XA2
@ -85,7 +85,7 @@ Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject
// If we found a usable file, check that it is writable // If we found a usable file, check that it is writable
if(chargingEnabledFile) { if(chargingEnabledFile) {
logV("Charger control file: " + chargingEnabledFile->fileName()); logE("Charger control file: " + chargingEnabledFile->fileName());
if(chargingEnabledFile->open(QIODevice::WriteOnly)) { if(chargingEnabledFile->open(QIODevice::WriteOnly)) {
chargingEnabledFile->close(); chargingEnabledFile->close();
} }
@ -138,20 +138,21 @@ void Battery::updateData()
if(nextState != state) { if(nextState != state) {
state = nextState; state = nextState;
emit stateChanged(state); emit stateChanged(state);
logV("Charging status:" + state); logV("Charging state: " + state);
// Hide/show notification right away // Hide/show notification right away
resetTimers(); resetTimers();
} }
stateFile->close(); stateFile->close();
} }
if(chargingEnabledFile && settings->getLimitEnabled()) { if(chargingEnabledFile && settings->getLimitEnabled()) {
if(chargingEnabled && charge >= settings->getHighLimit()) { if(chargingEnabled && charge >= settings->getHighLimit()) {
logV("Stop charging"); logD("Disabling charging...");
setChargingEnabled(false); setChargingEnabled(false);
} }
else if(!chargingEnabled && charge <= settings->getLowLimit()) { else if(!chargingEnabled && charge <= settings->getLowLimit()) {
logV("Continue charging"); logD("Enabling charging...");
setChargingEnabled(true); setChargingEnabled(true);
} }
} }
@ -185,7 +186,7 @@ void Battery::resetTimers() {
void Battery::showHighNotification() { void Battery::showHighNotification() {
if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging") if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging")
&& !(charge == 100 && state == "idle")) { && !(charge == 100 && state == "idle")) {
logD("Send high battery notification"); logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile());
if(settings->getHighNotificationsInterval() == 50) { if(settings->getHighNotificationsInterval() == 50) {
logD("Stop high battery timer"); logD("Stop high battery timer");
@ -196,11 +197,15 @@ void Battery::showHighNotification() {
logD("Close high battery notification"); logD("Close high battery notification");
notification->close(); notification->close();
} }
else {
logD("No high notification action");
}
} }
void Battery::showLowNotification() { void Battery::showLowNotification() {
logD(QString("Low notification if %1% < %2%)").arg(charge).arg(settings->getLowAlert()));
if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") { if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") {
logD("Send high battery notification"); logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
if(settings->getLowNotificationsInterval() == 50) { if(settings->getLowNotificationsInterval() == 50) {
logD("Stop low battery timer"); logD("Stop low battery timer");
@ -211,6 +216,9 @@ void Battery::showLowNotification() {
logD("Close low battery notification"); logD("Close low battery notification");
notification->close(); notification->close();
} }
else {
logD("No low notification action");
}
} }
int Battery::getCharge() { return charge; } int Battery::getCharge() { return charge; }
@ -252,7 +260,7 @@ bool Battery::getChargerConnected() {
} }
void Battery::shutdown() { void Battery::shutdown() {
logD("Preparing for exit..."); logV("Service shut down...");
blockSignals(true); blockSignals(true);
if(updateTimer) { if(updateTimer) {
updateTimer->stop(); updateTimer->stop();

View file

@ -137,7 +137,7 @@ void Settings::updateConfig(const QString path) {
if(oldLogLevel != logLevel) { if(oldLogLevel != logLevel) {
logger->debug = (logLevel == 2); logger->debug = (logLevel == 2);
logger->verbose = (logLevel > 1); logger->verbose = (logLevel > 1);
logE(QString("Log level set to %1").arg(logLevel)); logE(QString("Log level set to %1").arg((logLevel == 0 ? "low" : (logLevel == 1 ? "medium" : "high"))));
} }