Skip to content

Commit 3e1f486

Browse files
author
Mich
committed
Finished truncate log on write functionality
1 parent fd9c78b commit 3e1f486

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/logger.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void Logger::openFile(QString fileName, bool truncateFile)
1212
logFile->setFileName(fileName);
1313

1414
if (truncateFile)
15-
logFile->open(QIODevice::OpenModeFlag::ReadWrite | QIODevice::OpenModeFlag::Truncate | QIODevice::Text);
15+
logFile->open(QIODevice::OpenModeFlag::Truncate | QFile::OpenModeFlag::ReadWrite | QIODevice::Text);
1616
else
1717
logFile->open(QIODevice::OpenModeFlag::ReadWrite | QIODevice::Text);
1818
}
@@ -32,16 +32,16 @@ void Logger::closeFile()
3232
}
3333
}
3434

35-
bool Logger::beginLog(QString path, bool autoLogging, QString fileName)
35+
bool Logger::beginLog(QString path, bool autoLogging, QString fileName, bool truncateFile)
3636
{
3737
if (logFile == nullptr && QDir(path).isReadable())
3838
{
3939
qDebug() << "File open";
4040

4141
if (autoLogging)
42-
openFile(path + "/" + QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss.zzz_") + "Log" + fileName.right(fileName.length() - fileName.lastIndexOf('.')));
42+
openFile(path + "/" + QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss.zzz_") + "Log" + fileName.right(fileName.length() - fileName.lastIndexOf('.')),truncateFile);
4343
else
44-
openFile(path + "/" + fileName);
44+
openFile(path + "/" + fileName, truncateFile);
4545

4646
return true;
4747
}

src/logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Logger : public QObject
1313
Q_OBJECT
1414
public:
1515
explicit Logger(QObject *parent = nullptr);
16-
bool beginLog(QString path, bool autoLogging, QString fileName);
16+
bool beginLog(QString path, bool autoLogging, QString fileName, bool truncateFile = false);
1717
bool isOpen();
1818
void closeFile();
1919
void openFile(QString fileName, bool truncateFile = false);

src/mainwindow.ui

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@
10631063
</item>
10641064
<item>
10651065
<widget class="QCheckBox" name="checkBoxTruncateFileOnSave">
1066+
<property name="whatsThis">
1067+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Deletes file's contents upon first acces. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1068+
</property>
10661069
<property name="text">
10671070
<string>Truncate</string>
10681071
</property>
@@ -1200,7 +1203,7 @@
12001203
<item row="1" column="0">
12011204
<widget class="QLabel" name="label_22">
12021205
<property name="text">
1203-
<string>Log mode:</string>
1206+
<string>Text format</string>
12041207
</property>
12051208
</widget>
12061209
</item>
@@ -1220,7 +1223,7 @@
12201223
</property>
12211224
<item>
12221225
<property name="text">
1223-
<string>Text</string>
1226+
<string>Raw message</string>
12241227
</property>
12251228
</item>
12261229
<item>
@@ -1238,6 +1241,9 @@
12381241
<verstretch>0</verstretch>
12391242
</sizepolicy>
12401243
</property>
1244+
<property name="whatsThis">
1245+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Pick log format&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1246+
</property>
12411247
<property name="sizeAdjustPolicy">
12421248
<enum>QComboBox::AdjustToContents</enum>
12431249
</property>
@@ -2637,7 +2643,7 @@ p, li { white-space: pre-wrap; }
26372643
<x>0</x>
26382644
<y>0</y>
26392645
<width>1801</width>
2640-
<height>22</height>
2646+
<height>27</height>
26412647
</rect>
26422648
</property>
26432649
<widget class="QMenu" name="menuFile">

0 commit comments

Comments
 (0)