MCPcopy
hub / github.com/CodisLabs/codis / roll

Method roll

pkg/utils/log/rolling.go:42–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40)
41
42func (r *rollingFile) roll() error {
43 suffix := time.Now().Format(string(r.rolling))
44 if r.file != nil {
45 if suffix == r.fileFrag {
46 return nil
47 }
48 r.file.Close()
49 r.file = nil
50 }
51 r.fileFrag = suffix
52 r.filePath = fmt.Sprintf("%s.%s", r.basePath, r.fileFrag)
53
54 if dir, _ := filepath.Split(r.basePath); dir != "" && dir != "." {
55 if err := os.MkdirAll(dir, 0777); err != nil {
56 return errors.Trace(err)
57 }
58 }
59
60 f, err := os.OpenFile(r.filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
61 if err != nil {
62 return errors.Trace(err)
63 } else {
64 r.file = f
65 return nil
66 }
67}
68
69func (r *rollingFile) Close() error {
70 r.mu.Lock()

Callers 1

WriteMethod · 0.95

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected