Browse code

Make logfile perms configurable

Signed-off-by: Benjamin Yolken <yolken@stripe.com>

Benjamin Yolken authored on 2018/03/08 07:54:51
Showing 2 changed files
... ...
@@ -95,7 +95,7 @@ func New(info logger.Info) (logger.Logger, error) {
95 95
 		return b, nil
96 96
 	}
97 97
 
98
-	writer, err := loggerutils.NewLogFile(info.LogPath, capval, maxFiles, marshalFunc, decodeFunc)
98
+	writer, err := loggerutils.NewLogFile(info.LogPath, capval, maxFiles, marshalFunc, decodeFunc, 0640)
99 99
 	if err != nil {
100 100
 		return nil, err
101 101
 	}
... ...
@@ -31,13 +31,14 @@ type LogFile struct {
31 31
 	notifyRotate  *pubsub.Publisher
32 32
 	marshal       logger.MarshalFunc
33 33
 	createDecoder makeDecoderFunc
34
+	perms         os.FileMode
34 35
 }
35 36
 
36 37
 type makeDecoderFunc func(rdr io.Reader) func() (*logger.Message, error)
37 38
 
38 39
 //NewLogFile creates new LogFile
39
-func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.MarshalFunc, decodeFunc makeDecoderFunc) (*LogFile, error) {
40
-	log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
40
+func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.MarshalFunc, decodeFunc makeDecoderFunc, perms os.FileMode) (*LogFile, error) {
41
+	log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, perms)
41 42
 	if err != nil {
42 43
 		return nil, err
43 44
 	}
... ...
@@ -55,6 +56,7 @@ func NewLogFile(logPath string, capacity int64, maxFiles int, marshaller logger.
55 55
 		notifyRotate:  pubsub.NewPublisher(0, 1),
56 56
 		marshal:       marshaller,
57 57
 		createDecoder: decodeFunc,
58
+		perms:         perms,
58 59
 	}, nil
59 60
 }
60 61
 
... ...
@@ -100,7 +102,7 @@ func (w *LogFile) checkCapacityAndRotate() error {
100 100
 		if err := rotate(name, w.maxFiles); err != nil {
101 101
 			return err
102 102
 		}
103
-		file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0640)
103
+		file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, w.perms)
104 104
 		if err != nil {
105 105
 			return err
106 106
 		}