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

Is it possible to disable rotation? #96

Closed
pims opened this issue Dec 3, 2019 · 2 comments
Closed

Is it possible to disable rotation? #96

pims opened this issue Dec 3, 2019 · 2 comments

Comments

@pims
Copy link

@pims pims commented Dec 3, 2019

In some environments, it might be advisable to disable log rotation and let another process handle that work.

I originally thought that setting MaxSize: 0 would disable log rotation, but the func (l *Logger) max() function returns the defaultMaxSize:

// max returns the maximum size in bytes of log files before rolling.
func (l *Logger) max() int64 {
	if l.MaxSize == 0 {
		return int64(defaultMaxSize * megabyte)
	}
	return int64(l.MaxSize) * int64(megabyte)
}

to preserve existing behavior, would you be open to adding a disableFileRotation field to the Logger struct and replacing the various:

if info.Size()+int64(writeLen) >= l.max() {
    return l.rotate()
}

with:

func(l *Logger) shouldRotate(currentSize, writeLen int64) bool {
   if l.disableFileRotation {
        return false
   }
   return currentSize + writeLen >= l.max()
}

This should be backward compatible behavior, since the default value for disableFileRotation would be false and only interested parties would set it to true.

Another alternative would be to set MaxSize to -1 and change behavior accordingly, but many consumer of lumberjack already error on negative values.

@xiegeo

This comment has been minimized.

Copy link

@xiegeo xiegeo commented Dec 3, 2019

The point of lumberjack is to rotate logs, if you don't need rotation, don't use lumberjack, or make it optional to use lumberjack in your codebase.

@pims

This comment has been minimized.

Copy link
Author

@pims pims commented Dec 3, 2019

@xiegeo that's fair. I was hoping to find an alternative to removing lumberjack from github.com/kubernetes/kubernetes by having a disable rotation flag, but as you pointed out, it's better to make it optional.

@pims pims closed this Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.