Skip to content

Commit

Permalink
Merge pull request #4322 from Shopify/dunk.jsonl-tty
Browse files Browse the repository at this point in the history
Don't pretty print --json output for logs
  • Loading branch information
DuncanUszkay1 authored Aug 14, 2024
2 parents a953300 + bae0acf commit 9b0a43c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('renderJsonLogs', () => {
},
})

expect(outputInfo).toHaveBeenNthCalledWith(1, JSON.stringify({payload: {message: 'Log 1'}}, null, 2))
expect(outputInfo).toHaveBeenNthCalledWith(2, JSON.stringify({payload: {message: 'Log 2'}}, null, 2))
expect(outputInfo).toHaveBeenNthCalledWith(1, JSON.stringify({payload: {message: 'Log 1'}}))
expect(outputInfo).toHaveBeenNthCalledWith(2, JSON.stringify({payload: {message: 'Log 2'}}))
expect(pollAppLogs).toHaveBeenCalled()
expect(vi.getTimerCount()).toEqual(1)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function renderJsonLogs({

if (appLogs) {
appLogs.forEach((log) => {
outputInfo(toFormattedAppLogJson(log, parseAppLogPayload(log.payload, log.log_type)))
outputInfo(toFormattedAppLogJson(log, parseAppLogPayload(log.payload, log.log_type), false))
})
}

Expand Down
13 changes: 10 additions & 3 deletions packages/app/src/cli/services/app-logs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ export const handleFetchAppLogsError = async (
return {retryIntervalMs, nextJwtToken}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const toFormattedAppLogJson = (appLog: AppLogData, appLogPayload: AppLogPayload | any): string => {
export const toFormattedAppLogJson = (
appLog: AppLogData,
appLogPayload: AppLogPayload | unknown,
prettyPrint = true,
): string => {
const {cursor: _, ...appLogWithoutCursor} = appLog
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const toSaveData: any = camelcaseKeys(
Expand All @@ -180,7 +183,11 @@ export const toFormattedAppLogJson = (appLog: AppLogData, appLogPayload: AppLogP
toSaveData.payload.logs = appLogPayload.logs.split('\n').filter(Boolean)
}

return JSON.stringify(toSaveData, null, 2)
if (prettyPrint) {
return JSON.stringify(toSaveData, null, 2)
} else {
return JSON.stringify(toSaveData)
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 9b0a43c

Please sign in to comment.