Skip to content

Remove log4r dependency (replace with base R logging)#141

Merged
tonywu1999 merged 3 commits into
develfrom
MSstatsConvert/work/20260716_remove_log4r_dependency
Jul 16, 2026
Merged

Remove log4r dependency (replace with base R logging)#141
tonywu1999 merged 3 commits into
develfrom
MSstatsConvert/work/20260716_remove_log4r_dependency

Conversation

@swaraj-neu

@swaraj-neu swaraj-neu commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Please include relevant motivation and context of the problem along with a short summary of the solution.

Changes

Please provide a detailed bullet point list of your changes.

Testing

Please describe any unit tests you added or modified to verify your changes.

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 context

The package removes its log4r dependency and switches to base R logging, while keeping the same user-facing behaviors for writing logs to a file, emitting messages to the console, or suppressing output. The update introduces internal logging helpers and adjusts package initialization/configuration to use them instead of log4r.

Changes

  • Bumped package version in DESCRIPTION from 1.23.2 to 1.23.3.
  • Removed log4r from DESCRIPTION Imports.
  • Updated NAMESPACE to remove importFrom(log4r, console_appender) and importFrom(log4r, file_appender).
  • Reworked logging implementation in R/utils_logging.R:
    • Added .formatLogMessage() to standardize log line formatting.
    • Replaced log4r appender usage with internal closures:
      • .fileAppender() (writes one formatted log line to a file)
      • .consoleAppender() (writes one formatted log line to the console)
      • .nullAppender (suppresses output)
    • Updated .onLoad to conditionally set MSstatsLog / MSstatsMsg using the new internal appenders when not already configured.
    • Updated MSstatsLogsSettings() to build logging behavior using .fileAppender()/.nullAppender (file logging controlled by use_log_file) and .consoleAppender()/.nullAppender (console logging controlled by verbose), wiring results into options(...).
  • Added/updated documentation for the new internal logging helpers:
    • New Rd pages for .consoleAppender(), .fileAppender(), and .formatLogMessage().
    • Updated .nullAppender documentation wording to remove “log4r appender” phrasing.
  • Updated vignette text (vignettes/msstats_data_format.Rmd) to describe flexible logging without referencing log4r.
  • Note: the generated docs/ pkgdown HTML still contains some log4r references (e.g., docs/articles/msstats_data_format.html, docs/reference/dot-nullAppender.html), suggesting the site output may not have been fully regenerated after source changes.

Unit tests

No unit tests were added or modified.

Coding guideline violations

No coding guideline violations were identified from the provided changes; however, there is a documentation consistency gap in the generated docs/ HTML where log4r text remains despite source updates.

@swaraj-neu
swaraj-neu requested a review from tonywu1999 July 16, 2026 16:00
@swaraj-neu swaraj-neu self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7461523e-e8d4-42e7-b60f-2f41c2d467fa

📥 Commits

Reviewing files that changed from the base of the PR and between 63f46a5 and 17be83f.

📒 Files selected for processing (2)
  • DESCRIPTION
  • R/utils_logging.R

📝 Walkthrough

Walkthrough

The package replaces log4r appenders with internal file, console, and null appenders, updates logging configuration and package imports, documents the new helpers, bumps the version to 1.23.3, and removes log4r-specific vignette wording.

Changes

Internal logging replacement

Layer / File(s) Summary
Internal appender utilities
R/utils_logging.R, man/dot-*.Rd
Adds formatted file and console appenders, updates null-appender wording, and documents the internal helpers.
Logging configuration and package wiring
DESCRIPTION, NAMESPACE, R/utils_logging.R
Removes log4r appender imports and configures load-time and runtime logging with the internal appenders.
Package metadata and logging description
DESCRIPTION, vignettes/msstats_data_format.Rmd
Bumps the package version to 1.23.3 and removes the log4r reference from the logging documentation.

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

Suggested reviewers: tonywu1999

Poem

A rabbit tuned the logbook bright,
With gentle lines for day and night.
No borrowed tools hop through the door,
New little appenders write some more.
Version carrots rise—what a delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only contains the template headings and placeholder text, with no actual motivation, changes, testing, or checklist details. Fill in each section with concrete motivation/context, a bullet list of changes, testing performed, and completed checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately states the main change: removing log4r and switching to base R logging.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MSstatsConvert/work/20260716_remove_log4r_dependency

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
R/utils_logging.R (2)

