Commit bb5a322c authored by Maxime's avatar Maxime

Added lumberjack library for log rolling

parent afd6b7ea
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment