Browse Source

Set default file log size to 65 KiB and delete backup logs older than 1 month.

adaptive-webui-19844
sledgehammer999 7 years ago
parent
commit
024df8c53f
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 29
      src/app/application.cpp
  2. 2
      src/app/application.h
  3. 2
      src/app/filelogger.cpp
  4. 4
      src/gui/optionsdlg.cpp
  5. 6
      src/gui/optionsdlg.ui

29
src/app/application.cpp

@ -87,7 +87,7 @@ namespace
const QString KEY_FILELOGGER_PATH = FILELOGGER_SETTINGS_KEY("Path"); const QString KEY_FILELOGGER_PATH = FILELOGGER_SETTINGS_KEY("Path");
const QString KEY_FILELOGGER_BACKUP = FILELOGGER_SETTINGS_KEY("Backup"); const QString KEY_FILELOGGER_BACKUP = FILELOGGER_SETTINGS_KEY("Backup");
const QString KEY_FILELOGGER_DELETEOLD = FILELOGGER_SETTINGS_KEY("DeleteOld"); const QString KEY_FILELOGGER_DELETEOLD = FILELOGGER_SETTINGS_KEY("DeleteOld");
const QString KEY_FILELOGGER_MAXSIZE = FILELOGGER_SETTINGS_KEY("MaxSize"); const QString KEY_FILELOGGER_MAXSIZEBYTES = FILELOGGER_SETTINGS_KEY("MaxSizeBytes");
const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age"); const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age");
const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType"); const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType");
@ -98,6 +98,10 @@ namespace
const char PARAMS_SEPARATOR[] = "|"; const char PARAMS_SEPARATOR[] = "|";
const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QLatin1String("profile"); const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QLatin1String("profile");
const int MIN_FILELOG_SIZE = 1024; // 1KiB
const int MAX_FILELOG_SIZE = 1000 * 1024 * 1024; // 1000MiB
const int DEFAULT_FILELOG_SIZE = 65 * 1024; // 65KiB
} }
Application::Application(const QString &id, int &argc, char **argv) Application::Application(const QString &id, int &argc, char **argv)
@ -221,29 +225,22 @@ void Application::setFileLoggerDeleteOld(bool value)
int Application::fileLoggerMaxSize() const int Application::fileLoggerMaxSize() const
{ {
int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZE, 10).toInt(); int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE).toInt();
if (val < 1) return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
return 1;
if (val > 1000)
return 1000;
return val;
} }
void Application::setFileLoggerMaxSize(const int value) void Application::setFileLoggerMaxSize(const int bytes)
{ {
int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
if (m_fileLogger) if (m_fileLogger)
m_fileLogger->setMaxSize(value); m_fileLogger->setMaxSize(clampedValue);
settings()->storeValue(KEY_FILELOGGER_MAXSIZE, std::min(std::max(value, 1), 1000)); settings()->storeValue(KEY_FILELOGGER_MAXSIZEBYTES, clampedValue);
} }
int Application::fileLoggerAge() const int Application::fileLoggerAge() const
{ {
int val = settings()->loadValue(KEY_FILELOGGER_AGE, 6).toInt(); int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1).toInt();
if (val < 1) return std::min(std::max(val, 1), 365);
return 1;
if (val > 365)
return 365;
return val;
} }
void Application::setFileLoggerAge(const int value) void Application::setFileLoggerAge(const int value)

2
src/app/application.h

@ -101,7 +101,7 @@ public:
bool isFileLoggerDeleteOld() const; bool isFileLoggerDeleteOld() const;
void setFileLoggerDeleteOld(bool value); void setFileLoggerDeleteOld(bool value);
int fileLoggerMaxSize() const; int fileLoggerMaxSize() const;
void setFileLoggerMaxSize(const int value); void setFileLoggerMaxSize(const int bytes);
int fileLoggerAge() const; int fileLoggerAge() const;
void setFileLoggerAge(const int value); void setFileLoggerAge(const int value);
int fileLoggerAgeType() const; int fileLoggerAgeType() const;

2
src/app/filelogger.cpp

@ -135,7 +135,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl; str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl;
if (m_backup && (m_logFile->size() >= (m_maxSize * 1024 * 1024))) { if (m_backup && (m_logFile->size() >= m_maxSize)) {
closeLogFile(); closeLogFile();
int counter = 0; int counter = 0;
QString backupLogFilename = m_path + ".bak"; QString backupLogFilename = m_path + ".bak";

4
src/gui/optionsdlg.cpp

@ -537,7 +537,7 @@ void OptionsDialog::saveOptions()
Application * const app = static_cast<Application*>(QCoreApplication::instance()); Application * const app = static_cast<Application*>(QCoreApplication::instance());
app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath()); app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked()); app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value()); app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
app->setFileLoggerAge(m_ui->spinFileLogAge->value()); app->setFileLoggerAge(m_ui->spinFileLogAge->value());
app->setFileLoggerAgeType(m_ui->comboFileLogAgeType->currentIndex()); app->setFileLoggerAgeType(m_ui->comboFileLogAgeType->currentIndex());
app->setFileLoggerDeleteOld(m_ui->checkFileLogDelete->isChecked()); app->setFileLoggerDeleteOld(m_ui->checkFileLogDelete->isChecked());
@ -765,7 +765,7 @@ void OptionsDialog::loadOptions()
m_ui->checkFileLogDelete->setChecked(fileLogDelete); m_ui->checkFileLogDelete->setChecked(fileLogDelete);
m_ui->spinFileLogAge->setEnabled(fileLogDelete); m_ui->spinFileLogAge->setEnabled(fileLogDelete);
m_ui->comboFileLogAgeType->setEnabled(fileLogDelete); m_ui->comboFileLogAgeType->setEnabled(fileLogDelete);
m_ui->spinFileLogSize->setValue(app->fileLoggerMaxSize()); m_ui->spinFileLogSize->setValue(app->fileLoggerMaxSize() / 1024);
m_ui->spinFileLogAge->setValue(app->fileLoggerAge()); m_ui->spinFileLogAge->setValue(app->fileLoggerAge());
m_ui->comboFileLogAgeType->setCurrentIndex(app->fileLoggerAgeType()); m_ui->comboFileLogAgeType->setCurrentIndex(app->fileLoggerAgeType());
// End General preferences // End General preferences

6
src/gui/optionsdlg.ui

@ -535,16 +535,16 @@
<item> <item>
<widget class="QSpinBox" name="spinFileLogSize"> <widget class="QSpinBox" name="spinFileLogSize">
<property name="suffix"> <property name="suffix">
<string> MB</string> <string> KiB</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>1</number> <number>1</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>1000</number> <number>1024000</number>
</property> </property>
<property name="value"> <property name="value">
<number>10</number> <number>65</number>
</property> </property>
</widget> </widget>
</item> </item>

Loading…
Cancel
Save