Open Source Content Management Framework

midcom_debug

  1. Log levels
  2. Enabling web-based logs
  3. Debugging a site
  4. Adding debug calls to a component

midcom_debug is the debug logging tool for the Midgard Component Framework. It is used by all MidCOM components to output useful status and error information.

Log levels

The logging level can be controlled with the MidCOM debug loglevel field in the MidCOM template settigs interface in /midcom-admin/settings/. The possible values are:

  • 0 (MIDCOM_LOG_CRIT): Critical messages
  • 1 (MIDCOM_LOG_ERROR): Error messages
  • 2 (MIDCOM_LOG_WARN): Warnings
  • 3 (MIDCOM_LOG_INFO): Informative messages
  • 4 (MIDCOM_LOG_DEBUG): General debug messages

By default the log file is placed in /var/log/midgard/midcom/www.example.net_80.log where www.example.net_80 is the hostname and port of the MidCOM powered website.

Enabling web-based logs

If allowed by site configuration, the debug log can also be read over the web. To enable the logging URL server-wide, use the following configuration setting in /etc/midgard/midcom.conf:

<?php
$GLOBALS['midcom_config_site']['log_tailurl_enable'] = FALSE;
?>

If you want to enable it only for a specific sitegroup, you can set the following in the /sitegroup-config/midcom-template/config snippet :

$GLOBALS['midcom_config_local']['log_tailurl_enable'] = FALSE;

After this the log file can be read in URL /midcom-log-N where N is the number of lines to show.

Debugging a site

On busy live sites debug logs can overflow and the useful information is lost easily in a rapidly changing log file.

To prevent this it is possible to create custom log with customized log level eg. for a certain IP address. It is possible to get a custom log eg. by placing the following code snippet to snippet /sitegroup-config/midcom-template/config-afterauth.

<?php
// Enable custom log for a certain IP - change it according to your own IP
if ($_SERVER['REMOTE_ADDR'] == '84.34.133.194')
{
    $GLOBALS['midcom_config_local']['log_filename'] = '/tmp/custom_log.log';
    $GLOBALS['midcom_config_local']['log_level'] = 4;
}
?>

Adding debug calls to a component

It is very useful to add debug calls to ease troubleshooting. To get debugging started, you need to call the following in the method you plan to debug:

debug_push_class(__CLASS__, __FUNCTION__);

After this you can use the debug_add function to output information to the debug log. You can use any of the log levels mentioned above.

if (!is_object($campaign))
{
    debug_add("Campaign object {$identifier} is not an object", MIDCOM_LOG_ERROR);
}

Before you exit (via return, exit() or $_MIDCOM->generate_error()) the particular method you must call debug_pop to restore the previous debug prefix. For example:

debug_pop();
return false;
Designed by Nemein, hosted by Kafit