Skip to content

feat: Add option to change the log level of logs emitted by Cloud Functions #8530

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions spec/CloudCodeLogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ describe('Cloud Code Logger', () => {
});
});

it('should log cloud function ran using the custom log level', async done => {
await reconfigureServer({
silent: true,
logLevels: {
cloudFunctionRan: 'warn',
},
});

Parse.Cloud.define('aFunction', () => {
return 'it worked!';
});

spy = spyOn(Config.get('test').loggerController.adapter, 'log').and.callThrough();

Parse.Cloud.run('aFunction', { foo: 'bar' }).then(() => {
const log = spy.calls.allArgs().find(log => log[1].startsWith('Ran cloud function '))?.[0];

expect(log).toEqual('warn');

done();
});
});

it('should log cloud function triggers using the custom log level', async () => {
Parse.Cloud.beforeSave('TestClass', () => {});
Parse.Cloud.afterSave('TestClass', () => {});
Expand Down
5 changes: 5 additions & 0 deletions src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ module.exports.AuthAdapter = {
},
};
module.exports.LogLevels = {
cloudFunctionRan: {
env: 'PARSE_SERVER_LOG_LEVELS_CLOUD_FUNCTION_RAN',
help: 'Log level used by the Cloud Code Functions. Default is `info`.',
default: 'info',
},
triggerAfter: {
env: 'PARSE_SERVER_LOG_LEVELS_TRIGGER_AFTER',
help:
Expand Down
1 change: 1 addition & 0 deletions src/Options/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,8 @@ export interface LogLevels {
:DEFAULT: error
*/
triggerBeforeError: ?string;
/* Log level used by the Cloud Code Functions. Default is `info`.
:DEFAULT: info
*/
cloudFunctionRan: ?string;
}
2 changes: 1 addition & 1 deletion src/Routers/FunctionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class FunctionsRouter extends PromiseRouter {
result => {
try {
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
logger.info(
logger[req.config.logLevels.cloudFunctionRan](
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Result: ${cleanResult}`,
{
functionName,
Expand Down