refactor(log): add explicit log close lifecycle
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
fd76640d69
commit
9e44fb6ea3
1 changed files with 32 additions and 0 deletions
32
log/impl.go
32
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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue