function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JP2016JP2016 

Persistant Log Pattern

Hi,

I'm looking for a good pattern to be able to log:
  • Inbound REST requests - capture details of request and response
  • Outbound REST requests - capture details of request and response.  Needs to be able to log request priort to call out and then log response post call out.
  • Exception logging
  • Custom settings to control levels of logging - can be basic at the moment as in on/off
  • Log clean up/purge jobs 
I have no doubt you guys have already done this a million times in salesforce! 
Thanks! 
James LoghryJames Loghry
I haven't seen a solution that checks all of these boxes per se, but I've seen custom objects used for this purpose.  The idea is that you create a custom object (e.g. Error__c), with a few fields like Error Message, Stack Trace, Method Name, etc.  Then you can try / catch exceptions and insert them into the custom object.

For ther error level piece, you could create a custom setting or custom metadata that your code reads.  In addition to the  error level, you could also have an on/off checkbox value in the custom setting that dictates whether or not to log the errors.

The inbound REST request piece isn't very feasible without the paid add on of Event Monitoring (See the following trailhead for more info on Event Monitoring: https://trailhead.salesforce.com/modules/event_monitoring/units/event_monitoring_intro)