@@ -117,24 +117,18 @@ func (w *fileWriter) swap() {
117
117
// We need to make sure that the log file is written to disk before closing the file.
118
118
if err := w .fd .Sync (); err != nil {
119
119
internal .EchoError ("Failed to sync log file %s: %s." , w .name , err )
120
- return
121
120
}
122
121
// On the windows platform, the file must be closed before renaming the file.
123
122
// We need to ignore the error that the file is closed.
124
123
if err := w .fd .Close (); err != nil {
125
- e , ok := err .(* os.PathError )
126
- if ! ok || e .Err != os .ErrClosed {
127
- internal .EchoError ("Failed to close log file %s: %s." , w .name , err )
128
- return
129
- }
124
+ internal .EchoError ("Failed to close log file %s: %s." , w .name , err )
130
125
}
131
126
// Accurate to the nanosecond, it maximizes the assurance that file names are not duplicated.
132
127
suffix := time .Now ().Format ("20060102150405.000000000" )
133
128
if err := os .Rename (w .name , w .name + "." + suffix ); err != nil {
134
129
internal .EchoError ("Failed to rename log file %s to %s.%s: %s." , w .name , w .name , suffix , err )
135
- return
136
130
}
137
- fd , err := os .OpenFile (w .name , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0666 )
131
+ fd , err := os .OpenFile (w .name , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0666 )
138
132
if err != nil {
139
133
internal .EchoError ("Failed to open log file %s: %s." , w .name , err )
140
134
return
0 commit comments