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

Use the context logger, if available. #180

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nyergler
Copy link
Contributor

This allows use of a non-global logger for finer grained control.

This allows use of a non-global logger for finer grained control.
@@ -68,6 +68,7 @@ var _ driver.RowsColumnTypeLength = (*rows)(nil)
var _ dbsqlrows.Rows = (*rows)(nil)

func NewRows(
ctx context.Context,
Copy link
Contributor

Choose a reason for hiding this comment

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

If the only thing we are using ctx for is to extract a logger. I would rather pass in a logger as the last argument to NewRows and ensure that dbsqllog.AddContext handles a nil first argument.

logger/logger.go Outdated
@@ -123,9 +124,24 @@ func Err(err error) *zerolog.Event {
return Logger.Err(err)
}

// Ctx returns a DBSQLLogger from the provided context. If no logger is found,
// the default logger is returned.
func Ctx(ctx context.Context) *DBSQLLogger {
Copy link
Contributor

Choose a reason for hiding this comment

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

If find this function name a bit confusing. I know that naming things here is complicated by the use of the noun context and the type context but it would be good to have a function name that more clearly tells you what it is doing. Maybe something like FromCtx? I'm open to suggestions.

- Don't pass Context directly into NewRows
- Rename function for retrieving logger from Context
@nyergler
Copy link
Contributor Author

Hi @rcypher-databricks , thanks for the review (and apologies for radio silence). I think I've addressed the feedback, let me know if you see anything else that could be improved.

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.

2 participants