mirror of https://github.com/jlelse/GoBlog
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
779 B
Go
33 lines
779 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gorilla/handlers"
|
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
|
)
|
|
|
|
func (a *goBlog) initHTTPLog() (err error) {
|
|
if !a.cfg.Server.Logging || a.cfg.Server.LogFile == "" {
|
|
return nil
|
|
}
|
|
a.logf, err = rotatelogs.New(
|
|
a.cfg.Server.LogFile+".%Y%m%d",
|
|
rotatelogs.WithLinkName(a.cfg.Server.LogFile),
|
|
rotatelogs.WithClock(rotatelogs.UTC),
|
|
rotatelogs.WithMaxAge(30*24*time.Hour),
|
|
rotatelogs.WithRotationTime(24*time.Hour),
|
|
)
|
|
return
|
|
}
|
|
|
|
func (a *goBlog) logMiddleware(next http.Handler) http.Handler {
|
|
h := handlers.CombinedLoggingHandler(a.logf, next)
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Remove remote address for privacy
|
|
r.RemoteAddr = ""
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|