Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow setting filemode for log files #210

Open
wants to merge 1 commit into
base: v2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lumberjack.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type Logger struct {
// using gzip. The default is not to perform compression.
Compress bool `json:"compress" yaml:"compress"`

// FileMode represents the file mode to be used when opening the new log file, 0600 is the default.
FileMode os.FileMode

size int64
file *os.File
mu sync.Mutex
Expand Down Expand Up @@ -212,7 +215,7 @@ func (l *Logger) openNew() error {
}

name := l.filename()
mode := os.FileMode(0600)
mode := l.fileMode()
info, err := osStat(name)
if err == nil {
// Copy the mode off the old logfile.
Expand Down Expand Up @@ -297,6 +300,14 @@ func (l *Logger) filename() string {
return filepath.Join(os.TempDir(), name)
}

// fileMode returns the FileMode to use when creating the log file.
func (l *Logger) fileMode() os.FileMode {
if l.FileMode == 0 {
return 0600
}
return l.FileMode
}

// millRunOnce performs compression and removal of stale log files.
// Log files are compressed if enabled via configuration and old log
// files are removed, keeping at most l.MaxBackups files, as long as
Expand Down