forked from jlelse/GoBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpLogs.go
More file actions
32 lines (28 loc) · 779 Bytes
/
Copy pathhttpLogs.go
File metadata and controls
32 lines (28 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
})
}