From 17662a8fcf8d4892565abeb786cf48989f507053 Mon Sep 17 00:00:00 2001 From: owen-cole Date: Sat, 23 Nov 2024 14:34:02 -0500 Subject: [PATCH 1/4] Add --format="text" option to vip logs --- src/bin/vip-logs.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index 7b0ff786a..6db11d162 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -14,7 +14,7 @@ const LIMIT_MIN = 1; const LIMIT_MAX = 5000; const LIMIT_DEFAULT = 500; const ALLOWED_TYPES = [ 'app', 'batch' ]; -const ALLOWED_FORMATS = [ 'csv', 'json', 'table' ]; +const ALLOWED_FORMATS = [ 'csv', 'json', 'table', 'text' ]; const DEFAULT_POLLING_DELAY_IN_SECONDS = 30; const MIN_POLLING_DELAY_IN_SECONDS = 5; const MAX_POLLING_DELAY_IN_SECONDS = 300; @@ -179,6 +179,12 @@ function printLogs( logs, format ) { } output = table.toString(); + } else if ( format && 'text' === format ) { + const rows = []; + for ( const { timestamp, message } of logs ) { + rows.push( `${ timestamp } ${ message }` ); + output = rows.join( '\n' ); + } } else { output = formatData( logs, format ); } From 09ead6c57ec19d7511d12f3c6c070aa92a5846d0 Mon Sep 17 00:00:00 2001 From: owen-cole Date: Sat, 23 Nov 2024 14:47:09 -0500 Subject: [PATCH 2/4] update help docs --- src/bin/vip-logs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index 6db11d162..c9264ce1a 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -249,7 +249,7 @@ command( { `The maximum number of entries to return. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).` ) .option( 'follow', 'Output new entries as they are generated.' ) - .option( 'format', 'Render output in a particular format. Accepts “csv”, and “json”.', 'table' ) + .option( 'format', 'Render output in a particular format. Accepts “csv”, “json” and “text”.', 'table' ) .examples( [ { usage: 'vip @example-app.production logs', From 8f2e717984f04885d8addda0c0fc2e3b78e0d8c3 Mon Sep 17 00:00:00 2001 From: owen-cole Date: Sat, 23 Nov 2024 14:58:47 -0500 Subject: [PATCH 3/4] add oxford comma in help output --- src/bin/vip-logs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index c9264ce1a..a59f48e48 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -249,7 +249,7 @@ command( { `The maximum number of entries to return. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).` ) .option( 'follow', 'Output new entries as they are generated.' ) - .option( 'format', 'Render output in a particular format. Accepts “csv”, “json” and “text”.', 'table' ) + .option( 'format', 'Render output in a particular format. Accepts “csv”, “json”, and “text”.', 'table' ) .examples( [ { usage: 'vip @example-app.production logs', From c1cddcec0fb1b00dc37cb932e306b2f8d4d4052a Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Sun, 24 Nov 2024 21:17:34 +0200 Subject: [PATCH 4/4] fix: simplify `if` conditions --- src/bin/vip-logs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index a59f48e48..28e7e09e4 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -148,7 +148,7 @@ function printLogs( logs, format ) { } ); let output = ''; - if ( format && 'table' === format ) { + if ( 'table' === format ) { const options = { wordWrap: true, wrapOnWordBoundary: true, @@ -179,7 +179,7 @@ function printLogs( logs, format ) { } output = table.toString(); - } else if ( format && 'text' === format ) { + } else if ( 'text' === format ) { const rows = []; for ( const { timestamp, message } of logs ) { rows.push( `${ timestamp } ${ message }` );