Skip to content

Commit

Permalink
[ssu] Only log ERR or higher, add loglevel setting in ssu.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Apr 11, 2014
1 parent 499014f commit b062d35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libssu/ssulog.cpp
Expand Up @@ -9,13 +9,15 @@
#include <QTextStream>

#include "ssulog.h"
#include "ssucoreconfig.h"

SsuLog *SsuLog::ssuLog = 0;

SsuLog *SsuLog::instance(){
if (!ssuLog){
ssuLog = new SsuLog();
ssuLog->fallbackLogPath = "/tmp/ssu.log";
ssuLog->ssuLogLevel = -1;
}

return ssuLog;
Expand All @@ -25,6 +27,20 @@ void SsuLog::print(int priority, QString message){
QByteArray ba = message.toUtf8();
const char *ca = ba.constData();

if (ssuLogLevel == -1){
SsuCoreConfig *settings = SsuCoreConfig::instance();

if (settings->contains("loglevel"))
ssuLog->ssuLogLevel = settings->value("loglevel").toInt();
else
ssuLog->ssuLogLevel = LOG_ERR;
}

// this is rather dirty, but since systemd does not seem to allow to enable debug
// logging only for specific services probably best way for now
if (priority > ssuLogLevel)
return;

if (sd_journal_print(priority, "ssu: %s", ca) < 0 && fallbackLogPath != ""){
QFile logfile;
QTextStream logstream;
Expand Down
1 change: 1 addition & 0 deletions libssu/ssulog.h
Expand Up @@ -26,6 +26,7 @@ class SsuLog {
SsuLog(const SsuLog &); // hide copy constructor

static SsuLog *ssuLog;
int ssuLogLevel;
QString fallbackLogPath;
};

Expand Down

0 comments on commit b062d35

Please sign in to comment.