mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-19 14:08:31 -04:00
main,log,errors: Option to disable log rotation ("rolling")
For log and errors directive, as well as process log.
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-syslog"
|
||||
gsyslog "github.com/hashicorp/go-syslog"
|
||||
"github.com/mholt/caddy"
|
||||
)
|
||||
|
||||
@@ -162,7 +162,7 @@ selectwriter:
|
||||
return err
|
||||
}
|
||||
|
||||
if l.Roller != nil {
|
||||
if l.Roller != nil && !l.Roller.Disabled {
|
||||
file.Close()
|
||||
l.Roller.Filename = l.Output
|
||||
l.writer = l.Roller.GetLogWriter()
|
||||
|
||||
@@ -20,11 +20,12 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
// LogRoller implements a type that provides a rolling logger.
|
||||
type LogRoller struct {
|
||||
Disabled bool
|
||||
Filename string
|
||||
MaxSize int
|
||||
MaxAge int
|
||||
@@ -66,10 +67,11 @@ func IsLogRollerSubdirective(subdir string) bool {
|
||||
return subdir == directiveRotateSize ||
|
||||
subdir == directiveRotateAge ||
|
||||
subdir == directiveRotateKeep ||
|
||||
subdir == directiveRotateCompress
|
||||
subdir == directiveRotateCompress ||
|
||||
subdir == directiveRotateDisable
|
||||
}
|
||||
|
||||
var invalidRollerParameterErr = errors.New("invalid roller parameter")
|
||||
var errInvalidRollParameter = errors.New("invalid roller parameter")
|
||||
|
||||
// ParseRoller parses roller contents out of c.
|
||||
func ParseRoller(l *LogRoller, what string, where ...string) error {
|
||||
@@ -79,16 +81,16 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
|
||||
|
||||
// rotate_compress doesn't accept any parameters.
|
||||
// others only accept one parameter
|
||||
if (what == directiveRotateCompress && len(where) != 0) ||
|
||||
(what != directiveRotateCompress && len(where) != 1) {
|
||||
return invalidRollerParameterErr
|
||||
if ((what == directiveRotateCompress || what == directiveRotateDisable) && len(where) != 0) ||
|
||||
((what != directiveRotateCompress && what != directiveRotateDisable) && len(where) != 1) {
|
||||
return errInvalidRollParameter
|
||||
}
|
||||
|
||||
var (
|
||||
value int
|
||||
err error
|
||||
)
|
||||
if what != directiveRotateCompress {
|
||||
if what != directiveRotateCompress && what != directiveRotateDisable {
|
||||
value, err = strconv.Atoi(where[0])
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -96,6 +98,8 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
|
||||
}
|
||||
|
||||
switch what {
|
||||
case directiveRotateDisable:
|
||||
l.Disabled = true
|
||||
case directiveRotateSize:
|
||||
l.MaxSize = value
|
||||
case directiveRotateAge:
|
||||
@@ -127,6 +131,7 @@ const (
|
||||
// defaultRotateKeep is 10 files.
|
||||
defaultRotateKeep = 10
|
||||
|
||||
directiveRotateDisable = "rotate_disable"
|
||||
directiveRotateSize = "rotate_size"
|
||||
directiveRotateAge = "rotate_age"
|
||||
directiveRotateKeep = "rotate_keep"
|
||||
@@ -134,5 +139,7 @@ const (
|
||||
)
|
||||
|
||||
// lumberjacks maps log filenames to the logger
|
||||
// that is being used to keep them rolled/maintained.
|
||||
var lumberjacks = make(map[string]*lumberjack.Logger)
|
||||
// that is being used to keep them rolled/maintained;
|
||||
// if rolling is disabled, it's just a regular
|
||||
// *os.File, not a lumberjack
|
||||
var lumberjacks = make(map[string]io.Writer)
|
||||
|
||||
Reference in New Issue
Block a user