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:
parent
b98d3bcf4e
commit
1aeb049a54
1 changed files with 5 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue