Commit 96f1cc0b authored by Lukas Appelhans's avatar Lukas Appelhans

Implement retrieveLoggedActions

parent cb82ff1f
......@@ -16,11 +16,14 @@
#include <syslog.h>
#include <QDateTime>
#include <QTextStream>
#include <QFile>
namespace {
/* These are required to hold the configuration between calls */
static std::ofstream logStream;
static bool isSyslog( false );
static QString pathToFile;
static QString __msg_prefix[] = { "", "Warning: ", "Critical: " };
static int __msg_priority[] = { LOG_WARNING, LOG_WARNING, LOG_CRIT };
......@@ -74,13 +77,14 @@ AkabeiLogLine::~AkabeiLogLine()
/*
* This must be called before using the logging system
*/
void AkabeiLogLine::initialize(bool syslog, QString filename)
void AkabeiLogLine::initialize(bool syslog, const QString &filename)
{
isSyslog = syslog;
if (isSyslog) {
openlog("akabei", LOG_PID | LOG_CONS, LOG_USER); /* open connection for a generic user service */
} else {
pathToFile = filename;
logStream.open(filename.toUtf8().constData(), std::ios::app);
if (!logStream.is_open()) {
......@@ -230,3 +234,28 @@ AkabeiLogLine log()
return AkabeiLogLine(LogNormal);
}
QString readLoggedActions(const QString &filter)
{
if (isSyslog)
return QString();
if (pathToFile.isEmpty()) {
std::cerr << "Log error: logging system not initialized correctly. Cannot read from log." << std::endl;
return QString();
}
QString result;
QFile file(pathToFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if (line.contains(filter))
result.append(line + "\n");
}
return result;
}
......@@ -45,7 +45,7 @@ public:
AkabeiLogLine& operator<<(const QByteArray &);
AkabeiLogLine& operator<<(const void *);
static void initialize(bool syslog, QString filename = QString());
static void initialize(bool syslog, const QString &filename = QString());
private:
class Private;
......@@ -56,4 +56,6 @@ AkabeiLogLine logWarning();
AkabeiLogLine logCritical();
AkabeiLogLine log();
QString readLoggedActions(const QString &filter);
#endif
......@@ -24,6 +24,8 @@
#include <QFile>
#include <QDir>
#include <akabeidebug.h>
#include <akabeipackage.h>
#include <akabeilog.h>
namespace Akabei {
void PackagePrivate::setName(const QString &n)
......@@ -448,7 +450,7 @@ QString Package::retrieveLoggedActions() const
{
Q_D(const Package);
QWriteLocker locker(d->mutex);
return QString();
return readLoggedActions(' ' + d->name + ' ');//We have empty spaces around, otherwise we will e.g. get all the apr-utils log lines for apr as well
}
QStringList Package::conflictsWith() const
......
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