Skip to content
Snippets Groups Projects
Commit 5f37e6e5 authored by OZGCloud's avatar OZGCloud
Browse files

Log umgestellt

parent ee050e8d
Branches
Tags
No related merge requests found
module antragsraum-proxy
go 1.23.0
go 1.23.0
require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.64.0
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.64.0
gopkg.in/yaml.v3 v3.0.1
go.elastic.co/ecslogrus master
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 // indirect
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 // indirect
)
......@@ -11,4 +11,5 @@ const (
)
var conf = config.LoadConfig()
var logger = logging.GetLogger()
var log := logrus.New()
log.SetFormatter(&ecslogrus.Formatter{})
......@@ -94,7 +94,7 @@ func createRueckfrageClient(grpcAddress string) (pb.AntragraumServiceClient, fun
target := GetGrpcServerUrl(grpcAddress, conf)
conn, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logger.Error("rueckfrage router failed to route: %v", err)
log.WithError(err).Error("rueckfrage router failed to route: %v", err)
return nil, nil, errors.New("rueckfrage router failed to route")
}
......@@ -126,7 +126,7 @@ func createCommandClient(grpcAddress string) (pb.CommandServiceClient, func() er
target := GetGrpcServerUrl(grpcAddress, conf)
conn, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logger.Error("command router failed to route: %v", err)
log.WithError(err).Error("command router failed to route: %v", err)
return nil, nil, errors.New("command router failed to route")
}
......@@ -169,12 +169,12 @@ func StartGrpcRouter() *grpc.Server {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", conf.Grpc.Router.Port))
if err != nil {
logger.Fatal("gRPC router failed to listen: %v", err)
log.WithError(err).Error("gRPC router failed to listen: %v", err)
}
logger.Info("gRPC router listening on port %d", conf.Grpc.Router.Port)
log.Info("gRPC router listening on port %d", conf.Grpc.Router.Port)
if err = s.Serve(lis); err != nil {
logger.Fatal("gRPC router failed to serve: %v", err)
log..WithError(err).Error("gRPC router failed to serve: %v", err)
}
return s
......
......@@ -49,18 +49,20 @@ const (
fileChunkSizeInByte = 1024 * 1024
)
func RegisterHomeEndpoint(mux *runtime.ServeMux) {
err := mux.HandlePath("GET", "/", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
defer func() {
if err := recover(); err != nil {
logger.Error("failed to recover: %v", err)
log.WithError(err).Error("failed to recover: %v", err)
http.Error(w, fmt.Sprintf("failed to recover: %v", err), http.StatusInternalServerError)
}
}()
})
if err != nil {
logger.Fatal("failed to register home endpoint: %v", err)
log.WithError(err).Error("failed to register home endpoint: %v", err)
}
}
......@@ -68,7 +70,7 @@ func RegisterAntragraumEndpoints(ctx context.Context, mux *runtime.ServeMux, grp
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := pb.RegisterAntragraumServiceHandlerFromEndpoint(ctx, mux, grpcUrl, opts)
if err != nil {
logger.Fatal("failed to register antragraum endpoints: %v", err)
log.WithError(err).Error("failed to register antragraum endpoint: %v", err)
}
}
......@@ -76,7 +78,8 @@ func RegisterCommandEndpoints(ctx context.Context, mux *runtime.ServeMux, grpcUr
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := pb.RegisterCommandServiceHandlerFromEndpoint(ctx, mux, grpcUrl, opts)
if err != nil {
logger.Fatal("failed to register command endpoints: %v", err)
log.WithError(err).Error("failed to register command endpoint: %v", err)
}
}
......@@ -84,7 +87,7 @@ func RegisterUploadAttachmentEndpoint(mux *runtime.ServeMux) {
err := mux.HandlePath("POST", "/api/v1/file", attachmentUploadHandler)
if err != nil {
logger.Fatal("failed to register file upload endpoint: %v", err)
log.WithError(err).Error("failed to register upload endpoint: %v", err)
}
}
......@@ -190,7 +193,8 @@ func RegisterGetAttachmentContentEndpoint(mux *runtime.ServeMux) {
err := mux.HandlePath("POST", "/api/v1/file/content", getAttachmentContentHandler)
if err != nil {
logger.Fatal("failed to register get file endpoint: %v", err)
log.WithError(err).Error("failed to register get file endpoint: %v", err)
}
}
......@@ -288,6 +292,6 @@ func ErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.
_, writeErr := w.Write([]byte(st.Message()))
if writeErr != nil {
logger.Fatal("failed to handle grpc error: %v", writeErr)
log.WithError(err).Error("failed to handle grpc error: %v", writeErr)
}
}
......@@ -64,7 +64,7 @@ func StartHttpGateway() *http.Server {
logger.Info("HTTP gateway listening on port %d", conf.Http.Server.Port)
if err := httpServer.ListenAndServe(); err != nil {
logger.Fatal("HTTP gateway failed to serve: %v", err)
log.WithError(err).Error("HTTP gateway failed to serve: %v", err)
}
return httpServer
......
......@@ -53,21 +53,21 @@ func RequestLoggingMiddleware(h http.Handler) http.Handler {
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("failed to read %v request body for %v: %v", r.Method, r.URL.Path, err)
log..WithError(err).Error("failed to read %v request body for %v: %v", r.Method, r.URL.Path, err)
http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest)
return
}
r.Body = io.NopCloser(bytes.NewReader(body))
logger.Debug("received %v request for %v with body: %v", r.Method, r.URL.Path, string(body))
log.Debug("received %v request for %v with body: %v", r.Method, r.URL.Path, string(body))
lw := &logResponseWriter{w, http.StatusOK}
h.ServeHTTP(lw, r)
if lw.statusCode == http.StatusOK {
logger.Debug("successfully handled %v request for %v with body: %v", r.Method, r.URL.Path, string(body))
log.Debug("successfully handled %v request for %v with body: %v", r.Method, r.URL.Path, string(body))
} else {
logger.Error("failed handling %v request for %v with body: %v, status code: %d", r.Method, r.URL.Path, string(body), lw.statusCode)
log.Error("failed handling %v request for %v with body: %v, status code: %d", r.Method, r.URL.Path, string(body), lw.statusCode)
}
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment