@@ -85,13 +85,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8585 log := resp .GetOutput ()
8686 lines := strings .Split (log , "\n " )
8787
88- if len (lines ) > int (* model .Length ) {
89- // Truncate output and show most recent logs
90- start := len (lines ) - int (* model .Length )
91- return outputResult (params .Printer , model .OutputFormat , serverLabel , strings .Join (lines [start :], "\n " ))
88+ maxLines := int (* model .Length )
89+ if len (lines ) <= maxLines {
90+ return outputResult (params .Printer , serverLabel , lines )
9291 }
9392
94- return outputResult (params .Printer , model .OutputFormat , serverLabel , log )
93+ recentLogs := lines [len (lines )- maxLines :]
94+ return outputResult (params .Printer , serverLabel , recentLogs )
9595 },
9696 }
9797 configureFlags (cmd )
@@ -132,9 +132,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
132132 return apiClient .GetServerLog (ctx , model .ProjectId , model .Region , model .ServerId )
133133}
134134
135- func outputResult (p * print.Printer , outputFormat , serverLabel , log string ) error {
136- return p .OutputResult (outputFormat , log , func () error {
137- p .Outputf ("Log for server %q\n %s" , serverLabel , log )
138- return nil
139- })
135+ func outputResult (p * print.Printer , serverLabel string , logLines []string ) error {
136+ p .Outputf ("Log for server %q\n " , serverLabel )
137+ for _ , line := range logLines {
138+ // Skip empty lines
139+ if strings .TrimSpace (line ) == "" {
140+ continue
141+ }
142+ p .Outputln (line )
143+ }
144+
145+ return nil
140146}
0 commit comments