mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-25 00:07:36 +02:00
More visitor log fields
This commit is contained in:
parent
a32e8abc12
commit
d44a11325d
5 changed files with 99 additions and 58 deletions
server
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/gorilla/websocket"
|
||||
"golang.org/x/time/rate"
|
||||
"heckel.io/ntfy/log"
|
||||
"heckel.io/ntfy/util"
|
||||
"net/http"
|
||||
|
@ -24,9 +23,7 @@ func logv(v *visitor) *log.Event {
|
|||
|
||||
// logr creates a new log event with HTTP request and visitor fields
|
||||
func logvr(v *visitor, r *http.Request) *log.Event {
|
||||
return logv(v).
|
||||
Fields(httpContext(r)).
|
||||
Fields(requestLimiterFields(v.RequestLimiter()))
|
||||
return logv(v).Fields(httpContext(r))
|
||||
}
|
||||
|
||||
// logvrm creates a new log event with HTTP request, visitor fields and message fields
|
||||
|
@ -73,13 +70,6 @@ func websocketErrorContext(err error) log.Context {
|
|||
}
|
||||
}
|
||||
|
||||
func requestLimiterFields(limiter *rate.Limiter) map[string]any {
|
||||
return map[string]any{
|
||||
"visitor_request_limiter_limit": limiter.Limit(),
|
||||
"visitor_request_limiter_tokens": limiter.Tokens(),
|
||||
}
|
||||
}
|
||||
|
||||
func renderHTTPRequest(r *http.Request) string {
|
||||
peekLimit := 4096
|
||||
lines := fmt.Sprintf("%s %s %s\n", r.Method, r.URL.RequestURI(), r.Proto)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue