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

Added ctx object to all system struct's constructors #837

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

aelsabbahy
Copy link
Member

@aelsabbahy aelsabbahy commented Sep 9, 2023

The idea behind this commit is to set the stage for adding additional logging metadata.

Added logging support for command as an example.

Checklist
  • make test-all (UNIX) passes. CI will also test this
  • unit and/or integration tests are included (if applicable)
  • documentation is changed or added (if applicable)

Description of change

This is the simpler version of #836 it goes against the guidance here but it is a much simpler (and cleaner?) implementation.

Also, this approach didn't break any of the unit tests, like #836 did.

The idea behind this commit is to set the stage for adding aditional
logging metadata.
* Added new flags `--log-level` and `-l` to be consistent with other goss
flags.
  * `--loglevel` and `-L` will be deprecated in a future release
* Log level accepts any casing, so DEBUG and debug are both valid cli opts
* Add log level support for `add` and `autoadd` commands
@@ -48,14 +49,15 @@ func (c *Command) GetExec() string {
}

func (c *Command) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", c.ID())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using context values for this is ok, but probably more idiomatic these days to use a structured logger like the (new) slog or something like logrus and then pass that down with key-vals added.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm very interested to see what ends up as idiomatic with the introduction of slog.

Seems like it's been a heavily debated topic: golang/go#58243

I'm okay with pivoting to whatever becomes the norm once the dust settles a bit on slog and patterns emerge.

@aelsabbahy
Copy link
Member Author

Seems a bit of work piled up, going to start merging it.. since it's internal to the app we can revisit/change in a future PR.

@aelsabbahy aelsabbahy merged commit e6c727d into master Sep 14, 2023
@aelsabbahy aelsabbahy deleted the add_ctx_simple branch September 14, 2023 17:43
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