check / check (push) Waiting to run
ratelimit.New takes ratelimit.Params (Limits, MaxClients) in place of two arguments by position. The process logger moves out of requestlog into internal/processlog, whose New takes Params (Output, InstanceName, Level); its two tests move with it unchanged. geojs.GeoJS keeps its params whole, as DNSBL, AbuseIPDB and routewatch.Client do. SPEC and README list the new package. Model: opus-5-5
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Package processlog builds the logger for the process's own messages,
|
|
// which it writes as JSON lines marked "type":"process". The request log
|
|
// is package requestlog's.
|
|
package processlog
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// Params are what New needs.
|
|
type Params struct {
|
|
// Output is where the lines are written.
|
|
Output io.Writer
|
|
// InstanceName, SWW_WAF_INSTANCE_NAME, is each line's instance.
|
|
InstanceName string
|
|
// Level, SWW_WAF_LOG_LEVEL, is the least severe level written.
|
|
Level slog.Level
|
|
}
|
|
|
|
// New returns the logger for the process's own messages: JSON lines on
|
|
// params.Output, marked "type":"process", with the time in the same form
|
|
// as a request line's. It writes only the messages at params.Level or more
|
|
// severe; the request lines requestlog.Write writes are never held back.
|
|
func New(params Params) *slog.Logger {
|
|
handler := slog.NewJSONHandler(params.Output, &slog.HandlerOptions{
|
|
Level: params.Level,
|
|
ReplaceAttr: func(groups []string, attr slog.Attr) slog.Attr {
|
|
if attr.Key == slog.TimeKey && len(groups) == 0 {
|
|
return slog.String(
|
|
slog.TimeKey,
|
|
requestlog.FormatTime(attr.Value.Time()),
|
|
)
|
|
}
|
|
|
|
return attr
|
|
},
|
|
})
|
|
|
|
return slog.New(handler).
|
|
With("type", "process", "instance", params.InstanceName)
|
|
}
|