feat: add log message color configuration#108
Conversation
synackd
left a comment
There was a problem hiding this comment.
I tested this and it works well.
However, there is a missing piece that is required for config merging to work correctly. For instance, if I:
# Set value in user config
ochami config set log.color on
I can see it get changed in the user config:
$ ochami config show log.color --user
on
But the merged config uses the default value:
$ ./ochami config show log.color
auto
To fix this, we'll have to add a case for this config value in the custom config unmarshaller. There is already code there for timeout (case statement, default value setting) that can serve as a reference.
|
I adjusted the title of this PR to follow Conventional Commit format for the future squash merge. |
Is this desired behavior, though? The other two logging options don't have any default handling in that style, instead the program exits with an error if they aren't specified, and the defaulting appears to be handled by virtue of the options being specified in the default config. I've implemented a quick fix that solves the issue (outside of the config unmarshaling code, since the ConfigLog struct doesn't already have an UnmarshalYAML method). |
| if lc == "auto" || lc == "" { | ||
| cw.NoColor = !term.IsTerminal(int(os.Stderr.Fd())) | ||
| } else if lc == "on" { | ||
| cw.NoColor = false | ||
| } else if lc == "off" { | ||
| cw.NoColor = true | ||
| } else { | ||
| return fmt.Errorf("invalid log-color: %s", lc) | ||
| } |
There was a problem hiding this comment.
Could we make this a switch-case?
switch lc {
case "", "auto":
cw.NoColor = !term.IsTerminal(int(os.Stderr.Fd()))
case "on":
cw.NoColor = false
case "off":
cw.NoColor = true
default:
return fmt.Errorf("invalid log-color: %s", lc)
}
The desired behavior is to use the following precedence for configuration options:
What I am seeing now is that changing the |
|
Also, would you mind rebasing onto main to resolve the latest changes? |
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
Signed-off-by: Ethan Clark <ethan.clark@trojans.dsu.edu>
This looks like a bug in the code that loads all the logging config. I'm able to reproduce the same behavior with the log.format and log.level options as well. A fix might be better relegated to its own PR. |
Pull Request Template
Thank you for your contribution! Please ensure the following before submitting:
Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryDescription
Adds a
--log-coloroption for controlling colored log output. In addition to "on" and "off", "auto" (the default) will detect whether or not stderr is a terminal and act accordingly.Type of Change
For more info, see Contributing Guidelines.