Skip to content

Commit a9321ad

Browse files
committed
fixed
1 parent 99bd934 commit a9321ad

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

rotatelogs.go

+5-28
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ func (r *Rotate) Write(bytes []byte) (n int, err error) {
9191
// getBusinessWriter 获取 business io.Writer
9292
func (r *Rotate) getBusinessWriter(business string) (io.Writer, error) {
9393
var pattern *strftime.Strftime
94-
if business != "" {
95-
slice := strings.Split(r.pattern.Pattern(), "/")
96-
if slice[len(slice)-2] != business {
97-
slice = append(slice[:len(slice)-1], business, slice[len(slice)-1])
98-
pattern, _ = strftime.New(strings.Join(slice, "/"))
99-
}
94+
slice := strings.Split(r.pattern.Pattern(), "/")
95+
if slice[len(slice)-2] != business {
96+
slice = append(slice[:len(slice)-1], business, slice[len(slice)-1])
97+
pattern, _ = strftime.New(strings.Join(slice, "/"))
10098
}
10199
filename := GenerateFile(pattern, r.clock, r.rotationTime)
102100
out, err := CreateFile(filename)
@@ -113,29 +111,8 @@ func (r *Rotate) getWriter() (io.Writer, error) {
113111
if err != nil {
114112
return nil, err
115113
}
116-
err = r.out.Close()
117-
if err != nil {
118-
return nil, err
119-
}
114+
_ = r.out.Close()
120115
r.out = out
121116
r.filename = filename
122117
return out, nil
123118
}
124-
125-
// Close satisfies the io.Closer interface. You must
126-
// call this method if you performed any writes to
127-
// the object.
128-
func (r *Rotate) Close() error {
129-
r.mutex.Lock()
130-
defer r.mutex.Unlock()
131-
132-
if r.out == nil {
133-
return nil
134-
}
135-
err := r.out.Close()
136-
if err != nil {
137-
return err
138-
}
139-
r.out = nil
140-
return nil
141-
}

0 commit comments

Comments
 (0)