Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SliverHorn committed Aug 12, 2023
1 parent 99bd934 commit a9321ad
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions rotatelogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ func (r *Rotate) Write(bytes []byte) (n int, err error) {
// getBusinessWriter 获取 business io.Writer
func (r *Rotate) getBusinessWriter(business string) (io.Writer, error) {
var pattern *strftime.Strftime
if business != "" {
slice := strings.Split(r.pattern.Pattern(), "/")
if slice[len(slice)-2] != business {
slice = append(slice[:len(slice)-1], business, slice[len(slice)-1])
pattern, _ = strftime.New(strings.Join(slice, "/"))
}
slice := strings.Split(r.pattern.Pattern(), "/")
if slice[len(slice)-2] != business {
slice = append(slice[:len(slice)-1], business, slice[len(slice)-1])
pattern, _ = strftime.New(strings.Join(slice, "/"))
}
filename := GenerateFile(pattern, r.clock, r.rotationTime)
out, err := CreateFile(filename)
Expand All @@ -113,29 +111,8 @@ func (r *Rotate) getWriter() (io.Writer, error) {
if err != nil {
return nil, err
}
err = r.out.Close()
if err != nil {
return nil, err
}
_ = r.out.Close()
r.out = out
r.filename = filename
return out, nil
}

// Close satisfies the io.Closer interface. You must
// call this method if you performed any writes to
// the object.
func (r *Rotate) Close() error {
r.mutex.Lock()
defer r.mutex.Unlock()

if r.out == nil {
return nil
}
err := r.out.Close()
if err != nil {
return err
}
r.out = nil
return nil
}

0 comments on commit a9321ad

Please sign in to comment.