-
Notifications
You must be signed in to change notification settings - Fork 36
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
Support for structured logging #183
Conversation
blocked by: #184 |
9f5c408
to
fb7d284
Compare
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 had a quick read through the documentation of slog and I'm not sure if we actually need it? The json logging is awesome, I guess, but again is that ever useful here? When you get an error its usually just a single string and there isn't really that much useful context to provide imo.
But anyway that's not my main concern. My actual main concern is that this is potentially breaking the output contract and is adding inconsistency because we'll keep using fmt and slog now. What I mean is that, there are people who've written shell scripts to interact with spacectl, I'm afraid if we change the output, we might affect those. Maybe I missed something in the docs of slog though?
}, | ||
Before: func(c *cli.Context) error { | ||
var logger *slog.Logger | ||
switch c.String("log-format") { |
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.
Nit: It's kinda nicer when flags are defined vars as we can later use those to extract values from context: https://github.com/spacelift-io/spacectl/blob/main/internal/cmd/module/create_version.go#L13
You could just define them above main here 🤷🏻
IMHO it's crucial when doing log analysis and it's super useful when automating things, e.g.
I bet it's not just shell scripts, but also CI/CD pipelines. Parsing those logs if they are not structured can be really painful. Even if using text format and not JSON, the columns are easier to work with when using slog rather than fmt.Println(). We could instrument the cli with usage metrics to get some data on how it's actually being used, but that brings in a huge set of problems of its own.
You're absolutely right and the way I think about this is: do we want to stick with Obviously, there are more ways to approach it and to me, it looks like a judgment call on how fast you want to move vs. how much you want to avoid breaking things. Should we get more feedback from the team?
That's what I was concerned about as well, but it's a significant effort to switch away from fmt and I wanted to start the conversation before putting in the effort. |
Signed-off-by: Michal Wasilewski <[email protected]>
fb7d284
to
872c498
Compare
@mwasilew2, great response with valid points there.
I do not own |
I think overall this change is fine. I don't think there's an issue with altering the contract here because the logging is going to stderr rather than stdout. The main thing that could break the contract would be if, for example, we ended up sending log messages to stdout for a command like So basically in my mind there's two things at play here:
I think it's entirely reasonable for someone to rely on command output as part of automation, and we need to be careful when changing that, but I don't think there's any contract in place when it comes to log output. Ok, maybe three things actually - we also need to care about what the usability is like when not using |
we're not doing this |
Note: there's 74 candidates for switching from fmt.Println to log.*
If we decide to do it, I think it should be in a separate PR.