Skip to content

Commit

Permalink
Try different logger
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcurtis committed Aug 25, 2024
1 parent 6bffa53 commit 70574a5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 131 deletions.
21 changes: 12 additions & 9 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"log"
"net/http"
"os"
"os/signal"
Expand All @@ -11,16 +10,20 @@ import (

"gke-info/internal/metadata"

"github.com/sirupsen/logrus"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/profiler"

httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
)

var log = logrus.New()

// main initializes the HTTP server and sets up the routes.
func main() {
// Set log output to stdout
log.SetOutput(os.Stdout)
// Set log output to stdout and use JSON formatter
log.Out = os.Stdout
log.SetFormatter(&logrus.JSONFormatter{})

tracer.Start()
defer tracer.Stop()
Expand All @@ -32,7 +35,7 @@ func main() {
),
)
if err != nil {
log.Printf("Warning: Failed to start profiler: %v", err)
log.WithField("error", err).Warn("Failed to start profiler")
}
defer profiler.Stop()

Expand All @@ -51,23 +54,23 @@ func main() {
}

go func() {
log.Printf("[INFO] Starting server on port %s...\n", port)
log.WithField("port", port).Info("Starting server...")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("[ERROR] Failed to start server: %v", err)
log.WithField("error", err).Fatal("Failed to start server")
}
}()

// Graceful shutdown
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("[INFO] Shutting down server...")
log.Info("Shutting down server...")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Fatalf("[ERROR] Server forced to shutdown: %v", err)
log.WithField("error", err).Fatal("Server forced to shutdown")
}

log.Println("[INFO] Server exiting")
log.Info("Server exiting")
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module gke-info

go 1.22.4

require github.com/stretchr/testify v1.9.0
require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
)

require (
github.com/DataDog/appsec-internal-go v1.7.0 // indirect
Expand All @@ -16,7 +19,6 @@ require (
github.com/DataDog/sketches-go v1.4.6 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect
github.com/ebitengine/purego v0.7.1 // indirect
Expand All @@ -25,7 +27,6 @@ require (
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/outcaste-io/ristretto v0.2.3 // indirect
github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect
Expand All @@ -36,12 +37,11 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tinylib/msgp v1.2.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Expand Down
Loading

0 comments on commit 70574a5

Please sign in to comment.