Skip to content
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

Merged
merged 11 commits into from
Mar 13, 2023
Merged

feat: make logger easily replaceable #15358

merged 11 commits into from
Mar 13, 2023

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Mar 10, 2023

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@julienrbrt julienrbrt requested a review from a team as a code owner March 10, 2023 22:57
@github-prbot github-prbot requested review from a team, aaronc and atheeshp and removed request for a team March 10, 2023 22:58
@@ -1,5 +1,5 @@
---
sidebar_position: 0
sidebar_position: 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated: #15354 (comment)

server/util.go Outdated Show resolved Hide resolved
@@ -51,20 +50,11 @@ type Context struct {
Logger log.Logger
}

// ErrorCode contains the exit code for server exit.
Copy link
Member Author

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) {
Copy link
Member Author

@julienrbrt julienrbrt Mar 12, 2023

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 😄.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to InterceptConfigsAndCreateContext.

@julienrbrt julienrbrt enabled auto-merge (squash) March 13, 2023 08:40
@julienrbrt julienrbrt changed the title feat!: make logger easily replaceable feat: make logger easily replaceable Mar 13, 2023
@julienrbrt julienrbrt enabled auto-merge (squash) March 13, 2023 08:40
@julienrbrt julienrbrt merged commit abd4ac0 into main Mar 13, 2023
@julienrbrt julienrbrt deleted the julien/logger-overwrite branch March 13, 2023 09:02
default:
os.Exit(1)
}
panic(err)
Copy link
Contributor

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.

@julienrbrt julienrbrt mentioned this pull request Mar 13, 2023
19 tasks
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an API for providing different logging options
5 participants