mirror of
https://github.com/YACReader/yacreader
synced 2025-08-10 00:05:44 -04:00
fixed LibraryServer in Qt5
moved server_log to standardPath
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <stdio.h>
|
||||
#include "yacreader_global.h"
|
||||
|
||||
void FileLogger::refreshSettings() {
|
||||
mutex.lock();
|
||||
@ -21,7 +22,7 @@ void FileLogger::refreshSettings() {
|
||||
|
||||
// Load new config settings
|
||||
settings->sync();
|
||||
fileName=settings->value("fileName","./server/logs/log.log").toString();
|
||||
fileName=settings->value("fileName","server_log.log").toString();
|
||||
// Convert relative fileName to absolute, based on the directory of the config file.
|
||||
#ifdef Q_OS_WIN32
|
||||
if (QDir::isRelativePath(fileName) && settings->format()!=QSettings::NativeFormat)
|
||||
@ -29,16 +30,15 @@ void FileLogger::refreshSettings() {
|
||||
if (QDir::isRelativePath(fileName))
|
||||
#endif
|
||||
{
|
||||
QFileInfo configFile(settings->fileName());
|
||||
fileName=QFileInfo(configFile.absolutePath(),fileName).absoluteFilePath();
|
||||
QFileInfo configFile(YACReader::getSettingsPath());
|
||||
fileName=QFileInfo(YACReader::getSettingsPath(),fileName).absoluteFilePath();
|
||||
}
|
||||
maxSize=settings->value("maxSize",128000).toLongLong();
|
||||
maxSize=settings->value("maxSize",0).toLongLong();
|
||||
maxBackups=settings->value("maxBackups",0).toInt();
|
||||
msgFormat=settings->value("msgFormat","{timestamp} {type} {msg}").toString();
|
||||
timestampFormat=settings->value("timestampFormat","{yyyy-MM-dd hh:mm:ss.zzz}").toString();
|
||||
timestampFormat=settings->value("timestampFormat","yyyy-MM-dd hh:mm:ss.zzz").toString();
|
||||
minLevel=static_cast<QtMsgType>(settings->value("minLevel",0).toInt());
|
||||
bufferSize=settings->value("bufferSize",0).toInt();
|
||||
disabled=settings->value("disabled",false).toBool();
|
||||
|
||||
// Create new file if the filename has been changed
|
||||
if (oldFileName!=fileName) {
|
||||
@ -53,12 +53,13 @@ void FileLogger::refreshSettings() {
|
||||
FileLogger::FileLogger(QSettings* settings, const int refreshInterval, QObject* parent)
|
||||
: Logger(parent)
|
||||
{
|
||||
//Q_ASSERT(settings!=0);
|
||||
//Q_ASSERT(refreshInterval>=0);
|
||||
Q_ASSERT(settings!=0);
|
||||
Q_ASSERT(refreshInterval>=0);
|
||||
this->settings=settings;
|
||||
file=0;
|
||||
if (refreshInterval>0)
|
||||
if (refreshInterval>0) {
|
||||
refreshTimer.start(refreshInterval,this);
|
||||
}
|
||||
flushTimer.start(1000,this);
|
||||
refreshSettings();
|
||||
}
|
||||
@ -70,32 +71,29 @@ FileLogger::~FileLogger() {
|
||||
|
||||
|
||||
void FileLogger::write(const LogMessage* logMessage) {
|
||||
// Write to the file
|
||||
if (!disabled) {
|
||||
// Try to write to the file
|
||||
if (file) {
|
||||
// Try to write to the file
|
||||
if (file) {
|
||||
|
||||
// Write the message
|
||||
file->write(qPrintable(logMessage->toString(msgFormat,timestampFormat)));
|
||||
|
||||
// Flush error messages immediately, to ensure that no important message
|
||||
// gets lost when the program terinates abnormally.
|
||||
if (logMessage->getType()>=QtCriticalMsg) {
|
||||
file->flush();
|
||||
}
|
||||
|
||||
// Check for success
|
||||
if (file->error()) {
|
||||
close();
|
||||
qWarning("Cannot write to log file %s: %s",qPrintable(fileName),qPrintable(file->errorString()));
|
||||
}
|
||||
// Write the message
|
||||
file->write(qPrintable(logMessage->toString(msgFormat,timestampFormat)));
|
||||
|
||||
// Flush error messages immediately, to ensure that no important message
|
||||
// gets lost when the program terinates abnormally.
|
||||
if (logMessage->getType()>=QtCriticalMsg) {
|
||||
file->flush();
|
||||
}
|
||||
|
||||
// Fall-back to the super class method, if writing failed
|
||||
if (!file) {
|
||||
Logger::write(logMessage);
|
||||
// Check for success
|
||||
if (file->error()) {
|
||||
close();
|
||||
qWarning("Cannot write to log file %s: %s",qPrintable(fileName),qPrintable(file->errorString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Fall-back to the super class method, if writing failed
|
||||
if (!file) {
|
||||
Logger::write(logMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@ -105,8 +103,8 @@ void FileLogger::open() {
|
||||
qWarning("Name of logFile is empty");
|
||||
}
|
||||
else {
|
||||
file=new QFile(QDir::cleanPath(fileName));
|
||||
if (!file->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
file=new QFile(fileName);
|
||||
if (!file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
qWarning("Cannot open log file %s: %s",qPrintable(fileName),qPrintable(file->errorString()));
|
||||
file=0;
|
||||
}
|
||||
@ -147,8 +145,7 @@ void FileLogger::rotate() {
|
||||
}
|
||||
|
||||
// Backup the current logfile
|
||||
if(maxBackups>0)
|
||||
QFile::rename(fileName,fileName+".1");
|
||||
QFile::rename(fileName,fileName+".1");
|
||||
}
|
||||
|
||||
|
||||
@ -167,8 +164,7 @@ void FileLogger::timerEvent(QTimerEvent* event) {
|
||||
|
||||
// Rotate the file if it is too large
|
||||
if (maxSize>0 && file->size()>=maxSize) {
|
||||
|
||||
close();
|
||||
close();
|
||||
rotate();
|
||||
open();
|
||||
}
|
||||
|
Reference in New Issue
Block a user