Skip to content

Enable file logging by default#119

Merged
MaximumTrainer merged 3 commits intomasterfrom
copilot/enable-logging-by-default
Apr 4, 2026
Merged

Enable file logging by default#119
MaximumTrainer merged 3 commits intomasterfrom
copilot/enable-logging-by-default

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

File logging was opt-in, meaning errors were silently dropped on fresh installs unless the user manually enabled it in Preferences. This changes the out-of-the-box default to enabled.

Changes

  • src/app/logger.cppLogger::loadConfig() default for file_enabled flipped from falsetrue; existing saved preferences are unaffected
  • src/app/logger.h — header comment updated to document new default
  • README.md — Log Files section reworded to reflect always-on default
  • tests/logger/tst_logger.cpp — new test testConfig_fileLoggingEnabledByDefault asserts that a QSettings file with no file_enabled key resolves to true

Scope

Only the first-run/no-config path is affected. Users with an existing file_enabled=false saved in QSettings retain that preference. Log level default remains Info (captures Warn + Error without debug noise). WASM builds are unchanged — setFileLogging() is already a no-op there.

Copilot AI linked an issue Apr 4, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Enable logging errors by default and update configuration Enable file logging by default Apr 4, 2026
Copilot AI requested a review from MaximumTrainer April 4, 2026 14:29
@MaximumTrainer MaximumTrainer requested review from Copilot and removed request for MaximumTrainer April 4, 2026 14:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the default logging configuration so file logging is enabled out-of-the-box on fresh installs (when no prior QSettings value exists), preventing early errors from being silently dropped.

Changes:

  • Flip Logger::loadConfig() default for logging/file_enabled from false to true.
  • Update documentation to reflect the new default (header comment + README).
  • Add a unit test intended to validate the new “enabled by default” behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/app/logger.cpp Changes the QSettings default for file_enabled to true when the key is missing.
src/app/logger.h Updates the documented default for logging/file_enabled to true.
README.md Rewords the Log Files section to state file logging is enabled by default on first launch.
tests/logger/tst_logger.cpp Adds a new test around default file_enabled behavior (currently not exercising loadConfig()).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/logger/tst_logger.cpp Outdated
Comment on lines +360 to +389
void TstLogger::testConfig_fileLoggingEnabledByDefault()
{
// Build a QSettings file that has NO file_enabled key to simulate a
// fresh install. loadConfig() must default to enabled == true.
QTemporaryFile iniFile;
iniFile.setFileTemplate(QDir::tempPath() + QStringLiteral("/logger_default_XXXXXX.ini"));
QVERIFY(iniFile.open());
const QString iniPath = iniFile.fileName();
iniFile.close();

{
QSettings s(iniPath, QSettings::IniFormat);
s.beginGroup(QStringLiteral("logging"));
// Only write the level; deliberately omit file_enabled so the default kicks in.
s.setValue(QStringLiteral("level"), static_cast<int>(LogLevel::Info));
s.endGroup();
}

const bool savedFileEnabled = Logger::instance().isFileLoggingEnabled();
const QString savedFilePath = Logger::instance().logFilePath();
Logger::instance().setFileLogging(false); // start from a known disabled state

// Read the value that loadConfig() would use for file_enabled.
QSettings ws(iniPath, QSettings::IniFormat);
ws.beginGroup(QStringLiteral("logging"));
const bool defaultFileEnabled = ws.value(QStringLiteral("file_enabled"), true).toBool();
ws.endGroup();

QVERIFY2(defaultFileEnabled,
"file_enabled default must be true so logging is on for fresh installs");
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn’t actually exercise Logger::loadConfig(); it only asserts that QSettings::value("file_enabled", true) returns true when the key is missing, which will still pass even if Logger::loadConfig() regresses back to a false default. To validate the behavior change, call Logger::instance().loadConfig() against the temp settings and assert Logger::instance().isFileLoggingEnabled() becomes true when file_enabled is absent (using a test setup that makes loadConfig() read from the temp INI).

Copilot uses AI. Check for mistakes.
Comment thread tests/logger/tst_logger.cpp Outdated
Comment on lines +378 to +393
const bool savedFileEnabled = Logger::instance().isFileLoggingEnabled();
const QString savedFilePath = Logger::instance().logFilePath();
Logger::instance().setFileLogging(false); // start from a known disabled state

// Read the value that loadConfig() would use for file_enabled.
QSettings ws(iniPath, QSettings::IniFormat);
ws.beginGroup(QStringLiteral("logging"));
const bool defaultFileEnabled = ws.value(QStringLiteral("file_enabled"), true).toBool();
ws.endGroup();

QVERIFY2(defaultFileEnabled,
"file_enabled default must be true so logging is on for fresh installs");

// Restore previous file logging state.
Logger::instance().setFileLogging(savedFileEnabled, savedFilePath);
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

savedFileEnabled/savedFilePath restoration is not exception/early-return safe: if any QVERIFY* fails after setFileLogging(false), the test returns immediately and the logger state won’t be restored, which can make later tests flaky. Use an RAII rollback (e.g., a small guard object or QScopeGuard) to restore file logging state regardless of assertion outcomes.

Copilot uses AI. Check for mistakes.
@MaximumTrainer
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

@MaximumTrainer MaximumTrainer marked this pull request as ready for review April 4, 2026 14:54
…() with RAII guards

Agent-Logs-Url: https://github.com/MaximumTrainer/MaximumTrainer_Redux/sessions/be36561c-c943-47c3-9bd6-fba36b896431

Co-authored-by: MaximumTrainer <1376575+MaximumTrainer@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 4, 2026

@copilot apply changes based on the comments in this thread

Applied both changes in f197f0f:

  1. Test now exercises loadConfig() directly — it removes the file_enabled key from QSettings (simulating a fresh install), calls Logger::instance().loadConfig(), then asserts isFileLoggingEnabled() is true. A regression back to false default would now correctly fail the test.

  2. RAII guards — two qScopeGuard objects are set up at the top: one restores the Logger's file-logging state, the other restores (or removes) the file_enabled QSettings key. Both fire unconditionally, so any QVERIFY failure mid-test cannot leave stale state for subsequent tests.

Copilot AI requested a review from MaximumTrainer April 4, 2026 14:57
@MaximumTrainer MaximumTrainer merged commit 6cb10cf into master Apr 4, 2026
19 checks passed
@MaximumTrainer MaximumTrainer deleted the copilot/enable-logging-by-default branch April 4, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logging should be enabled by default

3 participants