MyXoops Forum

Forum - myXOOPS German Support

0 + 9 = ?  
Geben Sie das Ergebnis der Berechnung ein
Sie haben max. 10 Versuche.
 
* = Erforderlich

XOOPS-Debug ohne XOOPS-Debug!

Betreff: XOOPS-Debug ohne XOOPS-Debug!
von frankblack am 29.07.2009 15:53:33

Nachdem ich diesen Beitrag bereits auf xoops.org gepostet habe, kommen jetzt auch die deutschen User in den Genuss meines "Geistesblitzes".

Ich fand die XOOPS-internen Debugging-Funktionen immer etwas nervig, besonders wenn man (x)ajax zusätzlich genutzt hat. XOOPS-Debug und xajax schließt sich leider aus.

So bin ich auf die Idee gekommen FireBug + FirePHP (Addons für Firefox) einzusetzen. Ich habe die Datei class/logger/render.php umgeschrieben um die Ausgabe des Debug an FirePHP weierzuleiten. Diese Lösung ist meiner Meinung nach sehr flexibel.

Mit dieser Lösung kann man jede Art von debug-Hinweis setzen ohne echos zu bemühen die das Layout zerstören.

Beispiel:
$fb->log($thevariwanttodisplay);


Natürlich kann man render.php noch weiter adaptieren, um beispielsweise die Server-Variablen auszugeben etc.pp.

FirePHP gibt es HIER

Hier der Code für class/logger/render.php (hoffe der textsanitöter zerbrezelt das jetzt nicht):
<?php
/**
 * Xoops Logger renderer
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         kernel
 * @subpackage      logger
 * @since           2.3.0
 * @author          Skalpa Keo <skalpa@xoops.org>
 * @author          Taiwen Jiang <phppp@users.sourceforge.net>
 * @version         $Id: render.php 2633 2009-01-10 03:09:41Z phppp $
 *
 * @todo            Not well written, just keep as it is. Refactored in 3.0
 */

defined'XOOPS_ROOT_PATH' ) or die();
//ob_start();
global $xoopsUser;

if (
is_object($xoopsUser)) {
require_once 
XOOPS_ROOT_PATH.'/FirePHPCore/FirePHP.class.php';
$fb FirePHP::getInstance(true);
$ret '';

$this->addExtra'Included files'count get_included_files() ) . ' files' );
$memory 0;
if ( 
function_exists'memory_get_usage' ) ) {
    
$memory memory_get_usage() . ' bytes';
} else {
    
$os = isset( $_ENV['OS'] ) ? $_ENV['OS'] : $_SERVER['OS'];
    if ( 
strposstrtolower$os ), 'windows') !== false ) {
        
$out = array();
        
exec('tasklist /FI "PID eq ' getmypid() . '" /FO LIST'$out );
        
$memory substr$out[5], strpos$out[5], ':') + 1) . ' [Estimated]';
    }
}
if ( 
$memory ) {
    
$this->addExtra'Memory usage'$memory );
}

if ( empty(
$mode) || $mode == 'errors' ) {
    
$types = array(
        
E_USER_NOTICE => 'Notice',
        
E_USER_WARNING => 'Warning',
        
E_USER_ERROR => 'Error',
        
E_NOTICE => 'Notice',
        
E_WARNING => 'Warning',
        
E_STRICT => 'Strict',
    );
  
$fberrors = array();

    foreach ( 
$this->errors as $error ) {
        
$fberrorstype = isset( $types$error['errno'] ] ) ? $types$error['errno'] ] : 'Unknown';
        
$fberrors[] = array($fberrorstype.sprintf": %s in file %s line %s"$this->sanitizePath($error['errstr']), $this->sanitizePath($error['errfile']), $error['errline'] ));
    }
if (!empty(
$fberrors)) $fb->table('Errors'$fberrors);
}

if ( empty(
$mode) || $mode == 'queries' ) {
  
$fbqueries = array();

    
$pattern '/b' preg_quote($GLOBALS['xoopsDB']->prefix()) . '_/i';

    foreach (
$this->queries as $q) {
        
$sql preg_replace($pattern''$q['sql']);
        if (isset(
$q['error'])) {
            
$fbqueries[] = array(htmlentities($sql).' Error number: '.$q['errno'].' Error message: '.$q['error']);
        } else {
            
$fbqueries[] = array(htmlentities($sql));
        }
    }
    
$fbqueries[] = array('Total: '.count($this->queries).' queries');

$fb->table('Queries'$fbqueries);
}

if ( empty(
$mode) || $mode == 'blocks' ) {
  
$fbblocks = array();

    foreach (
$this->blocks as $b) {
        if (
$b['cached']) {
            
$fbblocks[] = array(htmlspecialchars($b['name']).': Cached (regenerates every '.intval($b['cachetime']).' seconds)');
        } else {
            
$fbblocks[] = array(htmlspecialchars($b['name']).': No Cache');
        }
    }
    
$fbblocks[] = array('Total: '.count($this->blocks).' blocks');

    if (
count($this->blocks) > 0$fb->table('Blocks'$fbblocks);
}

if ( empty(
$mode) || $mode == 'extra' ) {
    
$fbextra = array();

    foreach (
$this->extra as $ex) {
        
$fbextra[] = array(htmlspecialchars($ex['name']).': '.htmlspecialchars($ex['msg']));
    }

    
$fb->table('Extra'$fbextra);
}

if ( empty(
$mode) || $mode == 'timers' ) {
    
$fbtimers = array();

    foreach ( 
$this->logstart as $k => $v ) {
        
$fbtimers[] = array(htmlspecialchars($k).' took ' sprintf"%.03f"$this->dumpTime($k) ) . ' seconds to load.');
    }

    
$fb->table('Timers'$fbtimers);
}
}

?>


Die Ausgabe ist leider nicht formschön, aber besser als vorher.

Ich hoffe dieser Code kann irgendwem nützen?

Edit: ich habe noch eine Abfrage nach xoopsUser eingebaut, um den Debug vor Gästen zu verstecken.

Aktuell aus dem Forum

Forum Thema Antworten Views Letzter Beitrag
Modulentwicklung New Xoops Xcreate Module 0 5321 26.11.2025 15:22
efkan Gehe zum letzten Beitrag
Modulentwicklung XOOPS Custom Field Module 1 1813 24.11.2025 11:21
Goffy Gehe zum letzten Beitrag