MCPcopy
hub / github.com/docker/docker-agent / rotate

Method rotate

pkg/logging/rotate.go:105–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103}
104
105func (r *RotatingFile) rotate() error {
106 if err := r.file.Close(); err != nil {
107 return err
108 }
109
110 // Remove the oldest backup if it exists
111 oldest := fmt.Sprintf("%s.%d", r.path, r.maxBackups)
112 _ = os.Remove(oldest)
113
114 // Shift existing backups: .2 -> .3, .1 -> .2, etc.
115 for i := r.maxBackups - 1; i >= 1; i-- {
116 oldPath := fmt.Sprintf("%s.%d", r.path, i)
117 newPath := fmt.Sprintf("%s.%d", r.path, i+1)
118 _ = os.Rename(oldPath, newPath)
119 }
120
121 // Rename current log to .1
122 if err := os.Rename(r.path, r.path+".1"); err != nil && !os.IsNotExist(err) {
123 return err
124 }
125
126 r.size = 0
127 return r.openFile()
128}

Callers 1

WriteMethod · 0.95

Calls 3

openFileMethod · 0.95
CloseMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected