Skip to content

DevGuide DebugMelody

Violet edited this page Nov 2, 2010 · 2 revisions

MDG: Debugging Melody and Melody Plugins

Developing an application of any size requires tools to assist developers to help hunt down the bane of their existence: bugs. The smallest of these pesky little things can wreak havoc upon a system, and without the right skills and tools it can be near impossible to root them out. The following section discusses the many such tools in Melody to help developers in this unfortunate and inevitable task.

The Activity Log

Check the activity log. The Melody Activity Log is perhaps one of the most under-rated and under-utilized features of Melody. Virtually every action of interest inside the application is recorded there, providing a pretty reliable audit trail for the application, your content and your users. It can also provide a useful source of debugging information.

The Activity Log can also provide a useful source of debugging information. The following section will provide you with the information you need to leverage this resource to help debug and develop your plugin.

Tip: Using the activity log to detect plugin load failure

Commonly a developer will introduce a syntax error into a plugin they are developing without knowing it. When they go to test their plugin they realize that Melody is behaving as if their plugin wasn't even installed.

When Melody fails to load a plugin, due to an invalidly formatted config.yaml, or to a Perl error in their Plugin.pm file, Melody will ignore the plugin and continue operating normally. It will also record in the Activity Log the failure and the reason for the failure.

This often provides developers with the exact information they need to fix their plugin and continue on in their development.

Logging to the Activity Log

To create an entry in the Activity Log, use the following code sample:

MT->log({  
  message => "Something happened.",
  class => 'system',
  level => MT::Log::DEBUG(), 
});

MT->log Properties

  • message - The message to enter into the log.
  • class - The type of log entry. In most cases, the default "system" value is sufficient. The others are used to additional log information about content created in the system.
    • system (default)
    • comment
    • page
    • ping
  • level - The log level of nature of the log entry. This is used to differentiate between informational messages and errors.
    • MT::Log::INFO()
    • MT::Log::WARNING()
    • MT::Log::DEBUG()
    • MT::Log::SECURITY()
    • MT::Log::ERROR()

DebugMode

Melody has a built in developer mode that modifies the behavior of the application slightly to make it easier for developers to build, test and debug plugins they are building on top of Melody. This mode is activated when the DebugMode configuration directive has been added to the installation's config.cgi file.

When in "DebugMode" Melody can:

  • Monitor the API plugins use and report any issues, discrepancies or ways in which the plugin may not be fully compatible with MT4.
  • Use the non-compressed javascript files allowing javascript debuggers to more easily report specific line numbers and files in which problems may be occurring
  • Use non-compressed CSS files allowing debuggers to report more precisely about what stylesheet problems may exist
  • The devel.js javascript file will be included on each page of the application. This javascript file outputs log information to the browser console so that plugins like Firefox's FireBug can capture and report to developers debugging information about javascript code running on the page. IE and Safari users will have this information displayed to them through javascript pop-ups.
  • And warnings emanating from plugin code or perl code will be displayed at the bottom of the page. This provides a nice linting framework for reporting possible issues with the plugin.

Prerequisites

  • Users should install the Time::HiRes perl module prior to enabling DebugMode

Turning On Debug Mode

To turn on Debug Mode within Melody, edit your config.cgi file and add the following line:

DebugMode 1

The DebugMode is a bit-wise setting and offers the following options:

  • 1 - Display debug messages
  • 2 - Display a stack trace for messages captured
  • 4 - Lists queries issued by Data::ObjectDriver
  • 8 - Reports on Melody templates that take more than 1/4 second to build*
  • 128 - Outputs app-level request/response information to STDERR.

These can be combined, so if you want to display queries and debug messages, use a DebugMode of 5 for instance.

Debugging Template Tags

By setting the DebugMode to a value of 8, you can get some performance information about your template tags. These messages get sent to your web servers error log or STDERR. He is some sample output:

Builder: Tag [Assets] - 12.007559 seconds
Builder: Tag [Tags] - 0.877185 seconds
Builder: Tag [If] - 0.877515 seconds
Builder: Tag [Include] - 1.063821 seconds
Builder: Tag [Else] - 1.064076 seconds
Builder: Tag [If] - 1.064391 seconds

Plugin Compatibility

When Debug Mode is enabled, Melody will report for each enabled plugin the use of any deprecated API. This is a very simple way for example to ensure that your plugins do not make calls to methods or subroutines that might in the future be removed. The screenshot below shows what type of information is displayed when DebugMode is set to "1".

A message that appears when a plugin is using a deprecated method.

Continue Reading

 


Questions, comments, can't find something? Let us know at our community outpost on Get Satisfaction.

Credits

  • Author: Byrne Reese
  • Edited by: Violet Bliss Dietz
Clone this wiki locally