kubedog icon indicating copy to clipboard operation
kubedog copied to clipboard

How to save kubedog output information to a variable?

Open oneinstack opened this issue 2 years ago • 3 comments

The default multitrack.Multitrack log is the standard output, How to save kubedog output information to a variable?

oneinstack avatar Mar 09 '22 05:03 oneinstack

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.

distorhead avatar Mar 11 '22 10:03 distorhead

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?

oneinstack avatar Mar 12 '22 07:03 oneinstack

Hi! I will need some free time to make refactor, maybe it will be possible during next week.

distorhead avatar Mar 15 '22 09:03 distorhead

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.

ilya-lesikov avatar Jan 22 '24 15:01 ilya-lesikov