Skip to content

Commit

Permalink
Merge pull request moby#36523 from yolken-stripe/36521-configurable-l…
Browse files Browse the repository at this point in the history
…ogfile-perms

Make LogFile perms configurable
  • Loading branch information
thaJeztah committed Mar 12, 2018
2 parents c74cd60 + d0c1287 commit 241c904
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion daemon/logger/jsonfilelog/jsonfilelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func New(info logger.Info) (logger.Logger, error) {
return b, nil
}

writer, err := loggerutils.NewLogFile(info.LogPath, capval, maxFiles, marshalFunc, decodeFunc)
writer, err := loggerutils.NewLogFile(info.LogPath, capval, maxFiles, marshalFunc, decodeFunc, 0640)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions daemon/logger/loggerutils/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ type LogFile struct {
notifyRotate *pubsub.Publisher
marshal logger.MarshalFunc
createDecoder makeDecoderFunc
perms os.FileMode
}

type makeDecoderFunc func(rdr io.Reader) func() (*logger.Message, error)

//NewLogFile creates new LogFile
func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.MarshalFunc, decodeFunc makeDecoderFunc) (*LogFile, error) {
log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.MarshalFunc, decodeFunc makeDecoderFunc, perms os.FileMode) (*LogFile, error) {
log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, perms)
if err != nil {
return nil, err
}
Expand All @@ -55,6 +56,7 @@ func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.
notifyRotate: pubsub.NewPublisher(0, 1),
marshal: marshaller,
createDecoder: decodeFunc,
perms: perms,
}, nil
}

Expand Down Expand Up @@ -100,7 +102,7 @@ func (w *LogFile) checkCapacityAndRotate() error {
if err := rotate(name, w.maxFiles); err != nil {
return err
}
file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0640)
file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, w.perms)
if err != nil {
return err
}
Expand Down

0 comments on commit 241c904

Please sign in to comment.