From 9e44fb6ea36139ab42b0dfcd81454f9987af5b92 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 23:45:11 +0000 Subject: [PATCH] refactor(log): add explicit log close lifecycle Co-Authored-By: Virgil --- log/impl.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/log/impl.go b/log/impl.go index ba1232c..324e132 100644 --- a/log/impl.go +++ b/log/impl.go @@ -14,6 +14,22 @@ func NewAccessLog(path string) *AccessLog { return &AccessLog{path: path} } +// Close releases the underlying file handle if the log has been opened. +// +// al := log.NewAccessLog("/var/log/proxy-access.log") +// defer al.Close() +func (l *AccessLog) Close() { + if l == nil { + return + } + l.mu.Lock() + defer l.mu.Unlock() + if l.f != nil { + _ = l.f.Close() + l.f = nil + } +} + // OnLogin writes a CONNECT line. func (l *AccessLog) OnLogin(e proxy.Event) { if l == nil || e.Miner == nil { @@ -35,6 +51,22 @@ func NewShareLog(path string) *ShareLog { return &ShareLog{path: path} } +// Close releases the underlying file handle if the log has been opened. +// +// sl := log.NewShareLog("/var/log/proxy-shares.log") +// defer sl.Close() +func (l *ShareLog) Close() { + if l == nil { + return + } + l.mu.Lock() + defer l.mu.Unlock() + if l.f != nil { + _ = l.f.Close() + l.f = nil + } +} + // OnAccept writes an ACCEPT line. func (l *ShareLog) OnAccept(e proxy.Event) { if l == nil || e.Miner == nil {