-
Notifications
You must be signed in to change notification settings - Fork 8
HYPERFLEET-458 - Migrate from glog to slog-based structured logging #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,14 @@ package server | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "time" | ||
|
|
||
| _ "github.com/auth0/go-jwt-middleware" | ||
| _ "github.com/golang-jwt/jwt/v4" | ||
| "github.com/golang/glog" | ||
| gorillahandlers "github.com/gorilla/handlers" | ||
| sdk "github.com/openshift-online/ocm-sdk-go" | ||
| "github.com/openshift-online/ocm-sdk-go/authentication" | ||
|
|
@@ -37,9 +38,9 @@ func NewAPIServer() Server { | |
|
|
||
| if env().Config.Server.EnableJWT { | ||
| // Create the logger for the authentication handler: | ||
| authnLogger, err := sdk.NewGlogLoggerBuilder(). | ||
| InfoV(glog.Level(1)). | ||
| DebugV(glog.Level(5)). | ||
| authnLogger, err := sdk.NewStdLoggerBuilder(). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was curios and looked at the definition of this, which says We could update it to call that logging.NewStdLoggerBuilder() directly and not the depcrecated one. |
||
| Streams(os.Stdout, os.Stderr). | ||
| Debug(false). | ||
| Build() | ||
| check(err, "Unable to create authentication logger") | ||
|
|
||
|
|
@@ -117,16 +118,16 @@ func (s apiServer) Serve(listener net.Listener) { | |
| } | ||
|
|
||
| // Serve with TLS | ||
| glog.Infof("Serving with TLS at %s", env().Config.Server.BindAddress) | ||
| slog.Info("Serving with TLS", "address", env().Config.Server.BindAddress) | ||
| err = s.httpServer.ServeTLS(listener, env().Config.Server.HTTPSCertFile, env().Config.Server.HTTPSKeyFile) | ||
| } else { | ||
| glog.Infof("Serving without TLS at %s", env().Config.Server.BindAddress) | ||
| slog.Info("Serving without TLS", "address", env().Config.Server.BindAddress) | ||
| err = s.httpServer.Serve(listener) | ||
| } | ||
|
|
||
| // Web server terminated. | ||
| check(err, "Web server terminated with errors") | ||
| glog.Info("Web server terminated") | ||
| slog.Info("Web server terminated") | ||
| } | ||
|
|
||
| // Listen only start the listener, not the server. | ||
|
|
@@ -139,15 +140,16 @@ func (s apiServer) Listen() (listener net.Listener, err error) { | |
| func (s apiServer) Start() { | ||
| listener, err := s.Listen() | ||
| if err != nil { | ||
| glog.Fatalf("Unable to start API server: %s", err) | ||
| slog.Error("Unable to start API server", "error", err) | ||
| os.Exit(1) | ||
| } | ||
| s.Serve(listener) | ||
|
|
||
| // after the server exits but before the application terminates | ||
| // we need to explicitly close Go's sql connection pool. | ||
| // this needs to be called *exactly* once during an app's lifetime. | ||
| if err := env().Database.SessionFactory.Close(); err != nil { | ||
| glog.Errorf("Error closing database connection: %v", err) | ||
| slog.Error("Error closing database connection", "error", err) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the error for arm64 , since I never had an error working on a Macbook M3 and also the image
openapitools/openapi-generator-cli:v7.16.0and is the one used in Sentinel....was that one also giving you problems?
Either way, it doesn't hurt if this fixes errors, and we may transition to discard completely the Java based generator in favor of a faster go-based one (without containers)