Skip to content

Commit

Permalink
Add systemd logging to core library
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Mar 11, 2013
1 parent 680a8a8 commit 93c60c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libssu/libssu.pro
Expand Up @@ -4,10 +4,11 @@ HEADERS = ssu.h \
SOURCES = ssu.cpp
TEMPLATE = lib
TARGET = ssu
CONFIG += dll mobility
CONFIG += dll mobility link_pkgconfig
QT -= gui
QT += network xml
MOBILITY += systeminfo
PKGCONFIG += libsystemd-journal

headers.files = ssu.h
headers.path = /usr/include
Expand Down
19 changes: 18 additions & 1 deletion libssu/ssu.cpp
Expand Up @@ -8,13 +8,15 @@
#include <QSystemDeviceInfo>

#include <QtXml/QDomDocument>

#include "ssu.h"
#include "../constants.h"

QTM_USE_NAMESPACE

Ssu::Ssu(): QObject(){
Ssu::Ssu(QString fallbackLog): QObject(){
errorFlag = false;
fallbackLogPath = fallbackLog;

#ifdef SSUCONFHACK
// dirty hack to make sure we can write to the configuration
Expand Down Expand Up @@ -289,6 +291,21 @@ QString Ssu::lastError(){
return errorString;
}

void Ssu::printJournal(int priority, QString message){
QByteArray ba = message.toUtf8();
const char *ca = ba.constData();

if (sd_journal_print(LOG_INFO, "ssu: %s", ca) < 0 && fallbackLogPath != ""){
QFile logfile;
QTextStream logstream;
logfile.setFileName(fallbackLogPath);
logfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
logstream.setDevice(&logfile);
logstream << message << "\n";
logstream.flush();
}
}

bool Ssu::registerDevice(QDomDocument *response){
QString certificateString = response->elementsByTagName("certificate").at(0).toElement().text();
QSslCertificate certificate(certificateString.toAscii());
Expand Down
10 changes: 8 additions & 2 deletions libssu/ssu.h
Expand Up @@ -16,11 +16,13 @@

#include <QtXml/QDomDocument>

#include <systemd/sd-journal.h>

class Ssu: public QObject {
Q_OBJECT

public:
Ssu();
Ssu(QString fallbackLog="");
/**
* Find a username/password pair for the given scope
* @return a QPair with username and password, or an empty QPair if scope is invalid
Expand Down Expand Up @@ -86,6 +88,10 @@ class Ssu: public QObject {
* successful.
*/
Q_INVOKABLE QString lastError();
/**
* Print a message to systemds journal, or to a text log file, if a fallback is defined
*/
void printJournal(int priority, QString message);
/**
* Return the release version string for either a release, or a RnD snapshot
*/
Expand Down Expand Up @@ -122,7 +128,7 @@ class Ssu: public QObject {
Q_INVOKABLE bool useSslVerify();

private:
QString errorString;
QString errorString, fallbackLogPath;
QString cachedModel, cachedFamily;
bool errorFlag;
QNetworkAccessManager *manager;
Expand Down

0 comments on commit 93c60c6

Please sign in to comment.