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

This commit is contained in:
alljinx
2023-05-09 15:03:00 +02:00
committed by GitHub
parent 1302853187
commit 2caea310be
5 changed files with 58 additions and 2 deletions

View File

@@ -182,6 +182,42 @@ describe('Cloud Code Logger', () => {
});
});
it('should log cloud function execution using the custom log level', async done => {
Parse.Cloud.define('aFunction', () => {
return 'it worked!';
});
Parse.Cloud.define('bFunction', () => {
throw new Error('Failed');
});
await Parse.Cloud.run('aFunction', { foo: 'bar' }).then(() => {
const log = spy.calls.allArgs().find(log => log[1].startsWith('Ran cloud function '))?.[0];
expect(log).toEqual('info');
});
await reconfigureServer({
silent: true,
logLevels: {
cloudFunctionSuccess: 'warn',
cloudFunctionError: 'info',
},
});
spy = spyOn(Config.get('test').loggerController.adapter, 'log').and.callThrough();
try {
await Parse.Cloud.run('bFunction', { foo: 'bar' });
throw new Error('bFunction should have failed');
} catch {
const log = spy.calls
.allArgs()
.find(log => log[1].startsWith('Failed running cloud function bFunction for '))?.[0];
expect(log).toEqual('info');
done();
}
});
it('should log cloud function triggers using the custom log level', async () => {
Parse.Cloud.beforeSave('TestClass', () => {});
Parse.Cloud.afterSave('TestClass', () => {});