Panic if logging is attempted after Close

Attempt to catch places where logs are truncated by panicing if
logging is attempted after Close.

Test: m nothing
Change-Id: If670f20d08832ed65b63af5589b548e9815f2f0d
This commit is contained in:
Colin Cross 2019-03-21 16:36:33 -07:00
parent b98d3bcf4e
commit 1aeb049a54
1 changed files with 5 additions and 1 deletions

View File

@ -180,12 +180,16 @@ func (s *stdLogger) SetOutput(path string) *stdLogger {
return s
}
type panicWriter struct{}
func (panicWriter) Write([]byte) (int, error) { panic("write to panicWriter") }
// Close disables logging to the file and closes the file handle.
func (s *stdLogger) Close() {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.file != nil {
s.fileLogger.SetOutput(ioutil.Discard)
s.fileLogger.SetOutput(panicWriter{})
s.file.Close()
s.file = nil
}