mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
Added lumberjack library for log rolling
This commit is contained in:
parent
afd6b7ea27
commit
bb5a322ce2
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/go-syslog"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"github.com/mholt/caddy/middleware/errors"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
// Errors configures a new gzip middleware instance.
|
||||
|
@ -35,10 +36,15 @@ func Errors(c *Controller) (middleware.Middleware, error) {
|
|||
return err
|
||||
}
|
||||
} else if handler.LogFile != "" {
|
||||
file, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||
_, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file = &lumberjack.Logger{
|
||||
Filename: handler.LogFile,
|
||||
MaxSize: 20,
|
||||
MaxBackups: 10,
|
||||
}
|
||||
}
|
||||
|
||||
handler.Log = log.New(file, "", 0)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/mholt/caddy/middleware"
|
||||
caddylog "github.com/mholt/caddy/middleware/log"
|
||||
"github.com/mholt/caddy/server"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
// Log sets up the logging middleware.
|
||||
|
@ -34,10 +35,15 @@ func Log(c *Controller) (middleware.Middleware, error) {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
file, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||
_, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file = &lumberjack.Logger{
|
||||
Filename: rules[i].OutputFile,
|
||||
MaxSize: 20,
|
||||
MaxBackups: 10,
|
||||
}
|
||||
}
|
||||
|
||||
rules[i].Log = log.New(file, "", 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user