WIP, but this is going to become my new blog CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
766 B

package main
import (
"net/http"
"time"
"github.com/gorilla/handlers"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
)
var logf *rotatelogs.RotateLogs
func initHTTPLog() (err error) {
if !appConfig.Server.Logging {
return nil
}
logf, err = rotatelogs.New(
appConfig.Server.LogFile+".%Y%m%d",
rotatelogs.WithLinkName(appConfig.Server.LogFile),
rotatelogs.WithClock(rotatelogs.UTC),
rotatelogs.WithMaxAge(30*24*time.Hour),
rotatelogs.WithRotationTime(24*time.Hour),
)
return
}
func logMiddleware(next http.Handler) http.Handler {
h := handlers.CombinedLoggingHandler(logf, next)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Remove remote address for privacy
r.RemoteAddr = ""
h.ServeHTTP(w, r)
})
}