Skip to content

Commit 71f8812

Browse files
committed
Add cloudFunctionRan function to logLevels configuration #8529
1 parent 6207a02 commit 71f8812

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

spec/CloudCodeLogger.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ describe('Cloud Code Logger', () => {
182182
});
183183
});
184184

185+
it('should log cloud function ran using the custom log level', async done => {
186+
await reconfigureServer({
187+
silent: true,
188+
logLevels: {
189+
cloudFunctionRan: 'warn',
190+
},
191+
});
192+
193+
Parse.Cloud.define('aFunction', () => {
194+
return 'it worked!';
195+
});
196+
197+
spy = spyOn(Config.get('test').loggerController.adapter, 'log').and.callThrough();
198+
199+
Parse.Cloud.run('aFunction', { foo: 'bar' }).then(() => {
200+
const log = spy.calls.allArgs().find(log => log[1].startsWith('Ran cloud function '))?.[0];
201+
202+
expect(log).toEqual('warn');
203+
204+
done();
205+
});
206+
});
207+
185208
it('should log cloud function triggers using the custom log level', async () => {
186209
Parse.Cloud.beforeSave('TestClass', () => {});
187210
Parse.Cloud.afterSave('TestClass', () => {});

src/Options/Definitions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,11 @@ module.exports.AuthAdapter = {
993993
},
994994
};
995995
module.exports.LogLevels = {
996+
cloudFunctionRan: {
997+
env: 'PARSE_SERVER_LOG_LEVELS_CLOUD_FUNCTION_RAN',
998+
help: 'Log level used by the Cloud Code Functions. Default is `info`.',
999+
default: 'info',
1000+
},
9961001
triggerAfter: {
9971002
env: 'PARSE_SERVER_LOG_LEVELS_TRIGGER_AFTER',
9981003
help:

src/Options/docs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,8 @@ export interface LogLevels {
577577
:DEFAULT: error
578578
*/
579579
triggerBeforeError: ?string;
580+
/* Log level used by the Cloud Code Functions. Default is `info`.
581+
:DEFAULT: info
582+
*/
583+
cloudFunctionRan: ?string;
580584
}

src/Routers/FunctionsRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class FunctionsRouter extends PromiseRouter {
140140
result => {
141141
try {
142142
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
143-
logger.info(
143+
logger[req.config.logLevels.cloudFunctionRan](
144144
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Result: ${cleanResult}`,
145145
{
146146
functionName,

0 commit comments

Comments
 (0)