From 8b46c21866e28779afce8d1dc176f9859ef430e6 Mon Sep 17 00:00:00 2001 From: kevkevinpal Date: Tue, 17 Dec 2024 16:11:12 -0500 Subject: [PATCH 1/3] feat: created util to print out trace from endpoint call --- routes/people.go | 7 ++-- routes/person.go | 3 +- routes/test_routes.go | 22 +++++++++++- utils/trace.go | 81 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 utils/trace.go diff --git a/routes/people.go b/routes/people.go index 59d6b0480..1f11e5735 100644 --- a/routes/people.go +++ b/routes/people.go @@ -6,6 +6,7 @@ import ( "github.com/go-chi/chi" "github.com/stakwork/sphinx-tribes/db" "github.com/stakwork/sphinx-tribes/handlers" + "github.com/stakwork/sphinx-tribes/utils" ) func PeopleRoutes() chi.Router { @@ -14,9 +15,9 @@ func PeopleRoutes() chi.Router { peopleHandler := handlers.NewPeopleHandler(db.DB) r.Group(func(r chi.Router) { - r.Get("/", peopleHandler.GetListedPeople) - r.Get("/search", peopleHandler.GetPeopleBySearch) - r.Get("/posts", handlers.GetListedPosts) + r.Get("/", utils.TraceWithLogging(peopleHandler.GetListedPeople)) + r.Get("/search", utils.TraceWithLogging(peopleHandler.GetPeopleBySearch)) + r.Get("/posts", utils.TraceWithLogging(handlers.GetListedPosts)) r.Get("/wanteds/assigned/{uuid}", bountyHandler.GetPersonAssignedBounties) r.Get("/wanteds/created/{uuid}", bountyHandler.GetPersonCreatedBounties) r.Get("/wanteds/header", handlers.GetWantedsHeader) diff --git a/routes/person.go b/routes/person.go index 1b4246563..1c98b4625 100644 --- a/routes/person.go +++ b/routes/person.go @@ -5,6 +5,7 @@ import ( "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" "github.com/stakwork/sphinx-tribes/handlers" + "github.com/stakwork/sphinx-tribes/utils" ) func PersonRoutes() chi.Router { @@ -13,7 +14,7 @@ func PersonRoutes() chi.Router { r.Group(func(r chi.Router) { r.Get("/{pubkey}", peopleHandler.GetPersonByPubkey) r.Get("/id/{id}", peopleHandler.GetPersonById) - r.Get("/uuid/{uuid}", peopleHandler.GetPersonByUuid) + r.Get("/uuid/{uuid}", utils.TraceWithLogging(peopleHandler.GetPersonByUuid)) r.Get("/uuid/{uuid}/assets", handlers.GetPersonAssetsByUuid) r.Get("/githubname/{github}", handlers.GetPersonByGithubName) }) diff --git a/routes/test_routes.go b/routes/test_routes.go index 92a82b872..5b944adf5 100644 --- a/routes/test_routes.go +++ b/routes/test_routes.go @@ -2,6 +2,10 @@ package routes import ( "net/http" + "runtime/trace" + "log" +// "os" + "bytes" "github.com/go-chi/chi" ) @@ -10,7 +14,23 @@ func TestRoutes() chi.Router { r := chi.NewRouter() r.Get("/internal-server-error", func(w http.ResponseWriter, r *http.Request) { - panic("Forced internal server error") + // Enable tracing + //f, err := os.Create("trace.out") + var buf bytes.Buffer + //if err != nil { + // log.Fatalf("Failed to create trace output file: %v", err) + //} + //defer f.Close() + + if err := trace.Start(&buf); err != nil { + log.Fatalf("Failed to start trace: %v", err) + } + defer func() { + trace.Stop() + log.Println("Trace Data:") + log.Println(buf.String()) + }() + //panic("Forced internal server error") }) return r diff --git a/utils/trace.go b/utils/trace.go new file mode 100644 index 000000000..d7570c89c --- /dev/null +++ b/utils/trace.go @@ -0,0 +1,81 @@ +package utils + +import ( + "bytes" + "log" + "net/http" + "regexp" + "runtime/trace" + "strings" +) + +func TraceWithLogging(next http.HandlerFunc) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var buf bytes.Buffer + + // Start trace capturing + if err := trace.Start(&buf); err != nil { + http.Error(w, "Failed to start trace", http.StatusInternalServerError) + log.Fatalf("Failed to start trace: %v", err) + return + } + defer func() { + trace.Stop() + + // Extract and process trace output + traceOutput := buf.String() + //log.Println("Raw Trace Output (for debugging):", traceOutput) + // Split the trace output into lines + traceLines := strings.Split(traceOutput, "\n") + startedFormatting := false + + // Log each trace line with a line number and format + for _, line := range traceLines { + if !startedFormatting && strings.Contains(line, "start trace") { + startedFormatting = true + } else { + continue + } + + if line != "" { + traceFormatted := formatTrace(line) + for j, formattedLine := range traceFormatted { + log.Printf("%03d %s", j+1, formattedLine) + } + } + } + }() + + next(w, r) + } +} + +func splitTrace(traceString string) []string { + // Define the regex pattern for detecting file paths ending with .go + re := regexp.MustCompile(`/([^/\s]+\.go)`) + + // Replace each match with the file path followed by a newline + formattedTrace := re.ReplaceAllString(traceString, "$0\n") + + cleanRegex := regexp.MustCompile(`[^a-zA-Z0-9\s\./:_\-@()]`) + cleanedTrace := cleanRegex.ReplaceAllString(formattedTrace, "") + + + // Split the formatted trace into lines and return as a string array + return strings.Split(strings.TrimSpace(cleanedTrace), "\n") +} +func formatTrace(input string) []string { + // Find the position where "start trace" appears + startIdx := strings.Index(input, "start trace") + if startIdx == -1 { + return nil // "start trace" not found, return nil slice + } + + // Slice input string from "start trace" onwards + traceContent := input[startIdx:] + + // Use splitTrace to split and format the trace content + return splitTrace(traceContent) +} + + From e87c87e51962977c885a2df6af5ac5da073cca7c Mon Sep 17 00:00:00 2001 From: kevkevinpal Date: Thu, 19 Dec 2024 16:06:50 -0500 Subject: [PATCH 2/3] added xgo and started using Trap to intercept function calls --- go.mod | 1 + go.sum | 2 + routes/people.go | 8 ++-- routes/person.go | 2 +- routes/test_routes.go | 22 +---------- utils/logger.go | 53 +++++++++++++++++++++++++++ utils/trace.go | 85 ++++++++----------------------------------- 7 files changed, 78 insertions(+), 95 deletions(-) create mode 100644 utils/logger.go diff --git a/go.mod b/go.mod index 8b0898986..3a073f373 100644 --- a/go.mod +++ b/go.mod @@ -61,6 +61,7 @@ require ( github.com/onsi/gomega v1.26.0 // indirect github.com/robfig/cron v1.2.0 github.com/urfave/negroni v1.0.0 // indirect + github.com/xhd2015/xgo/runtime v1.0.52 // indirect golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index d389d674c..d4ae95b46 100644 --- a/go.sum +++ b/go.sum @@ -2168,6 +2168,8 @@ github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= +github.com/xhd2015/xgo/runtime v1.0.52 h1:njcRzY3Xo2AFu/qQSC4ak9+JN7xFmaI3iEUyJxoErWM= +github.com/xhd2015/xgo/runtime v1.0.52/go.mod h1:9GBQ2SzJCzpD3T+HRN+2C0TUOGv7qIz4s0mad1xJ8Jo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= diff --git a/routes/people.go b/routes/people.go index 1f11e5735..9a9d61f8f 100644 --- a/routes/people.go +++ b/routes/people.go @@ -15,10 +15,10 @@ func PeopleRoutes() chi.Router { peopleHandler := handlers.NewPeopleHandler(db.DB) r.Group(func(r chi.Router) { - r.Get("/", utils.TraceWithLogging(peopleHandler.GetListedPeople)) - r.Get("/search", utils.TraceWithLogging(peopleHandler.GetPeopleBySearch)) - r.Get("/posts", utils.TraceWithLogging(handlers.GetListedPosts)) - r.Get("/wanteds/assigned/{uuid}", bountyHandler.GetPersonAssignedBounties) + r.Get("/", utils.AutoLog(peopleHandler.GetListedPeople)) + r.Get("/search", utils.AutoLog(peopleHandler.GetPeopleBySearch)) + r.Get("/posts", utils.AutoLog(handlers.GetListedPosts)) + r.Get("/wanteds/assigned/{uuid}", utils.AutoLog(bountyHandler.GetPersonAssignedBounties)) r.Get("/wanteds/created/{uuid}", bountyHandler.GetPersonCreatedBounties) r.Get("/wanteds/header", handlers.GetWantedsHeader) r.Get("/short", handlers.GetPeopleShortList) diff --git a/routes/person.go b/routes/person.go index 1c98b4625..5cb45c9bd 100644 --- a/routes/person.go +++ b/routes/person.go @@ -14,7 +14,7 @@ func PersonRoutes() chi.Router { r.Group(func(r chi.Router) { r.Get("/{pubkey}", peopleHandler.GetPersonByPubkey) r.Get("/id/{id}", peopleHandler.GetPersonById) - r.Get("/uuid/{uuid}", utils.TraceWithLogging(peopleHandler.GetPersonByUuid)) + r.Get("/uuid/{uuid}", utils.AutoLog(peopleHandler.GetPersonByUuid)) r.Get("/uuid/{uuid}/assets", handlers.GetPersonAssetsByUuid) r.Get("/githubname/{github}", handlers.GetPersonByGithubName) }) diff --git a/routes/test_routes.go b/routes/test_routes.go index 5b944adf5..92a82b872 100644 --- a/routes/test_routes.go +++ b/routes/test_routes.go @@ -2,10 +2,6 @@ package routes import ( "net/http" - "runtime/trace" - "log" -// "os" - "bytes" "github.com/go-chi/chi" ) @@ -14,23 +10,7 @@ func TestRoutes() chi.Router { r := chi.NewRouter() r.Get("/internal-server-error", func(w http.ResponseWriter, r *http.Request) { - // Enable tracing - //f, err := os.Create("trace.out") - var buf bytes.Buffer - //if err != nil { - // log.Fatalf("Failed to create trace output file: %v", err) - //} - //defer f.Close() - - if err := trace.Start(&buf); err != nil { - log.Fatalf("Failed to start trace: %v", err) - } - defer func() { - trace.Stop() - log.Println("Trace Data:") - log.Println(buf.String()) - }() - //panic("Forced internal server error") + panic("Forced internal server error") }) return r diff --git a/utils/logger.go b/utils/logger.go new file mode 100644 index 000000000..e4685b0d4 --- /dev/null +++ b/utils/logger.go @@ -0,0 +1,53 @@ +package utils + +import ( + "log" + "os" + "github.com/stakwork/sphinx-tribes/config" +) + +type Logger struct { + infoLogger *log.Logger + warningLogger *log.Logger + errorLogger *log.Logger + debugLogger *log.Logger + machineLogger *log.Logger +} + +var Log = Logger{ + infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), + warningLogger: log.New(os.Stdout, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile), + errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), + debugLogger: log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), + machineLogger: log.New(os.Stdout, "MACHINE: ", log.Ldate|log.Ltime|log.Lshortfile), +} + +func (l *Logger) Machine(format string, v ...interface{}) { + if config.LogLevel == "MACHINE" { + l.machineLogger.Printf(format, v...) + } +} + +func (l *Logger) Debug(format string, v ...interface{}) { + if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" { + l.debugLogger.Printf(format, v...) + } +} + +func (l *Logger) Info(format string, v ...interface{}) { + if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" { + l.infoLogger.Printf(format, v...) + } +} + +func (l *Logger) Warning(format string, v ...interface{}) { + if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" { + l.warningLogger.Printf(format, v...) + } +} + +func (l *Logger) Error(format string, v ...interface{}) { + if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" || config.LogLevel == "ERROR" { + l.errorLogger.Printf(format, v...) + } +} diff --git a/utils/trace.go b/utils/trace.go index d7570c89c..650603613 100644 --- a/utils/trace.go +++ b/utils/trace.go @@ -1,81 +1,28 @@ package utils import ( - "bytes" - "log" + "context" "net/http" - "regexp" - "runtime/trace" + "fmt" "strings" + "github.com/xhd2015/xgo/runtime/core" + "github.com/xhd2015/xgo/runtime/trap" ) -func TraceWithLogging(next http.HandlerFunc) http.HandlerFunc { +func AutoLog(fn http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var buf bytes.Buffer - - // Start trace capturing - if err := trace.Start(&buf); err != nil { - http.Error(w, "Failed to start trace", http.StatusInternalServerError) - log.Fatalf("Failed to start trace: %v", err) - return - } - defer func() { - trace.Stop() - - // Extract and process trace output - traceOutput := buf.String() - //log.Println("Raw Trace Output (for debugging):", traceOutput) - // Split the trace output into lines - traceLines := strings.Split(traceOutput, "\n") - startedFormatting := false - - // Log each trace line with a line number and format - for _, line := range traceLines { - if !startedFormatting && strings.Contains(line, "start trace") { - startedFormatting = true - } else { - continue + trap.AddInterceptor(&trap.Interceptor{ + Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) { + index := strings.Index(f.File, "sphinx-tribes") + trimmed := f.File + if index != -1 { + trimmed = f.File[index:] } + fmt.Printf("%s:%d %s\n", trimmed, f.Line, f.Name) - if line != "" { - traceFormatted := formatTrace(line) - for j, formattedLine := range traceFormatted { - log.Printf("%03d %s", j+1, formattedLine) - } - } - } - }() - - next(w, r) + return nil, nil + }, + }) + fn(w, r) } } - -func splitTrace(traceString string) []string { - // Define the regex pattern for detecting file paths ending with .go - re := regexp.MustCompile(`/([^/\s]+\.go)`) - - // Replace each match with the file path followed by a newline - formattedTrace := re.ReplaceAllString(traceString, "$0\n") - - cleanRegex := regexp.MustCompile(`[^a-zA-Z0-9\s\./:_\-@()]`) - cleanedTrace := cleanRegex.ReplaceAllString(formattedTrace, "") - - - // Split the formatted trace into lines and return as a string array - return strings.Split(strings.TrimSpace(cleanedTrace), "\n") -} -func formatTrace(input string) []string { - // Find the position where "start trace" appears - startIdx := strings.Index(input, "start trace") - if startIdx == -1 { - return nil // "start trace" not found, return nil slice - } - - // Slice input string from "start trace" onwards - traceContent := input[startIdx:] - - // Use splitTrace to split and format the trace content - return splitTrace(traceContent) -} - - From 280dfe53bb37a26c73b879e600ce3c43c288da44 Mon Sep 17 00:00:00 2001 From: kevkevinpal Date: Sun, 22 Dec 2024 18:00:28 -0500 Subject: [PATCH 3/3] moved xgo to be used on all routes and internalServerMiddleware --- Dockerfile | 8 ++++++-- routes/index.go | 16 +++++++++++++++ routes/people.go | 9 ++++---- routes/person.go | 3 +-- utils/logger.go | 53 ------------------------------------------------ utils/trace.go | 28 ------------------------- 6 files changed, 27 insertions(+), 90 deletions(-) delete mode 100644 utils/logger.go delete mode 100644 utils/trace.go diff --git a/Dockerfile b/Dockerfile index d840376cd..3b80b05b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,15 @@ WORKDIR /app COPY go.mod . COPY go.sum . +# Installing xgo +RUN go install github.com/xhd2015/xgo/cmd/xgo@latest +ENV PATH="/usr/local/xgo/bin:${PATH}" + RUN go mod download COPY . . -RUN CGO_ENABLED=0 go build +RUN CGO_ENABLED=0 xgo build # final stage FROM alpine:latest @@ -24,4 +28,4 @@ COPY --from=builder /app/sphinx-tribes /app/ RUN ls app EXPOSE 5002 -ENTRYPOINT ["/app/sphinx-tribes"] \ No newline at end of file +ENTRYPOINT ["/app/sphinx-tribes"] diff --git a/routes/index.go b/routes/index.go index 2347dcca9..c6ac07f2e 100644 --- a/routes/index.go +++ b/routes/index.go @@ -9,11 +9,15 @@ import ( "os" "runtime" "time" + "strings" + "context" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/rs/cors" "github.com/urfave/negroni" + "github.com/xhd2015/xgo/runtime/core" + "github.com/xhd2015/xgo/runtime/trap" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/config" @@ -195,6 +199,18 @@ func internalServerErrorHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rr := negroni.NewResponseWriter(w) + trap.AddInterceptor(&trap.Interceptor{ + Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) { + index := strings.Index(f.File, "sphinx-tribes") + trimmed := f.File + if index != -1 { + trimmed = f.File[index:] + } + logger.Log.Machine("%s:%d %s\n", trimmed, f.Line, f.Name) + + return nil, nil + }, + }) defer func() { if err := recover(); err != nil { // Get stack trace diff --git a/routes/people.go b/routes/people.go index 9a9d61f8f..59d6b0480 100644 --- a/routes/people.go +++ b/routes/people.go @@ -6,7 +6,6 @@ import ( "github.com/go-chi/chi" "github.com/stakwork/sphinx-tribes/db" "github.com/stakwork/sphinx-tribes/handlers" - "github.com/stakwork/sphinx-tribes/utils" ) func PeopleRoutes() chi.Router { @@ -15,10 +14,10 @@ func PeopleRoutes() chi.Router { peopleHandler := handlers.NewPeopleHandler(db.DB) r.Group(func(r chi.Router) { - r.Get("/", utils.AutoLog(peopleHandler.GetListedPeople)) - r.Get("/search", utils.AutoLog(peopleHandler.GetPeopleBySearch)) - r.Get("/posts", utils.AutoLog(handlers.GetListedPosts)) - r.Get("/wanteds/assigned/{uuid}", utils.AutoLog(bountyHandler.GetPersonAssignedBounties)) + r.Get("/", peopleHandler.GetListedPeople) + r.Get("/search", peopleHandler.GetPeopleBySearch) + r.Get("/posts", handlers.GetListedPosts) + r.Get("/wanteds/assigned/{uuid}", bountyHandler.GetPersonAssignedBounties) r.Get("/wanteds/created/{uuid}", bountyHandler.GetPersonCreatedBounties) r.Get("/wanteds/header", handlers.GetWantedsHeader) r.Get("/short", handlers.GetPeopleShortList) diff --git a/routes/person.go b/routes/person.go index 5cb45c9bd..1b4246563 100644 --- a/routes/person.go +++ b/routes/person.go @@ -5,7 +5,6 @@ import ( "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" "github.com/stakwork/sphinx-tribes/handlers" - "github.com/stakwork/sphinx-tribes/utils" ) func PersonRoutes() chi.Router { @@ -14,7 +13,7 @@ func PersonRoutes() chi.Router { r.Group(func(r chi.Router) { r.Get("/{pubkey}", peopleHandler.GetPersonByPubkey) r.Get("/id/{id}", peopleHandler.GetPersonById) - r.Get("/uuid/{uuid}", utils.AutoLog(peopleHandler.GetPersonByUuid)) + r.Get("/uuid/{uuid}", peopleHandler.GetPersonByUuid) r.Get("/uuid/{uuid}/assets", handlers.GetPersonAssetsByUuid) r.Get("/githubname/{github}", handlers.GetPersonByGithubName) }) diff --git a/utils/logger.go b/utils/logger.go deleted file mode 100644 index e4685b0d4..000000000 --- a/utils/logger.go +++ /dev/null @@ -1,53 +0,0 @@ -package utils - -import ( - "log" - "os" - "github.com/stakwork/sphinx-tribes/config" -) - -type Logger struct { - infoLogger *log.Logger - warningLogger *log.Logger - errorLogger *log.Logger - debugLogger *log.Logger - machineLogger *log.Logger -} - -var Log = Logger{ - infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), - warningLogger: log.New(os.Stdout, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile), - errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), - debugLogger: log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), - machineLogger: log.New(os.Stdout, "MACHINE: ", log.Ldate|log.Ltime|log.Lshortfile), -} - -func (l *Logger) Machine(format string, v ...interface{}) { - if config.LogLevel == "MACHINE" { - l.machineLogger.Printf(format, v...) - } -} - -func (l *Logger) Debug(format string, v ...interface{}) { - if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" { - l.debugLogger.Printf(format, v...) - } -} - -func (l *Logger) Info(format string, v ...interface{}) { - if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" { - l.infoLogger.Printf(format, v...) - } -} - -func (l *Logger) Warning(format string, v ...interface{}) { - if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" { - l.warningLogger.Printf(format, v...) - } -} - -func (l *Logger) Error(format string, v ...interface{}) { - if config.LogLevel == "MACHINE" || config.LogLevel == "DEBUG" || config.LogLevel == "INFO" || config.LogLevel == "WARNING" || config.LogLevel == "ERROR" { - l.errorLogger.Printf(format, v...) - } -} diff --git a/utils/trace.go b/utils/trace.go deleted file mode 100644 index 650603613..000000000 --- a/utils/trace.go +++ /dev/null @@ -1,28 +0,0 @@ -package utils - -import ( - "context" - "net/http" - "fmt" - "strings" - "github.com/xhd2015/xgo/runtime/core" - "github.com/xhd2015/xgo/runtime/trap" -) - -func AutoLog(fn http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - trap.AddInterceptor(&trap.Interceptor{ - Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) { - index := strings.Index(f.File, "sphinx-tribes") - trimmed := f.File - if index != -1 { - trimmed = f.File[index:] - } - fmt.Printf("%s:%d %s\n", trimmed, f.Line, f.Name) - - return nil, nil - }, - }) - fn(w, r) - } -}