15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Escape brackets in Roxygen comment to prevent unintended link generation.

Because Markdown is enabled in roxygen2, the text [timestamp] is interpreted as a link to the timestamp function topic, producing \link{timestamp} in the generated .Rd file (as seen in man/dot-formatLogMessage.Rd). Escaping the brackets prevents this unintentional formatting.

🛠️ Proposed fix
-#' Format a log line as "LEVEL [timestamp] message"
+#' Format a log line as "LEVEL \[timestamp\] message"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@R/utils_logging.R` at line 15, Update the roxygen comment describing the log
format above dot-formatLogMessage to escape both brackets around timestamp,
preserving the displayed “LEVEL [timestamp] message” text without allowing
roxygen2 Markdown to generate a link.

39-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Route console logs to stderr() instead of stdout()
cat() writes to standard output by default, so these messages will mix with captured output and piped data. Switching this appender to file = stderr() keeps diagnostics separate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@R/utils_logging.R` around lines 39 - 45, Update .consoleAppender so its cat()
call writes formatted log messages to stderr() via the file argument, preserving
the existing message formatting and single-line behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@R/utils_logging.R`:
- Around line 27-36: Update .fileAppender so append = FALSE truncates the log
file once during appender creation, then make each closure write use append =
TRUE. Preserve append = TRUE behavior and ensure multiple log calls retain all
entries.

---

Nitpick comments:
In `@R/utils_logging.R`:
- Line 15: Update the roxygen comment describing the log format above
dot-formatLogMessage to escape both brackets around timestamp, preserving the
displayed “LEVEL [timestamp] message” text without allowing roxygen2 Markdown to
generate a link.
- Around line 39-45: Update .consoleAppender so its cat() call writes formatted
log messages to stderr() via the file argument, preserving the existing message
formatting and single-line behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a0f66683-9d96-4c9f-be5f-a2ef9fcc05de

📥 Commits

Reviewing files that changed from the base of the PR and between 038dd5d and 63f46a5.

📒 Files selected for processing (8)
  • DESCRIPTION
  • NAMESPACE
  • R/utils_logging.R
  • man/dot-consoleAppender.Rd
  • man/dot-fileAppender.Rd
  • man/dot-formatLogMessage.Rd
  • man/dot-nullAppender.Rd
  • vignettes/msstats_data_format.Rmd
💤 Files with no reviewable changes (1)
  • NAMESPACE

Comment thread R/utils_logging.R
Comment on lines +27 to +36
#' File appender: returns a function(level, ...) that writes one line to a file
#' @keywords internal
.fileAppender = function(log_file_path, append = TRUE) {
force(log_file_path)
force(append)
function(level, ...) {
cat(.formatLogMessage(level, ...), file = log_file_path, sep = "",
append = append)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the behavior of R's cat function when append=FALSE
Rscript -e '
path <- "test_log.txt"
cat("First log line\n", file=path, append=FALSE)
cat("Second log line\n", file=path, append=FALSE)
cat("File contents:\n")
cat(readLines(path), sep="\n")
'

Repository: Vitek-Lab/MSstatsConvert

Length of output: 207


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target file with line numbers and surrounding context.
git ls-files 'R/utils_logging.R'
wc -l R/utils_logging.R
cat -n R/utils_logging.R | sed -n '1,120p'

# Search for .fileAppender usages and related logging helpers.
rg -n "\.fileAppender|append = FALSE|fileAppender|formatLogMessage|log_file_path" R

Repository: Vitek-Lab/MSstatsConvert

Length of output: 11381


Log file is truncated on every write when append = FALSE. In R/utils_logging.R:29-35, the closure passes append = append to cat() for every message, so an existing file gets reopened in truncate mode on each log call and only the last entry survives. Truncate once when the appender is created, then always write with append = TRUE.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@R/utils_logging.R` around lines 27 - 36, Update .fileAppender so append =
FALSE truncates the log file once during appender creation, then make each
closure write use append = TRUE. Preserve append = TRUE behavior and ensure
multiple log calls retain all entries.

@tonywu1999
tonywu1999 merged commit be57c68 into devel Jul 16, 2026
1 of 2 checks passed
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