Serviceability Improvements For Gadgets
Problem
The more complex the gadget the more you are going to depend on servicability in order to debug problems with your app in production. Â We need to be able to place a gadget in "debug" mode in order to enable an app to start outputting the valuable debug information. Â Today we support gadgets.log, gadgets.warn, gadgets.info, and gadgets.error. Â We can also set the log level using gadgets.setLogLevel to set a logging level within the gadget. Â However this does not allow you to set a logging level for a specific "module" in your gadget. Â If your code is complex enough you may be writing numerous modules to encompas your code. Â When enabling logging in this code you probably want to do it on a per module basis and not enable logging for your entire app. Â Today we don't have support for this in the spec.
Solution One
One possible way to do this is to use the SUPPORT view, or some other view, of your gadget in order to allow the user to enable logging in your gadget. Â (You pass some view parameters from the SUPPORT view to other views of you gadget indicating debugging is enabled.) Â However you will have to role your own solution for logging different modules in your gadget.
Solution Two
This should have the same functionality as the solution one but instead of the gadget managing the UI for enabling debugging the container does it. Â Very similar to how the container can display gadget preferences.
<Module> <ModulePrefs title="Developer Forum" title_url="http://groups.google.com/group/Google-Gadgets-API" height="200" author="Jane Smith" author_email="xxx@google.com"> <Serviceability> <DebugModule id="org.opensocial.module1" description="this is a very important module"/> <DebugModule id="org.opensocial.module2" description="this is a semi-important module"/> </Serviceability> </ModulePrefs> <Content ...> ... content ... </Content> </Module>
APIs
String gadgets.isDebug()
Description
Indicates whether the gadget is in debug mode or not.
Return
Returns true if the gadget is in debug mode false if it is not.
gadgets.setDebug(boolean isDebug)
Description
Sets whether the gadget is in debug mode.
Parameters
isDebug - boolean indicating whether the gadget is in debug mode
gadgets.DebugModule gadgets.getDebugModule(String id)
Description
Gets a debug module given its id.
Parameters
The id of the debug module to get.
gadgets.DebugModule[] gadgets.getDebugModules()
Description
Gets an array of debug modules registered for this gadget.
Returns
An array of debug modules registered for this gadget.
String gadgets.DebugModule.getId()
Description
Gets the id of the debug module. Â This should be unique within the gadget.
Returns
The id of the debug module.
gadgets.DebugModule.setId(String id)
Description
Sets the id of the debug module.
String gadgets.DebugModule.getDescription()
Description
Gets the description of the debug module. Â This describes what the module does within the gadget.
Returns
The description of the debug module.
gadgets.DebugModule.setDescription(String description)
Description
Sets the description for the debug module.
boolean gadgets.DebugModule.isEnabled()
Description
Indicates whether debugging is enabled for the module.
Returns
True if debugging is enabled for the module, false otherwise.