Skip to content

Conversation

@maksymvavilov
Copy link
Contributor

@maksymvavilov maksymvavilov commented Dec 10, 2025

adding text formatter and aligning logger levels with the zap implementation

@maksymvavilov maksymvavilov force-pushed the gh-657 branch 2 times, most recently from 32b1be7 to 89e636e Compare December 15, 2025 11:19
@maksymvavilov maksymvavilov marked this pull request as ready for review December 15, 2025 11:21
@maksymvavilov maksymvavilov force-pushed the gh-657 branch 5 times, most recently from f561a28 to 87d155d Compare December 19, 2025 13:39
Signed-off-by: Maskym Vavilov <mvavilov@redhat.com>
default:
loggerLevel = zapcore.InfoLevel
}
return zap.New(zap.UseDevMode(false), zap.WriteTo(os.Stderr), zap.Level(loggerLevel))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm setting devMode here to false. It will be less human-readable this way. The DevMode uses a different config, and it invalidates any log levels passed in (it always will act as if it is in a debug mode)

externaldns "sigs.k8s.io/external-dns/endpoint"
)

func RenderEndpoints(endpoints []*externaldns.Endpoint) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The RenderEndpoints became a more generic PrintTable in the formatter.

type OutputFormatter interface {
Print(message string)
Error(err error, message string)
PrintObject(object any)
Copy link
Contributor Author

@maksymvavilov maksymvavilov Dec 19, 2025

Choose a reason for hiding this comment

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

There were concerns voiced over using any type, and I'm not a fan of it myself. However, I found that it works well enough with primitives.
That said, I don't see it being used - the Print(string) and PrintTable(...) should cover us for most of the cases, and the PrintObject(any), despite having any as type, should only be used for a single struct.
Also, I opted for the yaml format for a single struct. I've tried a number of options and found yaml to be the most human-friendly.

func init() {
rootCMD.SetArgs(os.Args[1:])
rootCMD.PersistentFlags().IntVarP(&verbose, "verbose", "v", 0, "verbosity level: 0 (errors only), 1 (+ info), 2 (+ debug)")
rootCMD.PersistentFlags().IntVarP(&verbose, "verbose", "v", output.DefaultLevel, "the higher verbosity level the more restrictive output; range from -1 (debug, includes everything) to 4 (panic, most restrictive)")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed those levels to match the approach logr has. There is still a bit of a "translation" happening, but our operator and cli will now follow the same idea - the higher level, the more restrictive it is. With the -1 being debug/verbose mode

PrintTable(array PrintableTable)
}

type PrintableTable struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you expect this to look like, when output as YAML or JSON or whatever?

Copy link
Contributor

@philbrookes philbrookes left a comment

Choose a reason for hiding this comment

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

I've tried this locally and the format looks fine now. I still have some concerns over how this will look when extended to more data-focused formats like JSON or YAML, but it's probably easier to just address those at the time, rather than trying to over-engineer for them here.

Happy for this to merge as it is now.

@maksymvavilov maksymvavilov added this pull request to the merge queue Dec 30, 2025
Merged via the queue into Kuadrant:main with commit add6c29 Dec 30, 2025
21 checks passed
@maksymvavilov maksymvavilov deleted the gh-657 branch December 30, 2025 14:40
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.

Add TextOutputFormatter and convert commands to use outputFormatter interface

2 participants