Commit 93c60c63 authored by Aard's avatar Aard

Add systemd logging to core library

parent 680a8a8c
......@@ -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
......
......@@ -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
......@@ -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());
......
......@@ -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
......@@ -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
*/
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment