@@ -26,13 +26,11 @@ const (
26
26
suffix = ".0"
27
27
)
28
28
29
- var (
30
- defaultRotator = Rotator {
31
- maxsize : 20 * Megabytes ,
32
- tailsize : 10 * Megabytes ,
33
- suffix : suffix ,
34
- }
35
- )
29
+ var defaultRotator = Rotator {
30
+ maxsize : 20 * Megabytes ,
31
+ tailsize : 10 * Megabytes ,
32
+ suffix : suffix ,
33
+ }
36
34
37
35
type Size int64
38
36
@@ -111,8 +109,8 @@ func (r *Rotator) Rotate(file string) error {
111
109
} else if err != nil {
112
110
return fmt .Errorf ("failed to open file '%s': %w" , file , err )
113
111
}
114
-
115
112
defer fd .Close ()
113
+
116
114
stat , err := fd .Stat ()
117
115
if err != nil {
118
116
return fmt .Errorf ("failed to get file stat: %w" , err )
@@ -122,7 +120,7 @@ func (r *Rotator) Rotate(file string) error {
122
120
return nil
123
121
}
124
122
125
- //otherwise we move seek to the end of the file
123
+ // otherwise we move seek to the end of the file
126
124
if _ , err := fd .Seek (- int64 (r .tailsize ), 2 ); err != nil {
127
125
return fmt .Errorf ("failed to seek to truncate position: %w" , err )
128
126
}
@@ -132,6 +130,7 @@ func (r *Rotator) Rotate(file string) error {
132
130
if err != nil {
133
131
return fmt .Errorf ("failed to create tail file '%s': %w" , tail , err )
134
132
}
133
+ defer tailFd .Close ()
135
134
136
135
if _ , err := io .Copy (tailFd , fd ); err != nil {
137
136
return fmt .Errorf ("failed to copy log tail: %w" , err )
0 commit comments