-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: make logger easily replaceable #15358
Conversation
@@ -1,5 +1,5 @@ | |||
--- | |||
sidebar_position: 0 | |||
sidebar_position: 1 |
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.
unrelated: #15354 (comment)
@@ -51,20 +50,11 @@ type Context struct { | |||
Logger log.Logger | |||
} | |||
|
|||
// ErrorCode contains the exit code for server exit. |
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.
This was not used.
server/util.go
Outdated
@@ -116,25 +125,25 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) | |||
// is used to read and parse the application configuration. Command handlers can | |||
// fetch the server Context to get the CometBFT configuration or to get access | |||
// to Viper. | |||
func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) error { | |||
func CreateServerContextFromConfig(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) (*Context, error) { |
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.
Do you think @tac0turtle this conveys enough what the function does? (which is more than creating a server context, as it calls interceptConfigs
).
I feel like maybe InterceptConfigsPreRunHandlerNoLoggerNoSaveContext
, while hideous, will convey more what this does. I am open for a better name too 😄.
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.
Actually, I even think, this could be named InterceptConfigsPreRunHandler
and have the other one be renamed to something more clear. However doing that is API breaking, so not ideal.
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.
Updated to InterceptConfigsAndCreateContext
.
default: | ||
os.Exit(1) | ||
} | ||
panic(err) |
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.
Does this keep the exit code of 1? If not, please revert.
Description
Closes: #15341
This creates an alternative to
InterceptConfigsPreRunHandler
which does not configure a logger and does not set the server context.This allows apps to keep using
InterceptConfigsPreRunHandler
from the SDK to keep the same behavior, or use the alternative function to configure their logger, without having to copy the whole server packages (due to some internal functions).Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change