Remove logfile if it's empty before exiting
This commit is contained in:
		@@ -25,7 +25,7 @@ func main() {
 | 
			
		||||
	defer handleErrors()
 | 
			
		||||
	f := initLogging()
 | 
			
		||||
	if f != nil {
 | 
			
		||||
		defer f.Close()
 | 
			
		||||
		defer teardownLogging(f)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	lock := grabExclusiveProcessLock()
 | 
			
		||||
 
 | 
			
		||||
@@ -17,4 +17,21 @@ func initLogging() *os.File {
 | 
			
		||||
 | 
			
		||||
	log.SetOutput(f)
 | 
			
		||||
	return f
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func teardownLogging(f *os.File) {
 | 
			
		||||
	fi, err := f.Stat()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	if fi.Size() == 0 {
 | 
			
		||||
			err = os.Remove(f.Name())
 | 
			
		||||
			if err != nil {
 | 
			
		||||
					panic(err)
 | 
			
		||||
			}
 | 
			
		||||
	}
 | 
			
		||||
	err = f.Close()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user