25

I have a massive log file which breaks the 2Meg limit and hence truncates.

There is some information I need that I am logging by doing

System.debug

However, I don't get to see because of the logfile truncation. I change the logging settings so that everything is logged at ERROR except apex code but this still does not bring logging under 2 Meg.

Any ideas?

Thanks.

1
  • 1
    There is a fundamental flaw with Salesforce truncating log files. To determine what caused an error, the most crucial information is in the last few lines of logs right before the error -- at the tail of the log file. Please vote up this idea to keep the last 2MB of logs, not the first 2MB which is are not useful for debugging. Roll the developer console debug logs instead of truncating with error.. As a point of proof, every Application Server in the universe rolls the server logs.
    – Arpi Jakab
    Dec 8, 2016 at 19:19

4 Answers 4

19

There are various ways you can reduce your log file size. The first step is to set the logging level on the important log statements to either Info, Warn or Error:

System.debug(LoggingLevel.Info, 'Important log message');

Then, reduce the logging level that gets captured. Such as setting class specific logging levels as per @Sdry's answer.


Eclipse

If you are capturing the log via anonymous Apex execution you can alter the logging levels that get captured.

With Eclipse you could reduce the Apex Code category to Info and all other categories to None. Eclipse Execute Anonymous Category Log Level

This should greatly reduce the size of your log.

You can do the same thing with running automated test cases.


Force.com Developer Console

With the Force.com Developer Console it is hidden under the Workspace (although I suspect it will be moving again with the Summer 13 release):

Force.com Developer Console Logging Levels


The log filters can also be altered from Setup > Administration Setup > Monitoring > Debug Logs. Then, under monitored users use the Filters link in the action column.

You might find it easier to just use the URL after replacing serverinstance and the user_id values: https://serverinstance.salesforce.com/apexdebug/DebugUserLogSpecification.apexp?user_id=005fullUserId00

Monitoring Debug Log Event Filters


You can also alter these levels with the FuseIT SFDC Explorer (Full Disclosure: Shameless plug for a free tool I tinker with):

Anonymous Apex:
FuseIT SFDC Explorer Anonymous Apex Logging Levels

Apex Test Execution:
FuseIT SFDC Explorer Apex Test Logging Levels

2
  • I know that I'm not supposed to say "thanks" in comments, but your answer is wonderful. Thank you! Aug 8, 2013 at 16:52
  • The tip about adding log level to the system.debug() statement (instead of relying on logging Apex at the Debug level) is particularly apt, and one I often forget. Dec 4, 2013 at 19:06
10

I had this issue (Eclipse IDE) and converted all my System.debug() statements to System.debug(DebugControl.getLoglevel(),'my message');

where static method getLoglevel() in APEX class DebugControl returned LoggingLevel.INFO (by default) or a testmethod-set other log level.

This way, I could see only those parts of the log that my code thought was important and avoided the endless noise from SFDC LoggingLevel.DEBUG log entries that I didn't care about (like method entry/exit). It was also a way to turn logging off for setup of test data and turning it back on for the real work of the testmethods

8

I'll probably get down-voted for this one, but I say avoid the debug logs entirely. All you care about is the output of that one debug statement? Use System.assertEquals instead with an assertion you know will fail. This way the error just bubbles right up and you dont need to go digging through debug logs or playing with log levels.

System.assertEquals('this-will-fail', '' + whatIAmTryingToDebugOut);
1
  • Alternative: System.assert(false, whatIamTryingToDebugOut)
    – sfdcfox
    Apr 18, 2017 at 4:11
7

Besides the log filters on the debug log page you can also override the specific log filters for each apex class. If you disable logging for all the apex classes you are not interested in you can minimize your log to what you're really looking for.

You can find this for each Apex class at the Log filter tab on the class detail page.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .