Closed Akash-Singh04 closed 1 month ago
@slayerjain Kindly review the PR and let me know if any changes are required.
Also fix the merge conflicts please
@PranshuSrivastava Kindly review this PR and have a look at the attached video to better understand the implementation, Thank You!
Also please fix the merge conflicts
Hey @Akash-Singh04 please update your branch with the refactoring changes. Mostly the code where the color is decided is same. Major change would be around cli. you can add the flag in this file https://github.com/keploy/keploy/blob/7febf76bd7b1230604d9b8afb5add32e703ba34d/cli/provider/cmd.go#L153 please add the flag in the config also and I think it is better to use persistent flag for this flag. You can discuss with the reviewer and go with.
@charankamarapu @PranshuSrivastava The pr is ready after refactoring! Do let me know if there are any further deliverables
Looks the color is not being changed in the correct place, I am still getting colored logs in the beginning
Looks the color is not being changed in the correct place, I am still getting colored logs in the beginning
The reason being that the logger is initially set-up here:
func NewColor(cfg zapcore.EncoderConfig, enableColor bool) (enc zapcore.Encoder) { if enableColor { return color{ EncoderConfig: &cfg, Encoder: zapcore.NewConsoleEncoder(cfg), } } // fmt.Println("Color is disabled") return zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()) }
Then when the command runs, and the flags are read, we change the color of the logger:
if !c.cfg.EnableANSIColor { c.logger.Info("Color encoding is disabled") logger, err := log.ChangeColorEncoding() *c.logger = *logger if err != nil { errMsg := "failed to change color encoding" utils.LogError(c.logger, err, errMsg) return errors.New(errMsg) } }
This is due to the current flow of commands in the v2 codebase. For the most part it correctly disables the ANSI color codes except in the beginning while the flags are being setup.
CC: @PranshuSrivastava
Ok, the first log can be left colored as we haven't fully read the flags by that time, but the second log is being printed by you right? So why can't you just print it after changing the colors instead of before it?
@PranshuSrivastava Your requested changes have been made
@PranshuSrivastava Your requested changes have been made
Hey @Akash-Singh04, I think the flag should be disableANSIColor
since, the value for the enableANSIColor
is true by default. Instead the value can be false and flag can be --disableANSIColor
. @PranshuSrivastava would that be ok right?
@re-Tick Yes thats good. I just want the name to be short
@re-Tick @PranshuSrivastava Your requested changes have been made
Related Issue
Closes: #1520
Describe the changes you've made
--enableANSIColor
PersistantFlag to CLI to enable/disable ASNI Color Codes Example of enabled ANSI Colors in Log files:Type of change
Please let us know if any test cases are added
NIL
Describe if there is any unusual behaviour of your code(Write
NA
if there isn't)NIL
Checklist:
Screenshots (if any)
Usage:
| | |
** |
|
Below is an attached video of the implementation in action:
https://github.com/keploy/keploy/assets/114267538/eac44ce0-fbfb-41a1-90a8-b62d908e22a5