Skip to content

Commit 36b5af3

Browse files
likeawindrammerCents02
andauthored
Add option for automatic logging (#203)
Just so we're on the same page, this is enabled by default. Co-authored-by: Cents02 <Cents02@Cents0.me>
1 parent bab10ea commit 36b5af3

6 files changed

Lines changed: 40 additions & 10 deletions

File tree

include/aoapplication.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ class AOApplication : public QApplication {
427427
// Get the message for the CM for casing alerts.
428428
QString get_casing_can_host_cases();
429429

430+
// Get if automatic logging is enabled
431+
bool get_auto_logging_enabled();
432+
430433
// The file name of the log file in base/logs.
431434
QString log_filename;
432435

include/aooptionsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class AOOptionsDialog : public QDialog {
131131
QCheckBox *ui_casing_cm_cb;
132132
QLabel *ui_casing_cm_cases_lbl;
133133
QLineEdit *ui_casing_cm_cases_textbox;
134+
QLabel *ui_log_lbl;
135+
QCheckBox *ui_log_cb;
134136

135137
bool needs_default_audiodev();
136138

src/aooptionsdialog.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,20 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
699699

700700
ui_casing_layout->setWidget(row, QFormLayout::FieldRole,
701701
ui_casing_cm_cases_textbox);
702+
//Check whether mass logging is enabled
703+
row += 1;
704+
ui_log_lbl = new QLabel(ui_casing_widget);
705+
ui_log_lbl->setText(tr("Automatic Logging:"));
706+
ui_log_lbl->setToolTip(
707+
tr("If checked, all logs will be automatically written in the "
708+
"/logs folder."));
709+
710+
ui_casing_layout->setWidget(row, QFormLayout::LabelRole, ui_log_lbl);
711+
712+
ui_log_cb = new QCheckBox(ui_casing_widget);
713+
ui_log_cb->setChecked(ao_app->get_auto_logging_enabled());
714+
715+
ui_casing_layout->setWidget(row, QFormLayout::FieldRole, ui_log_cb);
702716

703717
// When we're done, we should continue the updates!
704718
setUpdatesEnabled(true);
@@ -725,7 +739,7 @@ void AOOptionsDialog::save_pressed()
725739
configini->setValue("stickyeffects", ui_stickyeffects_cb->isChecked());
726740
configini->setValue("stickypres", ui_stickypres_cb->isChecked());
727741
configini->setValue("customchat", ui_customchat_cb->isChecked());
728-
742+
configini->setValue("automatic_logging_enabled", ui_log_cb->isChecked());
729743
QFile *callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini");
730744

731745
if (callwordsini->open(QIODevice::WriteOnly | QIODevice::Truncate |

src/courtroom.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,8 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
18701870
chatlogpiece *temp =
18711871
new chatlogpiece(f_charname, f_showname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt());
18721872
ic_chatlog_history.append(*temp);
1873-
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
1873+
if (ao_app->get_auto_logging_enabled())
1874+
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
18741875

18751876
while (ic_chatlog_history.size() > log_maximum_blocks &&
18761877
log_maximum_blocks > 0) {
@@ -3175,7 +3176,8 @@ void Courtroom::handle_song(QStringList *p_contents)
31753176
if (!mute_map.value(n_char)) {
31763177
chatlogpiece *temp = new chatlogpiece(str_char, str_show, f_song, true, m_chatmessage[TEXT_COLOR].toInt());
31773178
ic_chatlog_history.append(*temp);
3178-
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
3179+
if (ao_app->get_auto_logging_enabled())
3180+
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
31793181

31803182
while (ic_chatlog_history.size() > log_maximum_blocks &&
31813183
log_maximum_blocks > 0) {

src/packet_distribution.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,16 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
292292

293293
// Remove any characters not accepted in folder names for the server_name
294294
// here
295-
this->log_filename = QDateTime::currentDateTime().toUTC().toString(
296-
"'logs/" + server_name.remove(QRegExp("[\\\\/:*?\"<>|\']")) +
297-
"/'ddd MMMM yyyy hh.mm.ss t'.log'");
298-
this->write_to_file("Joined server " + server_name + " on address " +
299-
server_address + " on " +
300-
QDateTime::currentDateTime().toUTC().toString(),
301-
log_filename, true);
295+
if (AOApplication::get_auto_logging_enabled()){
296+
this->log_filename = QDateTime::currentDateTime().toUTC().toString(
297+
"'logs/" + server_name.remove(QRegExp("[\\\\/:*?\"<>|\']")) +
298+
"/'ddd MMMM yyyy hh.mm.ss t'.log'");
299+
this->write_to_file("Joined server " + server_name + " on address " +
300+
server_address + " on " +
301+
QDateTime::currentDateTime().toUTC().toString(),
302+
log_filename, true);
303+
}
304+
302305
QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256);
303306
hash.addData(server_address.toUtf8());
304307
if (is_discord_enabled())

src/text_file_functions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,3 +1049,9 @@ QString AOApplication::get_casing_can_host_cases()
10491049
.value<QString>();
10501050
return result;
10511051
}
1052+
bool AOApplication::get_auto_logging_enabled()
1053+
{
1054+
QString result =
1055+
configini->value("automatic_logging_enabled", "true").value<QString>();
1056+
return result.startsWith("true");
1057+
}

0 commit comments

Comments
 (0)