kubedog
kubedog copied to clipboard
How to save kubedog output information to a variable?
The default multitrack.Multitrack log is the standard output, How to save kubedog output information to a variable?
Hi! If I understand your question correctly, you need to save kubedog's output when using kubedog as a library in your code. It should be possible by initializing logboek — logging library internally used by kubedog — with special buffers instead of stdout/stderr.
But there is currently a problem with kubedog internals, because it uses context.Background()
when calling logboek internally, instead of using context.Context param (example https://github.com/werf/kubedog/blob/main/pkg/trackers/rollout/multitrack/multitrack_display.go#L74).
Logboek custom logger can be created like that:
var output bytes.Buffer
logger := logboek.NewLogger(&output, &output)
ctx := logboek.NewContext(context.Background(), logger)
Then this logger is activated used created context:
logboek.Context(ctx).LogF(...)
So to enable this case of usage we need to refactor kubedog internals to pass explicit positional context.Context param.
Yes, I need to save kubedog's output when using kubedog as a library in my code. Can you to refactor kubedog internals to pass explicit positional context.Context param?
Hi! I will need some free time to make refactor, maybe it will be possible during next week.
Use new Dynamic Tracker, which will constantly populate/update its Storage with resource states, events, logs. You can get whatever you want from Storage at any point of time and save it somewhere or do something else. Stdout printer in https://github.com/werf/nelm can be used as a reference.