Difference between revisions of "Java Debugging Tips"
imported>Aeric |
imported>Aeric |
||
Line 22: | Line 22: | ||
To view changes interactively, the code can be launched using a [[Macro]] or a [[Rule]]. For example: | To view changes interactively, the code can be launched using a [[Macro]] or a [[Rule]]. For example: | ||
:* | :* Open the object and create a macro that invokes a method. Then, when viewing a record, select the macro from the list of ''Actions''. | ||
:* Use an [[Event Rule]] that runs when a record is added. (As a precaution, you can set up a condition so that the rule is triggered only when some flag is set.) | :* Use an [[Event Rule]] that runs when a record is added. (As a precaution, you can set up a condition so that the rule is triggered only when some flag is set.) | ||
Revision as of 20:20, 23 January 2014
Debug Messages
To debug a Java class:
- Add messages to the debug log using
- Logger.info("message text", "message type");
- (The message type can be used for searching, when needed.)
- Open the debug log in a separate page:
- Display a note at the top of the user's page:
- Functions.showMessage("message text");
- Abort processing and display an error message:
- Functions.throwException("message text");
- Learn more:
- See the Class Template for code that uses many of those techniques.
Invoking Methods
The Unit Test Framework is great for automated testing of Java methods, but note that database changes don't persist. That's a highly desirable feature in a test harness, but it means you can't run a test and then look for changes interactively, in the GUI.
To view changes interactively, the code can be launched using a Macro or a Rule. For example:
- Open the object and create a macro that invokes a method. Then, when viewing a record, select the macro from the list of Actions.
- Use an Event Rule that runs when a record is added. (As a precaution, you can set up a condition so that the rule is triggered only when some flag is set.)
Setting up a "Debug Mode"
To ensure that your rule fires only when you are actively debugging, you can add a "Debug" flag to the User object, set the default to false, and then set it to true for yourself. The condition add-record Rule condition can then test for Owner.Debug equals true.
Or, more simply, change the value of your title field to "Developer", and then set the Rule condition to Owner.Title equals Developer. Anyone who creates a record is automatically its owner, so anyone who has the title "Developer" will execute the method when they add a record.