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