集成 Vector 日志处理

This commit is contained in:
2025-03-03 17:14:45 +08:00
parent cc0b74c5c2
commit 4b3cb8e354
8 changed files with 74 additions and 23 deletions

View File

@@ -122,7 +122,7 @@ func isTls(bytes []byte) (string, string, bool) {
}
func analysisHttp(reader *bufio.Reader) (string, error) {
slog.Debug("analysis http")
// reade top
top, err := httpReadLine(reader)
if err != nil {
@@ -164,7 +164,6 @@ func httpReadLine(reader *bufio.Reader) (line string, err error) {
}
func analysisTls(reader *bufio.Reader) (string, error) {
slog.Debug("analysis https")
// tls record
_, err := utils.ReadBuffer(reader, 5)

View File

@@ -48,9 +48,11 @@ func (s *Server) Run() error {
if err != nil {
return errors.Wrap(err, "dispatcher 监听失败")
}
defer utils.Close(ls)
m := cmux.New(ls)
m.SetReadTimeout(5 * time.Second)
defer m.Close()
go func() {
<-s.ctx.Done()

View File

@@ -125,7 +125,7 @@ func processHttps(ctx context.Context, req *Request) (*core.Conn, error) {
Conn: req.conn,
Reader: req.reader,
Tag: req.conn.RemoteAddr().String() + "_" + req.conn.LocalAddr().String(),
Protocol: "https",
Protocol: "http",
Dest: req.dest,
Auth: req.auth,
}, nil

View File

@@ -12,9 +12,6 @@ import (
"sync"
"syscall"
"time"
"github.com/lmittmann/tint"
"github.com/mattn/go-colorable"
)
type Context struct {
@@ -78,19 +75,23 @@ func Start() {
}
func initLog() {
writer := colorable.NewColorable(os.Stdout)
logger := slog.New(tint.NewHandler(writer, &tint.Options{
Level: slog.LevelDebug,
TimeFormat: time.RFC3339,
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
err, ok := attr.Value.Any().(error)
if !ok {
return attr
}
return tint.Err(err)
},
}))
slog.SetDefault(logger)
// writer := colorable.NewColorable(os.Stdout)
// logger := slog.New(tint.NewHandler(writer, &tint.Options{
// Level: slog.LevelDebug,
// TimeFormat: time.RFC3339,
// ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
// err, ok := attr.Value.Any().(error)
// if !ok {
// return attr
// }
// return tint.Err(err)
// },
// }))
// slog.SetDefault(logger)
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
slog.SetDefault(slog.New(handler))
}
func startFwdServer(ctx context.Context) error {