3

In java it's easy to throw in a Sytem.out.println() and get some helpful info on the console. The closest I have come to that on Force.com is system.debug(); and then plowing through pages of Debug Logs trying to find my line of output. There must be a better way, right?

2

3 Answers 3

1

I totally understand your question. For me standard debug logs and developer console were just huge time burners.

My approach to get something useful is the following: at system.debug use severity WARN. If possible it try to Execute Anonyous and in eclypse filter everything below WARN out. That you have to do for about 5 categories but it will be persistent. In rare cases when you need the endless default verbosity you can easily switch back.

As a convenient wrapper I wrote a (one liner) method called xt.log() which is pretty much like system.debug but allways WARN. You find this among other helper stuff here:

https://github.com/UweHeim/xt

Since we developed our own native and free IDE for Execute Anonyous we rarely use eclipse anymore but CodeFusion you can find here:

https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B5SYEEA3

Then to debug everything else (pages, triggers, batches, future) we have created an other managed package called XLog. It effectively logs into an custom object. We have not released it yet and it comes with some quirks, but it's good enough for 90% of all usecases.

1

system.debug() is how you get the system to print to the debug log. There is no other way. If you don't like ploughing through pages of log (although when you view the log in the browser UI it's always just one page) there are several things you can do.

  1. Filter the log in the dev console as you suggest in your comment. Dev console works better in Chrome / Firefox / Safari than in IE but it isn't entirely glitch free in my experience
  2. Filter the log at source so that only your debug statements get into it see Debug Log Filtering for Apex Classes and Apex Triggers and Setting Debug log Filters

    To set log filters: From a class or trigger detail page, click Log Filters. Click Override Log Filters. The log filters are set to the default log levels. Choose the log level desired for each log category.

  3. The log file entry includes the line number where the entry originated. So if you're calling system.debug() on line 447, the entry includes [447]. Search for that in the browser and you'll find your debug.
  4. Old school - prepend an identifier to every debug output: system.debug('@@@ ' + someVar); and then CTRL-F search the log page for @@@ and you can easily skip through to all your statements.

EDIT: and there's a great full answer here: Need to get logfile smaller

There are also good arguments for building your own debug message store in a custom object, not least of which is that debugging an installed managed package in a client's org is still impossible as far as I know. Although I think they're working on making it possible.

And if you have access to sandbox, the apex debugger is coming. It was announced at DF14 but it's an extra cost.

0

If its for debugging purposes and not needed long term you could add all your debugging into a Document so that you don't have tons of logs to look at and then delete that code afterwards when it's no longer needed.

String myLog = 'Start Log ' + DateTime.now();
...
myLog += '\nFinishing Log ' + DateTime.now();

Document d = new Document();
d.Name = 'LogFile xyz';
d.Body = Blob.valueOf(myLog); 
d.ContentType = 'text/plain';
d.Type = 'txt';
insert d;

You must log in to answer this question.

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