Add --logfile option to daemon

This commit is contained in:
Matti Viljanen 2021-04-24 18:14:26 +03:00
parent f542628e56
commit 942949226a
No known key found for this signature in database
GPG key ID: CF32A1495158F888
4 changed files with 19 additions and 10 deletions

View file

@ -19,7 +19,7 @@ Description=Battery Buddy background daemon
After=pre-user-session.target
[Service]
ExecStart=/usr/bin/harbour-batterybuddy-daemon --verbose --logfile
ExecStart=/usr/bin/harbour-batterybuddy-daemon --logfile
[Install]
WantedBy=user-session.target

View file

@ -17,11 +17,19 @@
*/
#include "battery.h"
Battery::Battery(Logger* newLogger, QObject *parent) : QObject(parent)
Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject(parent)
{
logger = newLogger;
QString filename;
settings = new Settings(logger, this);
// Read log level from config - if not already set
if(!loglevelSet) {
int logLevel = settings->getLogLevel();
logger->debug = (logLevel == 2);
logger->verbose = (logLevel > 1);
logE(QString("Log level set to %1").arg(logLevel));
}
updateTimer = new QTimer(this);
highNotifyTimer = new QTimer(this);
lowNotifyTimer = new QTimer(this);
@ -40,6 +48,7 @@ Battery::Battery(Logger* newLogger, QObject *parent) : QObject(parent)
logV("Charger status file: " + chargerConnectedFile->fileName());
// ENABLE/DISABLE CHARGING
QString filename;
if(QHostInfo::localHostName().contains("SailfishEmul")) {
logV("Sailfish SDK detected, not using charger control file");
}

View file

@ -33,7 +33,7 @@ class Battery : public QObject
Q_OBJECT
public:
Battery(Logger* newLogger, QObject *parent = nullptr);
Battery(Logger* newLogger, bool loglevelSet, QObject *parent = nullptr);
~Battery();
int getCharge();

View file

@ -46,13 +46,11 @@ int main(int argc, char** argv)
debug = true;
logLevelSet = true;
}
else if(!logLevelSet && QHostInfo::localHostName().contains("SailfishEmul")) {
verbose = true;
debug = true;
logLevelSet = true;
}
else if(!strcmp(argv[i],"--logfile")) {
logfile = true;
verbose = true;
debug = false;
logLevelSet = true;
}
else if(!strcmp(argv[i],"--help")) {
printf("%s %s\n", APP_NAME, APP_VERSION);
@ -60,6 +58,8 @@ int main(int argc, char** argv)
printf(" --verbose Enable informational messages\n");
printf(" --debug Enable informational and debugging messages\n");
printf(" --help Print version string and exit\n");
printf(" --logfile Write log to a file. Implies --verbose\n\n");
printf("Log file: ~/.cache/harbour-batterybuddy-daemon/harbour-batterybuddy-daemon.log\n");
return 0;
}
}
@ -71,7 +71,7 @@ int main(int argc, char** argv)
Logger* logger = new Logger(verbose, debug, logfile);
logE(QString("%1 %2").arg(APP_NAME, APP_VERSION));
Battery* battery = new Battery(logger);
Battery* battery = new Battery(logger, logLevelSet);
// Exit gracefully on Ctrl-C and service stop
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));