feat(logging): add --log-file option and catch SIGHUP to reopen#393
Open
gclough wants to merge 2 commits into
Open
feat(logging): add --log-file option and catch SIGHUP to reopen#393gclough wants to merge 2 commits into
gclough wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds optional file-based logging to vip-manager via a new --log-file / log-file config option, and introduces SIGHUP handling so the process can close/reopen the log file after rotation (e.g. via logrotate postrotate).
Changes:
- Add
log-fileconfiguration/flag and wire logger initialization to write to a reopenable file when set. - Add SIGHUP handling in
main.goto trigger log file reopen. - Add reopenable log file implementation plus stdout/stderr redirection helpers, along with tests and documentation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vipconfig/vip-manager.yml | Documents the new optional log-file YAML key and SIGHUP rotation behavior. |
| vipconfig/redirect_windows.go | Implements best-effort stdout/stderr handle redirection on Windows when logging to a file. |
| vipconfig/redirect_unix.go | Implements fd-level stdout/stderr redirection on Unix for panic/child-process output capture. |
| vipconfig/redirect_test.go | Adds Unix-only subprocess test to validate stdout/stderr fd capture into the log file. |
| vipconfig/logfile.go | Introduces reopenableFile with Reopen() to support log rotation without copytruncate. |
| vipconfig/logfile_test.go | Tests reopen behavior and append semantics for the reopenable log file. |
| vipconfig/config.go | Adds LogFile config, initializes zap to file when set, and exposes ReopenLog(). |
| vipconfig/config_test.go | Adds tests for file logging, reopen behavior, and flag presence/parsing. |
| README.md | Documents log-file, env var VIP_LOG_FILE, and provides a logrotate example. |
| main.go | Adds SIGHUP handling to trigger log file reopen during runtime. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+65
to
+76
| _ = r.f.Sync() | ||
| _ = r.f.Close() | ||
|
|
||
| f, err := os.OpenFile(r.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| r.f = f | ||
| if r.captureStd { | ||
| return redirectStdStreams(f) | ||
| } | ||
| return nil |
| <-c | ||
| log.Info("Received exit signal") | ||
| cancel() | ||
| signal.Notify(c, os.Interrupt, syscall.SIGHUP) |
Comment on lines
+58
to
+66
| if sig == syscall.SIGHUP { | ||
| // Reopen the log file so that logrotate (via "systemctl kill | ||
| // -s HUP") can move the current file aside. No-op on stdout. | ||
| log.Info("Received SIGHUP, reopening log file") | ||
| if err := conf.ReopenLog(); err != nil { | ||
| log.Errorf("Failed to reopen log file: %s", err) | ||
| } | ||
| continue | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I don't know GO, so this is a vibe-coded attempt at fixing issue #392 . As it stands I've added this to the service file so we capture output to a file, to match our other existing services:
Possibly you'd prefer us to just use syslog and handle rotation in there? If that's the case, then we can just close this PR and that Issue.