[GH-ISSUE #228] Feature request: Allow log rotation #45

Closed
opened 2026-02-26 18:33:03 +03:00 by kerem · 1 comment
Owner

Originally created by @Steltek on GitHub (Aug 1, 2025).
Original GitHub issue: https://github.com/decke/smtprelay/issues/228

Originally assigned to: @decke on GitHub.

Request:

It would be nice to be able to rotate the log so that it doesn't grow infinitely. Right now this is prevented on Windows as the logs are being opened with an exclusive lock, preventing the file from being renamed while smtprelay is running. (Programmatically stopping smtprelay to rotate the log might cause whatever message is in flight to get lost/dropped.)

Possible implementations:

A. Change smtprelay to open the log non-exclusively and handle the case of the file potentially vanishing by re-creating it.

or

B. Add log rotation directly in smtprelay, possibly configurable in the .ini.

The lumberjack module could be useful for that: https://pkg.go.dev/gopkg.in/natefinch/lumberjack.v2?utm_source=godoc

Example code (vibe-coded so may not be correct at all):

 {
        log.SetOutput(&lumberjack.Logger{
            Filename:   *logFile,
            MaxSize:    10, // megabytes
            MaxBackups: 5,
            MaxAge:     28,   // days
            Compress:   true, // compress rotated files
        })
    }

Originally created by @Steltek on GitHub (Aug 1, 2025). Original GitHub issue: https://github.com/decke/smtprelay/issues/228 Originally assigned to: @decke on GitHub. **Request:** It would be nice to be able to rotate the log so that it doesn't grow infinitely. Right now this is prevented on Windows as the logs are being opened with an exclusive lock, preventing the file from being renamed while smtprelay is running. (Programmatically stopping smtprelay to rotate the log might cause whatever message is in flight to get lost/dropped.) **Possible implementations:** A. Change smtprelay to open the log non-exclusively and handle the case of the file potentially vanishing by re-creating it. or B. Add log rotation directly in smtprelay, possibly configurable in the .ini. The lumberjack module could be useful for that: https://pkg.go.dev/gopkg.in/natefinch/lumberjack.v2?utm_source=godoc Example code (vibe-coded so may not be correct at all): ``` { log.SetOutput(&lumberjack.Logger{ Filename: *logFile, MaxSize: 10, // megabytes MaxBackups: 5, MaxAge: 28, // days Compress: true, // compress rotated files }) } ```
kerem 2026-02-26 18:33:03 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@decke commented on GitHub (Aug 2, 2025):

I agree that logfile rotation is essential and needs to function properly.

My issue with option A is that it should already work - though probably not on Windows. As for option B, lumberjack is no longer maintained. However, there appears to be a fork called timberjack that might be a better alternative.

I am currently working on a replacement of logrus with zerolog. Logrus is becoming obsolete and relies on some unmaintained projects. I already have a partially completed patch for this, but it still needs some refinement. I will check logfile rotation as well when I have time to work on it.

<!-- gh-comment-id:3146800543 --> @decke commented on GitHub (Aug 2, 2025): I agree that logfile rotation is essential and needs to function properly. My issue with option A is that it should already work - though probably not on Windows. As for option B, lumberjack is no longer maintained. However, there appears to be a fork called [timberjack](https://github.com/DeRuina/timberjack) that might be a better alternative. I am currently working on a replacement of logrus with zerolog. Logrus is becoming obsolete and relies on some unmaintained projects. I already have a partially completed patch for this, but it still needs some refinement. I will check logfile rotation as well when I have time to work on it.
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/smtprelay#45
No description provided.