Skip to content

Fix utils_logging.R log file append logic - #150

Merged
tonywu1999 merged 1 commit into
Vitek-Lab:develfrom
ShonenAsh:bugfix-logging
Nov 10, 2026
Merged

tonywu1999 merged 1 commit into
Vitek-Lab:develfrom
ShonenAsh:bugfix-logging

Conversation

@ShonenAsh

@ShonenAsh ShonenAsh commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Motivation and Context

A bug in file_appender() of utils_logging.R overwrites log files if append = FALSE because the flag is passed directly to cat(). This means anyone who sets log_file_path in their dataProcess() without setting append = TRUE, would get a log file with just the last line written.

Changes

  • Creates a log file or clears and existing one if append = FALSE, which is the intended behavior for appending logs to a file.

Testing

  • Modified test_logging.R to include asserts for append flag

Checklist Before Requesting a Review

  • I have read the MSstats contributing guidelines
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Motivation and solution

When append = FALSE, .fileAppender previously passed FALSE to cat(). This could prevent the log file from retaining all entries. The change clears or creates the file first, then writes each message in append mode.

Changes

  • Updated .fileAppender in R/utils_logging.R to clear or create the target file when append = FALSE.
  • Set message writes to always use append mode after file setup.
  • Preserved existing-file behavior when append = TRUE.

Tests

  • Added assertions in inst/tinytest/test_logging.R that append = FALSE removes the old line and writes two new entries.
  • Added an assertion that append = TRUE adds a third entry.
  • The test saves and restores the MSstatsLog and MSstatsMsg options.
  • Test execution result: not available.

Coding guidelines

  • The contribution guide asks for relevant tests and says new code should follow the tidyverse style guide, with listed exceptions. The added logging tests address the relevant test guidance.
  • No coding guideline violation is established by the available evidence.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The file appender now clears or creates the target file when append = FALSE, then writes log messages in append mode. A logging test checks the file contents with both append settings and restores the saved options.

Changes: Logging file behavior

Layer / File(s) Summary
File initialization and logging test
R/utils_logging.R, inst/tinytest/test_logging.R
When append = FALSE, the appender clears or creates the target file before writing. The test checks the resulting contents for append = FALSE and append = TRUE.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: swaraj-neu

Merge Risk: Minimal · up to 64dfc

Logging retains multiple entries with either append setting. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly identifies the change to the log file append logic.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description includes the required motivation and context, a change summary, testing details, and all checklist items. The checklist items are present but remain unchecked.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the log at night
First, old lines hop out of sight
New lines follow, one by one
Append keeps the earlier run
The test restores each option
Then I nibble on a carrot top

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8c122fae-bf23-49b8-8449-4dcbbb1d0abe
Commits

Reviewing files that changed from the base of the PR and between 3955a02 and 64dfc72.

Files selected for processing: 2

  • R/utils_logging.R
  • inst/tinytest/test_logging.R

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@tonywu1999
tonywu1999 merged commit ce9cb29 into Vitek-Lab:devel Nov 10, 2026
2 checks passed
@ShonenAsh
ShonenAsh deleted the bugfix-logging branch November 10, 2026 15:09
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.

2 participants