Skip to content

feat(logging): add --log-file option and catch SIGHUP to reopen#393

Open
gclough wants to merge 2 commits into
cybertec-postgresql:masterfrom
gclough:sighup_log_reopen
Open

feat(logging): add --log-file option and catch SIGHUP to reopen#393
gclough wants to merge 2 commits into
cybertec-postgresql:masterfrom
gclough:sighup_log_reopen

Conversation

@gclough

@gclough gclough commented Jul 6, 2026

Copy link
Copy Markdown

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:

# Log output to a file
StandardOutput=append:/var/log/vip-manager/vip-manager.log
StandardError=append:/var/log/vip-manager/vip-manager.log

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.

Copilot AI left a comment

Copy link
Copy Markdown

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 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-file configuration/flag and wire logger initialization to write to a reopenable file when set.
  • Add SIGHUP handling in main.go to 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 thread vipconfig/logfile.go
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
Comment thread main.go
<-c
log.Info("Received exit signal")
cancel()
signal.Notify(c, os.Interrupt, syscall.SIGHUP)
Comment thread main.go
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
}
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 50.6% (+2.6%) from 47.987% — gclough:sighup_log_reopen into cybertec-postgresql:master

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.

3 participants