-
Notifications
You must be signed in to change notification settings - Fork 66
Update project logs #591
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
Update project logs #591
Changes from 8 commits
7ae38e2
6ada60f
d264b87
4dfe1f6
bf6d7d9
c13d1e4
8cc5497
42f0c62
9f0d52c
8aecaa5
2efdd3c
d384024
45eff4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ const endpointLog = async (accountId, options) => { | |
}; | ||
|
||
exports.command = 'logs [endpoint]'; | ||
exports.describe = 'get logs for a function'; | ||
exports.describe = 'get logs for a function within a project'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this only used to get logs for functions within a project? What about functions outside of projects? |
||
|
||
exports.handler = async options => { | ||
await loadAndValidateOptions(options); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,25 @@ const { | |
getProjectAppFunctionLogs, | ||
getLatestProjectAppFunctionLog, | ||
} = require('@hubspot/cli-lib/api/functions'); | ||
const { | ||
getFunctionLogs, | ||
getLatestFunctionLog, | ||
} = require('@hubspot/cli-lib/api/results'); | ||
const { getProjectConfig } = require('../../lib/projects'); | ||
const { loadAndValidateOptions } = require('../../lib/validation'); | ||
const { tailLogs } = require('../../lib/serverlessLogs'); | ||
|
||
const handleLogsError = (e, accountId, projectName, appPath, functionName) => { | ||
if (e.statusCode === 404) { | ||
logger.error( | ||
`No logs were found for the function name '${functionName}' in the app path '${appPath}' within the project '${projectName}' in account ${accountId}.` | ||
appPath | ||
? `No logs were found for the function name '${functionName}' in the app path '${appPath}' within the project '${projectName}' in account ${accountId}.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way to rephrase this? It's four prepositional phrases in a row, I'm getting a little lost. Perhaps we could consult Erin. |
||
: `No logs were found for the function name '${functionName}' within the project '${projectName}' in account ${accountId}.` | ||
); | ||
} | ||
}; | ||
|
||
const appFunctionLog = async (accountId, options) => { | ||
const functionLog = async (accountId, options) => { | ||
const { | ||
latest, | ||
follow, | ||
|
@@ -37,28 +43,40 @@ const appFunctionLog = async (accountId, options) => { | |
|
||
let logsResp; | ||
|
||
const tailCall = async after => { | ||
try { | ||
return appPath | ||
? getProjectAppFunctionLogs( | ||
accountId, | ||
functionName, | ||
projectName, | ||
appPath, | ||
{ | ||
after, | ||
} | ||
) | ||
: getFunctionLogs(accountId, functionName, { after }); | ||
} catch (e) { | ||
handleLogsError(e, accountId, projectName, appPath, functionName); | ||
} | ||
}; | ||
const fetchLatest = async () => { | ||
return appPath | ||
? getLatestProjectAppFunctionLog( | ||
accountId, | ||
functionName, | ||
projectName, | ||
appPath | ||
) | ||
: getLatestFunctionLog(accountId, functionName); | ||
}; | ||
|
||
if (follow) { | ||
const spinnies = new Spinnies(); | ||
|
||
spinnies.add('tailLogs', { | ||
text: `Waiting for log entries for '${functionName}' on account '${accountId}'.\n`, | ||
}); | ||
const tailCall = after => | ||
getProjectAppFunctionLogs(accountId, functionName, projectName, appPath, { | ||
after, | ||
}); | ||
const fetchLatest = () => { | ||
try { | ||
return getLatestProjectAppFunctionLog( | ||
accountId, | ||
functionName, | ||
projectName, | ||
appPath | ||
); | ||
} catch (e) { | ||
handleLogsError(e, accountId, projectName, appPath, functionName); | ||
} | ||
}; | ||
|
||
await tailLogs({ | ||
accountId, | ||
|
@@ -69,24 +87,13 @@ const appFunctionLog = async (accountId, options) => { | |
}); | ||
} else if (latest) { | ||
try { | ||
logsResp = await getLatestProjectAppFunctionLog( | ||
accountId, | ||
functionName, | ||
projectName, | ||
appPath | ||
); | ||
logsResp = await fetchLatest(); | ||
} catch (e) { | ||
handleLogsError(e, accountId, projectName, appPath, functionName); | ||
} | ||
} else { | ||
try { | ||
logsResp = await getProjectAppFunctionLogs( | ||
accountId, | ||
functionName, | ||
projectName, | ||
appPath, | ||
{} | ||
); | ||
logsResp = await tailCall(); | ||
} catch (e) { | ||
handleLogsError(e, accountId, projectName, appPath, functionName); | ||
} | ||
|
@@ -97,7 +104,7 @@ const appFunctionLog = async (accountId, options) => { | |
} | ||
}; | ||
|
||
exports.command = 'logs [functionName]'; | ||
exports.command = 'logs'; | ||
exports.describe = 'get logs for a function within a project'; | ||
|
||
exports.handler = async options => { | ||
|
@@ -110,7 +117,7 @@ exports.handler = async options => { | |
logger.error('You must pass a function name to retrieve logs for.'); | ||
process.exit(1); | ||
} else if (!projectName) { | ||
const projectConfig = await getProjectConfig(getCwd()); | ||
const { projectConfig } = await getProjectConfig(getCwd()); | ||
if (projectConfig.name) { | ||
projectName = projectConfig.name; | ||
} else { | ||
|
@@ -128,22 +135,22 @@ exports.handler = async options => { | |
|
||
trackCommandUsage('project-logs', { latest }, accountId); | ||
|
||
appFunctionLog(accountId, { ...options, projectName }); | ||
functionLog(accountId, { ...options, projectName }); | ||
}; | ||
|
||
exports.builder = yargs => { | ||
yargs.positional('functionName', { | ||
describe: 'Serverless app function name', | ||
type: 'string', | ||
demandOption: true, | ||
}); | ||
yargs | ||
.options({ | ||
appPath: { | ||
describe: 'path to the app', | ||
functionName: { | ||
alias: 'function', | ||
describe: 'Serverless app function name or endpoint route', | ||
type: 'string', | ||
demandOption: true, | ||
}, | ||
appPath: { | ||
describe: 'Path to app folder, relative to project', | ||
type: 'string', | ||
}, | ||
projectName: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
describe: 'name of the project', | ||
type: 'string', | ||
|
@@ -172,7 +179,7 @@ exports.builder = yargs => { | |
|
||
yargs.example([ | ||
[ | ||
'$0 project logs my-function --appName="app" --projectName="my-project"', | ||
'$0 project logs --function=my-function --appPath="app" --projectName="my-project"', | ||
'Get 5 most recent logs for function named "my-function" within the app named "app" within the project named "my-project"', | ||
], | ||
]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this logs command only work for project functions now?