MCPcopy Create free account
hub / github.com/brimdata/super / OpenFile

Function OpenFile

service/logger/file.go:49–66  ·  view source on GitHub ↗
(path string, mode FileMode)

Source from the content-addressed store, hash-verified

47)
48
49func OpenFile(path string, mode FileMode) (zapcore.WriteSyncer, error) {
50 switch path {
51 case "stdout":
52 return zapcore.Lock(os.Stdout), nil
53 case "stderr":
54 return zapcore.Lock(os.Stderr), nil
55 case "/dev/null":
56 return zapcore.AddSync(io.Discard), nil
57 }
58 switch mode {
59 case FileModeRotate:
60 return logrotate(path)
61 case FileModeTruncate:
62 return fs.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
63 default: // FileModeAppend
64 return fs.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
65 }
66}
67
68func logrotate(path string) (zapcore.WriteSyncer, error) {
69 // Make sure directory exists

Callers 1

NewFunction · 0.70

Calls 2

OpenFileFunction · 0.92
logrotateFunction · 0.85

Tested by

no test coverage detected