Skip to content

fix: missing ext in sizerotate#36

Open
hunjixin wants to merge 1 commit intoeggjs:masterfrom
hunjixin:fix/missing_ext_in_size_rotate
Open

fix: missing ext in sizerotate#36
hunjixin wants to merge 1 commit intoeggjs:masterfrom
hunjixin:fix/missing_ext_in_size_rotate

Conversation

@hunjixin
Copy link
Copy Markdown

@hunjixin hunjixin commented Nov 6, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Fixed log rotation for compressed logs so rotated files consistently retain the compression extension and source/target paths align correctly during rotation. This prevents mismatched filenames after rotation and ensures compressed log files are handled reliably.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 6, 2025

Walkthrough

The SizeRotator rotation logic now computes an ext (gzip extension when enabled) and appends it to all rotated log file paths (maxFileName, srcPath, targetPath and mappings), ensuring rotated source and target paths include the same extension.

Changes

Cohort / File(s) Summary
Rotation path consistency
src/lib/size_rotator.ts
Compute ext (e.g., .gz) when gzip is enabled and append it to all rotated file path constructions: max file name, srcPath, targetPath, _setFile loop, and final logPath mapping. No public API changes; error handling preserved.

Sequence Diagram(s)

sequenceDiagram
    participant Timer as Size check / trigger
    participant Rotator as SizeRotator._setFile
    participant FS as File system

    Note over Rotator: compute ext = gzip ? '.gz' : ''
    Timer->>Rotator: check file size / decide rotation
    Rotator->>FS: build maxFileName = `${logPath}.maxFiles${ext}`
    Rotator->>FS: for i = max -> 1: build srcPath = `${logPath}.${i}${ext}`
    Rotator->>FS: for i = max -> 1: build targetPath = `${logPath}.${i+1}${ext}`
    FS-->>Rotator: rename / move (or ignore missing)
    Rotator->>FS: write new/empty current file (with ext logic applied where needed)
    Note right of FS: try/catch around operations preserved
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review src/lib/size_rotator.ts path-building sites to ensure every rotation-related path uses ext consistently.
  • Verify edge cases: absent files, max-file off-by-one, and gzip toggling during runtime.
  • Confirm tests (if present) cover rotation with and without gzip enabled.

Poem

🐰 I nudge the logs and tuck the .gz tight,
Hop through loops at quiet midnight,
Src and target now hold paws,
Rotations hum with matching laws,
A little hop—file paths just right! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: missing ext in sizerotate' directly and specifically describes the main change: adding missing file extension handling in the size rotator logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @hunjixin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a minor but critical bug in the log rotation mechanism. It ensures that the file extension is properly included when determining the source file path for rotation, thereby preventing potential issues with file identification and movement during the log management process.

Highlights

  • Log Rotation Fix: Corrected an oversight in the SizeRotator class where the file extension (ext) was not consistently applied to the source path during log file rotation, which could lead to incorrect file renaming or handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in the size-based log rotation where the file extension (e.g., .gz) was missing from the source path of rotated log files, ensuring gzipped logs are rotated properly. While this change is correct, a related issue exists in src/lib/size_rotator.ts outside of this diff: at line 38, maxFileName is constructed without the file extension. This will prevent the oldest gzipped log file from being deleted when gzip is enabled, causing rotation to fail. Addressing this in a follow-up would make the size rotation feature fully robust for gzipped files.

@hunjixin hunjixin force-pushed the fix/missing_ext_in_size_rotate branch from 2e0a588 to 07ecb9a Compare November 7, 2025 01:14
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/lib/size_rotator.ts (1)

63-74: Approve the rotation logic; consider extracting the duplicated extension calculation.

The rotation logic correctly applies the gzip extension to all intermediate and target paths, ensuring consistency throughout the rotation chain.

However, the ext calculation on line 63 duplicates the logic from line 22. Consider extracting this into a private helper method or computing it once and passing it as a parameter to _setFile.

Example refactor:

  _setFile(logPath: string, files: Map<string, RotateFile>) {
    const maxFiles = this.app.config.logrotator.maxFiles;
    if (files.has(logPath)) {
      return;
    }
-   const ext = this.app.config.logrotator.gzip === true ? '.gz' : '';
+   const ext = this._getExtension();
    // foo.log.2 -> foo.log.3
    // foo.log.1 -> foo.log.2
    for (let i = maxFiles - 1; i >= 1; i--) {

And add a helper method:

private _getExtension(): string {
  return this.app.config.logrotator.gzip === true ? '.gz' : '';
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e0a588 and 07ecb9a.

📒 Files selected for processing (1)
  • src/lib/size_rotator.ts (3 hunks)
🔇 Additional comments (1)
src/lib/size_rotator.ts (1)

22-39: LGTM! Gzip extension handling is correct.

The logic correctly computes the extension based on the gzip configuration and applies it to the max file name, ensuring that rotated files with gzip enabled are properly handled.

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Nov 7, 2025

can you add unittest for this bug fix?

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