Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Latest commit

 

History

History
293 lines (202 loc) · 8.59 KB

ExtensionDevelopmentDebugging.rst

File metadata and controls

293 lines (202 loc) · 8.59 KB

Extension Development, Debugging

<< Back to Extension Development page

[edit] [deprecated wiki link]

notice - Draft

Change the {{draft}} marker to {{review}} when you need a reviewer for text and TypoScript. info [deprecated wiki link]

warning - No longer supported TYPO3 version

This page contains information for older, no longer maintained TYPO3 versions. For information about TYPO3 versions, see get.typo3.org. For information about updating, see the Installation & Upgrade Guide

Tipps on debugging

Debug TYPO3

See also the Extension Developers Guide

  • In typo3conf/LocalConfiguration.php, set [FE][debug] = 1 and [SYS][devIPmask] to e.g. "192.,169.*,127.0.0.1". Then use the extended `debug <https://wiki.typo3.org/Category:Debug>`__*[deprecated wiki link]() function of the Extension cc_debug. On your TYPO3 site you will see a bomb ([[1]]) in the upper right corner if there is debug output by the currently running PHP script.
PHP Script [deprecated wiki link]
// show the variable together with the line number and file name
debug($variable, 'Variable name/description', __LINE__, __FILE__);

Alternatively you can use the extension beko_debugster or fh_debug. These will also work if there are HTML or JavaScript errors on a page.

PHP Script [deprecated wiki link]
// display the variable
debugster($variable, 'Variable name/description');
PHP Script [deprecated wiki link]
// show the stack trace of the current function
$tmp = t3lib_div::debug_trail();
debug($tmp, 'stack trace in className::methodName', __LINE__, __FILE__);
// Replace 'className' with the name of the class and 'methodName' with the name of the method from where you call <tt>debug()</tt>.

// If you want to add devLog functionality to your applications, simply write lines like this:
if (TYPO3_DLOG) {
  \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('some message', 'extension_key');
  // (…used to be »t3lib_div::devLog(), you may still see this in older examples)
  // …if you want debug data use this
  \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('some message', 'extension_key', 0, $dataArray);
}
The devlog-function itself provides only an interface for logging but no implementation to store the logs. So you need an extension save the log message to a desired place.
The devlog extension provides development logging/debugging functionality and stores the logs into a MySQL table by default. The
rlmp_filedevlog logs messages into a text file (by default to debug.log of your web server home directory, e.g. at /var/www/html/ - do not forget to allow write access for the httpd user).

You have to activate the devlog functionality on your system as well, by adding the following line to typo3conf/LocalConfiguration.php:

PHP Script [deprecated wiki link]
$TYPO3_CONF_VARS['SYS']['enable_DLOG'] = true;

error_log()

You can write to the (system) error log using:

PHP Script [deprecated wiki link]
error_log('text', 0);
error_log('postition A: $content='.$content, 3, '/usr/local/htdocs/typo3/error_log');

and view the entries of the log file. (Linux: /var/log/messages, /var/log/apache2/error_log or /var/log/httpd/error_log).

You can modify the error_log = syslog settings in /etc/php.ini.

If you supply a third parameter to error_log(), it will write that log entry to this file only.

To show the contents of arrays, you use foreach loops:

PHP Script [deprecated wiki link]
foreach ($menuItems as $key => $menuItem) {
   if (is_array($menuItem)) {
       error_log ('-- tx_commerce_cm1 menuItem['.$key.'] --', 0);
       foreach ($menuItem as $k1=>$v1) {
           error_log ('['.$k1.']='.$v1,0);
       }
   } else {
       error_log ('-- tx_commerce_cm1 menuItem['.$key.'] = '.$menuItem, 0);
   }
}

Or use these lines with var_dump():

PHP Script [deprecated wiki link]
ob_start();
print_r($myComplexArray);
$debugOut = ob_get_contents();
ob_end_clean();
error_log ('$myComplexArray = '.$debugOut);

How to debug SQL

PHP Script [deprecated wiki link]
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = true;
$GLOBALS['TYPO3_DB']->exec_UPDATEquery( 'xxx', 'yyy', 'zzz');
t3lib_div::devLog('[write message in english here]'.$GLOBALS['TYPO3_DB']->debug_lastBuiltQuery , 'extension key');

Use debug_mysql_db to debug SQL queries, measure query execution time and hide unnecessary PHP warning messages.

How to debug TypoScript

See TypoScript Reference, section stdWrap.

At the end of the table you will see three stdWrap options which enable various debug modes:

  • debug boolean

Passes output through htmlspecialchars(). Useful for debugging which value stdWrap actually ends up with while you're constructing a website with TypoScript.

  • debugFunc boolean

Prints the content using the debug() function. Set to value "2" (well, it's not *quite* a boolean;)) the content will be printed in a table - looks nicer. Example:

TS TypoScript [deprecated wiki link]
marks.MENU_TITLE = TEXT
marks.MENU_TITLE.field = title
marks.MENU_TITLE.stdWrap.debugFunc = 2
marks.MENU_TITLE.stdWrap.wrap = title at position 1 |
  • debugData boolean

Prints the current data-array, $cObj->data, directly to browser. This is where ".field" gets its data from.

A trick that's extremely useful while developing is simply build an extension template (+ext) for the specific page you want to debug; so that you can manipulate your TypoScript code as you want without affecting other pages. Once you've finished debugging, delete the extension template.

  • debugItemConf boolean

Outputs the configuration arrays for each menu item, using the debug()-function. Useful to debug optionSplit things and such. Applies to GMENU, TMENU, IMGMENU.

An example:

TS TypoScript [deprecated wiki link]
temp.L2menuItems = HMENU
temp.L2menuItems.entryLevel = 1
temp.L2menuItems.1 = TMENU
temp.L2menuItems.1.debugItemConf = 1