DiscardAfterClose is an io.WriteCloser that discards writes after it is closed without errors. It is useful as a target for a slog.Sink such that an underlying WriteCloser, like a file, can be cleaned up without race conditions from still-active loggers.
(wc io.WriteCloser)
| 15 | // It is useful as a target for a slog.Sink such that an underlying WriteCloser, like a file, can |
| 16 | // be cleaned up without race conditions from still-active loggers. |
| 17 | func DiscardAfterClose(wc io.WriteCloser) io.WriteCloser { |
| 18 | return &discardAfterClose{wc: wc} |
| 19 | } |
| 20 | |
| 21 | func (d *discardAfterClose) Write(p []byte) (n int, err error) { |
| 22 | d.Lock() |
no outgoing calls