Commit ed798e47 authored by Victor Yacovlev's avatar Victor Yacovlev

Fix for #kumir2-1897

parent 19aa53e3
......@@ -49,7 +49,7 @@ Logger::Logger(const QString & filePath, LogLevel logLevel)
#ifdef NDEBUG
bool process = Debug == logLevel_;
#else
bool process = true;
bool process = isDebugOnLinux();
#endif
if (process) {
writeLog("STARTED", "");
......@@ -61,7 +61,7 @@ Logger::~Logger()
#ifdef NDEBUG
bool process = Debug == logLevel_;
#else
bool process = true;
bool process = isDebugOnLinux();
#endif
if (process) {
writeLog("EXITING", "");
......@@ -73,6 +73,39 @@ Logger::~Logger()
}
}
static bool isUbuntu() {
#ifndef Q_OS_LINUX
return false;
#endif
QFile osRelease("/etc/os-release");
if (osRelease.open(QIODevice::ReadOnly|QIODevice::Text)) {
QByteArray content = osRelease.readAll();
osRelease.close();
return content.contains("ID=ubuntu");
}
return false;
}
static bool isInstalledInPosixSystem() {
#ifndef Q_OS_UNIX
return false;
#endif
const QString appDir = QCoreApplication::applicationDirPath();
return appDir.startsWith("/usr/") || appDir.startsWith("/opt/");
}
bool Logger::isDebugOnLinux()
{
#ifndef Q_OS_UNIX
return true;
#endif
// Check once
static const bool ubuntu = isUbuntu();
static const bool usrRoot = isInstalledInPosixSystem();
static const bool ubuntuPackage = ubuntu && usrRoot;
return ! ubuntuPackage;
}
void Logger::writeLog(const char *type, const QString &message)
{
QByteArray buffer;
......@@ -96,7 +129,7 @@ void Logger::debug(const QString &message)
#ifdef NDEBUG
bool process = Debug == logLevel_;
#else
bool process = true;
bool process = isDebugOnLinux();
#endif
if (process) {
writeLog("DEBUG", message);
......@@ -108,7 +141,7 @@ void Logger::warning(const QString &message)
#ifdef NDEBUG
bool process = Debug == logLevel_;
#else
bool process = true;
bool process = isDebugOnLinux();
#endif
if (process) {
writeLog("WARNING", message);
......
......@@ -34,6 +34,7 @@ public:
~Logger();
private:
static bool isDebugOnLinux();
void writeLog(const char * type, const QString &message);
Logger(const QString & filePath, LogLevel logLevel);
......
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