Jump to content

Advanced Debugger In Blesta


MartyIX

Recommended Posts

Hello,

 

Blesta has its own mechanism for displaying errors. It is part of minPHP framework and the relevant files are /lib/stdlib.php and /lib/unknown_exception.php. However, there are PHP libraries that can help you further to ease development in PHP. I like https://packagist.org/packages/tracy/tracy (see an example here: http://examples.nette.org/ndebug/nette-exception.html)

 
Advantages
  • Tracy has a production mode (useful for production version of Blesta when you want to log exceptions and other errors to files) and a develoment mode (useful for plugin developers, maybe even Blesta developers). Development mode allows you to see stack trace, parameters and much more (see http://examples.nette.org/ndebug/nette-exception.html)
  • You can catch all unhandled exceptions. You can event catch NOTICE errors (I believe that everybody should do that.)
  • If an error occurs you have a log file to examine.
 
How to make it work in Blesta
 
1) Composer settings (composer.json)
 
{
        "config": {
                "vendor-dir": "vendors"
        },
        "require": {
                "tracy/tracy": "dev-master"
        }
}

2) Create folder /log (in Blesta folder)

 

3) Update /index.php
<?php
/* SVN FILE: $Id: index.php 52 2010-10-01 20:50:08Z cody $ */
/**
 * This file transfers control over to the dispatcher which will invoke the
 * appropriate controller. We also handle any exceptions that were not handled
 * elsewhere in the application, so we can end gracefully.
 *
 * @package       minPHP
 * @version       $Revision: 52 $
 * @modifiedby    $LastChangedBy: cody $
 * @lastmodified  $Date: 2010-10-01 13:50:08 -0700 (Fri, 01 Oct 2010) $
 */


$start = microtime(true);


include __DIR__ . '/vendors/autoload.php';
include __DIR__ . '/vendors/Logger/Logger.php'; // my logging class containing \BlestaLogger (it has nothing to do with Tracy)


\BlestaLogger::create();
\BlestaLogger::addDebug("==== REQUEST START ====");


//try {
    include(dirname(__FILE__) . "/lib/init.php");


    // Start Tracy 
    // Note: Error handlers are registered in lib/init.php. Tracy does the same therefore 
    //   Tracy needs to be initalized after init.php to overwrite previous behaviour)
    $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "";
    $productionMode = php_sapi_name() === 'cli' || stripos($serverName, '.local') === false;
    $logDir = __DIR__ . '/log';
    \Tracy\Debugger::$strictMode = true;
    \Tracy\Debugger::$scream = true;
    \Tracy\Debugger::$onFatalError = "\UnknownException::setFatalErrorHandler";
    \Tracy\Debugger::enable($productionMode, $logDir);


    // Dispatch the Web request
    if (!empty($_SERVER['REQUEST_URI']))
        Dispatcher::dispatch($_SERVER['REQUEST_URI']);
    // Dispatch the CLI request
    else
        Dispatcher::dispatchCli($argv);
//}
/*catch (Exception $e) {
    try {
        // Attempt to raise any error, gracefully
        Dispatcher::raiseError($e);
    }
    catch (Exception $e) {
        if (Configure::get("System.debug"))
            echo $e->getMessage() . " on line <strong>" . $e->getLine() .
                "</strong> in <strong>" . $e->getFile() . "</strong>\n" .
                "<br />Printing Stack Trace:<br />" . nl2br($e->getTraceAsString());
        else
            echo $e->getMessage();
    }
}*/


\BlestaLogger::addDebug("==== REQUEST END ====");
$end = microtime(true);


// Display rendering time if benchmarking is enabled
if (Configure::get("System.benchmark"))
    echo "execution time: " . ($end-$start) . " seconds";
?>

Feature request

 

If you like Tracy (please note that I'm not affiliated with the library in any way) maybe you can integrate it into Blesta.

 

 

Have a nice day!

Link to comment
Share on other sites

Thanks for the input. We certainly encourage developers to include whatever debugging libraries they would like to use (that's why the source is there). Unfortunately, Blesta (and minPHP) has a strict PHP 5.1.3 requirement, so until 5.3+ becomes almost entirely unverisal we can't make namespaces, etc. a requirement. The good news is that things are moving in that direction. Perhaps in a year or so.

Link to comment
Share on other sites

  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...