Add --logfile option to daemon
This commit is contained in:
parent
f542628e56
commit
942949226a
4 changed files with 19 additions and 10 deletions
|
@ -19,7 +19,7 @@ Description=Battery Buddy background daemon
|
||||||
After=pre-user-session.target
|
After=pre-user-session.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/harbour-batterybuddy-daemon --verbose --logfile
|
ExecStart=/usr/bin/harbour-batterybuddy-daemon --logfile
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=user-session.target
|
WantedBy=user-session.target
|
||||||
|
|
|
@ -17,11 +17,19 @@
|
||||||
*/
|
*/
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
|
||||||
Battery::Battery(Logger* newLogger, QObject *parent) : QObject(parent)
|
Battery::Battery(Logger* newLogger, bool loglevelSet, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
logger = newLogger;
|
logger = newLogger;
|
||||||
QString filename;
|
|
||||||
settings = new Settings(logger, this);
|
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);
|
updateTimer = new QTimer(this);
|
||||||
highNotifyTimer = new QTimer(this);
|
highNotifyTimer = new QTimer(this);
|
||||||
lowNotifyTimer = 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());
|
logV("Charger status file: " + chargerConnectedFile->fileName());
|
||||||
|
|
||||||
// ENABLE/DISABLE CHARGING
|
// ENABLE/DISABLE CHARGING
|
||||||
|
QString filename;
|
||||||
if(QHostInfo::localHostName().contains("SailfishEmul")) {
|
if(QHostInfo::localHostName().contains("SailfishEmul")) {
|
||||||
logV("Sailfish SDK detected, not using charger control file");
|
logV("Sailfish SDK detected, not using charger control file");
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Battery : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Battery(Logger* newLogger, QObject *parent = nullptr);
|
Battery(Logger* newLogger, bool loglevelSet, QObject *parent = nullptr);
|
||||||
~Battery();
|
~Battery();
|
||||||
|
|
||||||
int getCharge();
|
int getCharge();
|
||||||
|
|
|
@ -46,13 +46,11 @@ int main(int argc, char** argv)
|
||||||
debug = true;
|
debug = true;
|
||||||
logLevelSet = true;
|
logLevelSet = true;
|
||||||
}
|
}
|
||||||
else if(!logLevelSet && QHostInfo::localHostName().contains("SailfishEmul")) {
|
|
||||||
verbose = true;
|
|
||||||
debug = true;
|
|
||||||
logLevelSet = true;
|
|
||||||
}
|
|
||||||
else if(!strcmp(argv[i],"--logfile")) {
|
else if(!strcmp(argv[i],"--logfile")) {
|
||||||
logfile = true;
|
logfile = true;
|
||||||
|
verbose = true;
|
||||||
|
debug = false;
|
||||||
|
logLevelSet = true;
|
||||||
}
|
}
|
||||||
else if(!strcmp(argv[i],"--help")) {
|
else if(!strcmp(argv[i],"--help")) {
|
||||||
printf("%s %s\n", APP_NAME, APP_VERSION);
|
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(" --verbose Enable informational messages\n");
|
||||||
printf(" --debug Enable informational and debugging messages\n");
|
printf(" --debug Enable informational and debugging messages\n");
|
||||||
printf(" --help Print version string and exit\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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ int main(int argc, char** argv)
|
||||||
Logger* logger = new Logger(verbose, debug, logfile);
|
Logger* logger = new Logger(verbose, debug, logfile);
|
||||||
logE(QString("%1 %2").arg(APP_NAME, APP_VERSION));
|
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
|
// Exit gracefully on Ctrl-C and service stop
|
||||||
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
|
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
|
||||||
|
|
Loading…
Reference in a new issue