Skip to content

fix: [#847] resolve log file rotation issue in daily logger#1323

Merged
hwbrzzl merged 2 commits intomasterfrom
bowen/fix-daily-log-1
Dec 29, 2025
Merged

fix: [#847] resolve log file rotation issue in daily logger#1323
hwbrzzl merged 2 commits intomasterfrom
bowen/fix-daily-log-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Dec 29, 2025

📑 Description

Closes goravel/goravel#847

This pull request improves the logging system by ensuring that all log entries consistently use the current time from the carbon package, which is especially important when using time mocking (e.g., carbon.SetTestNow()). It also adds a new test for daily log rotation and refactors some test and import naming for clarity.

Key changes include:

Logging Time Consistency:

  • All log methods in logrus_writer.go now explicitly set the log entry time using carbon.Now().StdTime(), ensuring logs reflect the correct (potentially mocked) time.
  • The daily log rotation in logger/daily.go now uses a custom rotatelogs.Clock implementation that always returns carbon.Now().StdTime(), maintaining correct rotation behavior when time is mocked. [1] [2]

Testing Improvements:

  • Added a new test TestLogrus_DailyLogWithDifferentDays to verify daily log rotation works correctly across simulated days using carbon.SetTestNow().
  • Test cleanup now asserts that log files are removed without error, improving test reliability. [1] [2]

Code and Naming Refactoring:

  • Renamed imports and variables in logrus_writer_test.go for better clarity and consistency (e.g., configmockmocksconfig, logcontractscontractslog). [1] [2] [3] [4] [5]
  • Added missing import for github.com/dromara/carbon/v2 in logrus_writer.go to support the new time handling.

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings December 29, 2025 06:42
@hwbrzzl hwbrzzl requested a review from a team as a code owner December 29, 2025 06:42
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.07%. Comparing base (428315b) to head (1a01203).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
log/logger/daily.go 33.33% 2 Missing ⚠️
log/logger/handler.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1323      +/-   ##
==========================================
- Coverage   70.09%   70.07%   -0.02%     
==========================================
  Files         282      282              
  Lines       16748    16752       +4     
==========================================
  Hits        11739    11739              
- Misses       4519     4522       +3     
- Partials      490      491       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
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 fixes a log file rotation issue in the daily logger by ensuring time consistency when using carbon's time mocking functionality. The changes enable proper testing of time-dependent behavior and improve code maintainability.

Key Changes:

  • Implemented a custom rotatelogsClock that uses carbon.Now().StdTime() to support time mocking in daily log rotation
  • Updated all log entry timestamps to use carbon.Now().StdTime() for consistency across the logging system
  • Added comprehensive test for daily log rotation across different days using carbon.SetTestNow()

Reviewed changes

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

Show a summary per file
File Description
log/writer.go Updated entry time assignment to use carbon.Now().StdTime() for mocking support
log/writer_test.go Refactored tests with updated imports, added daily rotation test, commented out duplicate test, improved mock consistency
log/logger/handler.go Enhanced error handling for first fprintf call, improved variable reuse
log/logger/daily.go Introduced custom clock implementation to support carbon time mocking in rotatelogs
.github/workflows/benchmark.yml Removed benchmark workflow file (entire file deleted)

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

@hwbrzzl hwbrzzl merged commit 9bad29e into master Dec 29, 2025
11 of 13 checks passed
@hwbrzzl hwbrzzl deleted the bowen/fix-daily-log-1 branch December 29, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The daily log driver cannot create a new log file except by restarting the server

2 participants