2016-05-06 13:46:13 +00:00
|
|
|
package progress
|
|
|
|
|
2016-12-07 16:27:51 +00:00
|
|
|
import "os"
|
2016-05-06 13:46:13 +00:00
|
|
|
|
|
|
|
// progressLogger provides a wrapper around an os.File that can either
|
|
|
|
// write to the file or ignore all writes completely.
|
|
|
|
type progressLogger struct {
|
|
|
|
writeData bool
|
|
|
|
log *os.File
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write will write to the file and perform a Sync() if writing succeeds.
|
|
|
|
func (l *progressLogger) Write(b []byte) error {
|
|
|
|
if l.writeData {
|
2016-12-07 15:33:33 +00:00
|
|
|
return nil
|
2016-05-06 13:46:13 +00:00
|
|
|
}
|
2016-12-07 15:33:33 +00:00
|
|
|
if _, err := l.log.Write(b); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return l.log.Sync()
|
2016-05-06 13:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close will call Close() on the underlying file
|
|
|
|
func (l *progressLogger) Close() error {
|
|
|
|
if l.log != nil {
|
|
|
|
return l.log.Close()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown will cause the logger to ignore any further writes. It should
|
|
|
|
// be used when writing causes an error.
|
|
|
|
func (l *progressLogger) Shutdown() {
|
|
|
|
l.writeData = false
|
|
|
|
}
|