Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --format="text" option to vip logs #2121

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +148,7 @@ function printLogs( logs, format ) {
} );

let output = '';
if ( format && 'table' === format ) {
if ( 'table' === format ) {
const options = {
wordWrap: true,
wrapOnWordBoundary: true,
Expand Down Expand Up @@ -179,6 +179,12 @@ function printLogs( logs, format ) {
}

output = table.toString();
} else if ( 'text' === format ) {
const rows = [];
for ( const { timestamp, message } of logs ) {
rows.push( `${ timestamp } ${ message }` );
output = rows.join( '\n' );
}
} else {
output = formatData( logs, format );
}
Expand Down Expand Up @@ -243,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' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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”, “table”, and “text”.', 'table' )

@yolih what do you think?

.examples( [
{
usage: 'vip @example-app.production logs',
Expand Down