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
JoeZaloom.ax395JoeZaloom.ax395 

Can't see System.debug() output in installed managed package

Hi,

 

We have an application that we distribute as a managed package. In the dev org where I created the package, I can see all output from my System.debug() calls in the system log window. 

 

When we install the package in a client's SF org, we can't see any of the System.debug() output. We do see the SF profiling information, but no debug() calls.

 

I can't find any reference to this in the documentation. 

 

- Is this known behavior?

 

- Is there some way to enable System.debug() output in a managed package?

 

thanks for any feedback,

joezaloom

Best Answer chosen by Admin (Salesforce Developers) 
billjgbilljg
This is known behavior.  The only logging that is performed for a managed installed package is logging that relates to DB statements or governor limits.  There is currently no way to enable other types of logging in a subscriber org.

All Answers

billjgbilljg
This is known behavior.  The only logging that is performed for a managed installed package is logging that relates to DB statements or governor limits.  There is currently no way to enable other types of logging in a subscriber org.
This was selected as the best answer
JoeZaloom.ax395JoeZaloom.ax395
Thanks for the quick reply.
Daniel LiedkeDaniel Liedke
Because all SQOL queries are logged it is possible to add some SQOL with messages for troubleshooting only.

Managed packages are very hard to troubleshoot without logs.
public static void logMessageWithSOQL(String message) {
          
        // Sanitize the message to remove invalid characters
        String sanitizedMessage = sanitizeForSOQL(message);

        // Construct the SOQL query
        String queryString = 'SELECT Name FROM PermissionSet WHERE Name LIKE \'' + sanitizedMessage + '\' LIMIT 1';

        // Execute the query
        List<PermissionSet> results = Database.query(queryString);
    }
    
    private static String sanitizeForSOQL(String input) {
        
        if (String.isEmpty(input)) {
            return '';
        }
    
        // Replace new lines with space
    	String sanitized = input.replace('\n', ' ').replace('\r', ' ');
        
        // Replace single quotes (common SOQL injection risk)
        sanitized = input.replace('\'', '\\\'');
    
        // Remove non-alphanumeric characters except underscores, percent signs,
        // spaces, parentheses, and dots
        // Adjust the regex to include these additional characters
        sanitized = sanitized.replaceAll('[^\\w%()\\.\\s]', '');
    
        return sanitized;
    }

Example of logs for troubleshooting (filter by SELECT Name FROM PermissionSet):

10:52:24.0 |SOQL_EXECUTE_BEGIN|SELECT Name FROM PermissionSet WHERE Name LIKE 'Before send() 
10:52:24.0 |SOQL_EXECUTE_BEGIN|SELECT Name FROM PermissionSet WHERE Name LIKE 'After send() 
10:52:24.0 |SOQL_EXECUTE_BEGIN|SELECT Name FROM PermissionSet WHERE Name LIKE 'Before getBody (MRA_Http_Util)' LIMIT 1
10:52:24.0 |SOQL_EXECUTE_BEGIN|SELECT Name FROM PermissionSet WHERE Name LIKE 'After getBody (MRA_Http_Util)' LIMIT 1

Thank you!
Daniel