This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit f64b6b93eeb43db1b9a3b911791f3d6be416b9ae
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Mar 25 08:50:39 2021 +0100

    Kamel Dump command: Added log lines parameter
---
 pkg/cmd/dump.go | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index 57dab43..a091753 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -44,11 +44,13 @@ func newCmdDump(rootCmdOptions *RootCmdOptions) 
(*cobra.Command, *dumpCmdOptions
                RunE:    options.dump,
        }
 
+       cmd.Flags().Int("logLines", 100, "Number of log lines to dump")
        return &cmd, &options
 }
 
 type dumpCmdOptions struct {
        *RootCmdOptions
+       LogLines int `mapstructure:"logLines"`
 }
 
 func (o *dumpCmdOptions) dump(_ *cobra.Command, args []string) error {
@@ -62,15 +64,15 @@ func (o *dumpCmdOptions) dump(_ *cobra.Command, args 
[]string) error {
                if err != nil {
                        return err
                }
-               dumpNamespace(o.Context, c, o.Namespace, writer)
+               dumpNamespace(o.Context, c, o.Namespace, writer, o.LogLines)
                defer writer.Close()
        } else {
-               dumpNamespace(o.Context, c, o.Namespace, os.Stdout)
+               dumpNamespace(o.Context, c, o.Namespace, os.Stdout, o.LogLines)
        }
        return nil
 }
 
-func dumpNamespace(ctx context.Context, c client.Client, ns string, out 
*os.File) error {
+func dumpNamespace(ctx context.Context, c client.Client, ns string, out 
*os.File, logLines int) error {
 
        camelClient, err := versioned.NewForConfig(c.GetConfig())
        if err != nil {
@@ -162,7 +164,7 @@ func dumpNamespace(ctx context.Context, c client.Client, ns 
string, out *os.File
                for _, container := range allContainers {
                        pad := "    "
                        fmt.Fprintf(out, "%s%s\n", pad, container.Name)
-                       err := dumpLogs(ctx, c, fmt.Sprintf("%s> ", pad), ns, 
pod.Name, container.Name, out)
+                       err := dumpLogs(ctx, c, fmt.Sprintf("%s> ", pad), ns, 
pod.Name, container.Name, out, logLines)
                        if err != nil {
                                fmt.Fprintf(out, "%sERROR while reading the 
logs: %v\n", pad, err)
                        }
@@ -177,8 +179,8 @@ func dumpConditions(prefix string, conditions 
[]v1.PodCondition, out *os.File) {
        }
 }
 
-func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, 
name string, container string, out *os.File) error {
-       lines := int64(50)
+func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, 
name string, container string, out *os.File, logLines int) error {
+       lines := int64(logLines)
        stream, err := c.CoreV1().Pods(ns).GetLogs(name, &v1.PodLogOptions{
                Container: container,
                TailLines: &lines,

Reply via email to