NebulaLogger icon indicating copy to clipboard operation
NebulaLogger copied to clipboard

Is it possible to configure the Logger to only do System.debug()?

Open mikesobczak opened this issue 1 year ago • 7 comments

Package Edition of Nebula Logger

Unlocked Package

Package Version of Nebula Logger

4.6.16

New Bug Summary

I'm having issues with the Logger generating too many SOQL queries, or too many platform events, as part of test coverage. Is it possible to configure Logger to only do System.debug(), and not create records and not generate platform events?

mikesobczak avatar Sep 06 '22 21:09 mikesobczak

Hi @mikesobczak - could you provide some more details on how you're using Nebula Logger? It looks like you're using a fairly old version of the package, but even so, it should only use 3-4 queries max. And could you share the error you receive about too many platform events?

jongpie avatar Sep 21 '22 21:09 jongpie

I setup my test coverage to configure the Logger to use the following:

config.IsEnabled__c = true;
config.LoggingLevel__c = 'INFO';
config.DefaultSaveMethod__c = 'SYNCHRONOUS_DML';

Here's a stack trace from my test method:

15:41:14.344 (13864258581)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
Class.LogEntryEventHandler.getRecentLogWithApiReleaseDetails: line 391, column 1
Class.LogEntryEventHandler.upsertLogs: line 56, column 1
Class.LogEntryEventHandler.executeAfterInsert: line 47, column 1
Class.Logger.saveLog: line 2572, column 1
Class.Logger.saveLog: line 2502, column 1
Class.RSBackend.defaultFinally: line 1250, column 1

mikesobczak avatar Sep 22 '22 19:09 mikesobczak

We are using unlocked package version 4.6.16

mikesobczak avatar Sep 22 '22 19:09 mikesobczak

Interesting, I don't normally recommend using 'SYNCHRONOUS_DML' in most cases, as that will cause more code & queries to run synchronously. Is there a reason you're using it?

And if you want to disable publishing of the platform events, you can try using config.DefaultSaveMethod__c = null instead, I think that would work on v4.6.16 - new versions of Nebula Logger have a field called IsSavingEnabled__c that can be set to false, but that's not available in the version that you're using (you may want to consider upgrading at some point).

jongpie avatar Sep 22 '22 20:09 jongpie

I had been using EVENT_BUS, but was exceeding the test coverage limit of 500 platform events.

mikesobczak avatar Sep 22 '22 20:09 mikesobczak

Unfortunately, Default Save Method is a required field in the version I'm running. I can't set it to null.

mikesobczak avatar Sep 29 '22 14:09 mikesobczak

@mikesobczak just to clarify on your scenario, when using EVENT_BUS, are you expecting there to be 500+ log entries created within your test method(s)? I'm not sure what your code is doing, but since you're using LoggingLevel__c = 'INFO', having 500+ entries generated seems like a lot, I'd be interested in hearing more about your use case.

As far as next steps, I think your best option is to upgrade Nebula Logger so you can leverage the new field LoggerSettings__c.IsSavingEnabled__c, it would provide the exact functionality you're looking for.

jongpie avatar Oct 04 '22 01:10 jongpie