Closed komuw closed 1 year ago
repro:
go run -race ./example/...
curl -vkL "https://127.0.0.1:65081/health" -H "Host: badHost.com"
{
"time": "2023-07-09T18:50:30.771492654Z",
"level": "ERROR",
"source": {
"function": "github.com/komuw/ong/middleware.logger.func1.1",
"file": "/home/ong/middleware/log.go",
"line": 74
},
"msg": "http_server",
"logID": "gTXenPA8mXCxQPqh",
"pid": 301538,
"logID": "KHxm2cKKfPjGqHDt",
"clientIP": "127.0.0.1",
"clientFingerPrint": "0d9kmhf55e80c",
"method": "GET",
"path": "/health",
"code": 400,
"status": "Bad Request",
"durationMS": 0,
"ongError": "ong/middleware: the HOST http header has an unexpected value: badHost.com",
"logID": "gTXenPA8mXCxQPqh"
}
repro:
package main
import (
"context"
"os"
"github.com/komuw/ong/log"
)
func main() {
l := log.New(os.Stdout, 100)(context.Background())
l.Error("my error")
}
{
"time": "2009-11-10T23:00:00Z",
"level": "ERROR",
"source": {
"function": "main.main",
"file": "/tmp/sandbox4189155437/prog.go",
"line": 12
},
"msg": "my error",
"logID": "cEKmgxtQCeDw7t3G",
"logID": "cEKmgxtQCeDw7t3G"
}
The following patch seems to fix it;
diff --git a/log/log.go b/log/log.go
index d257025..1636d2a 100644
--- a/log/log.go
+++ b/log/log.go
@@ -149,7 +149,7 @@ func (h handler) Handle(ctx context.Context, r slog.Record) error {
ctx = context.WithValue(ctx, octx.LogCtxKey, id)
newAttrs := []slog.Attr{
- {Key: logIDFieldName, Value: slog.StringValue(id)},
+ // {Key: logIDFieldName, Value: slog.StringValue(id)},
}
r.Attrs(func(a slog.Attr) bool {
if e, ok := a.Value.Any().(error); ok {