MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / Rotate

Method Rotate

pkg/logwrite/logwrite.go:80–109  ·  view source on GitHub ↗

Rotate closes the current log file, rotates the files and creates an empty log file.

(maxLogFiles int)

Source from the content-addressed store, hash-verified

78
79// Rotate closes the current log file, rotates the files and creates an empty log file.
80func (l *LogFile) Rotate(maxLogFiles int) error {
81 if err := l.File.Close(); err != nil {
82 return err
83 }
84 for i := maxLogFiles - 1; i >= 0; i-- {
85 newerFile := fmt.Sprintf("%s.%d", l.Path, i-1)
86 // special case: if index is 0 we omit the suffix i.e. we expect
87 // foo foo.1 foo.2 up to foo.<maxLogFiles-1>
88 if i == 0 {
89 newerFile = l.Path
90 }
91 olderFile := fmt.Sprintf("%s.%d", l.Path, i)
92 // overwrite the olderFile with the newerFile
93 err := os.Rename(newerFile, olderFile)
94 if os.IsNotExist(err) {
95 // the newerFile does not exist
96 continue
97 }
98 if err != nil {
99 return err
100 }
101 }
102 f, err := os.Create(l.Path)
103 if err != nil {
104 return err
105 }
106 l.File = f
107 l.BytesWritten = 0
108 return nil
109}
110
111func main() {
112 socketPath := flag.String("socket", "/var/run/memlogdq.sock", "memlogd log query socket")

Callers 1

mainFunction · 0.95

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected