MCPcopy Index your code
hub / github.com/docker/docker-agent / NewRotatingFile

Function NewRotatingFile

pkg/logging/rotate.go:41–61  ·  view source on GitHub ↗

NewRotatingFile creates a new rotating file writer.

(path string, opts ...Option)

Source from the content-addressed store, hash-verified

39
40// NewRotatingFile creates a new rotating file writer.
41func NewRotatingFile(path string, opts ...Option) (*RotatingFile, error) {
42 r := &RotatingFile{
43 path: path,
44 maxSize: DefaultMaxSize,
45 maxBackups: DefaultMaxBackups,
46 }
47
48 for _, opt := range opts {
49 opt(r)
50 }
51
52 if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
53 return nil, err
54 }
55
56 if err := r.openFile(); err != nil {
57 return nil, err
58 }
59
60 return r, nil
61}
62
63func (r *RotatingFile) openFile() error {
64 file, err := os.OpenFile(r.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)

Callers 6

setupLoggingMethod · 0.92
TestRotatingFile_WriteFunction · 0.85
TestRotatingFile_RotateFunction · 0.85

Calls 2

openFileMethod · 0.95
DirMethod · 0.80