Development

/branches/1.0/lib/log/sfLogger/sfWebDebugLogger.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/log/sfLogger/sfWebDebugLogger.class.php

Revision 7762, 2.4 kB (checked in by fabien, 7 years ago)

fixed web debug toolbar segfaults PHP when debugging using xdebug

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  *
13  * @package    symfony
14  * @subpackage log
15  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
16  * @version    SVN: $Id$
17  */
18 class sfWebDebugLogger
19 {
20   protected
21     $webDebug = null;
22
23   /**
24    * Initializes the web debug logger.
25    *
26    * @param array Logger options
27    */
28   public function initialize($options = array())
29   {
30     if (!sfConfig::get('sf_web_debug'))
31     {
32       return;
33     }
34
35     $this->webDebug = sfWebDebug::getInstance();
36   }
37
38   /**
39    * Logs a message.
40    *
41    * @param string Message
42    * @param string Message priority
43    * @param string Message priority name
44    */
45   public function log($message, $priority, $priorityName)
46   {
47     if (!sfConfig::get('sf_web_debug'))
48     {
49       return;
50     }
51
52     // if we have xdebug, add some stack information
53     $debug_stack = array();
54
55     // disable xdebug when an HTTP debug session exists (crashes Apache, see #2438)
56     if (function_exists('xdebug_get_function_stack') && !isset($_GET['XDEBUG_SESSION_START']) && !isset($_COOKIE['XDEBUG_SESSION']))
57     {
58       foreach (xdebug_get_function_stack() as $i => $stack)
59       {
60         if (
61           (isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log')))
62           || !isset($stack['function'])
63         )
64         {
65           $tmp = '';
66           if (isset($stack['function']))
67           {
68             $tmp .= 'in "'.$stack['function'].'" ';
69           }
70           $tmp .= 'from "'.$stack['file'].'" line '.$stack['line'];
71           $debug_stack[] = $tmp;
72         }
73       }
74     }
75
76     // get log type in {}
77     $type = 'sfOther';
78     if (preg_match('/^\s*{([^}]+)}\s*(.+?)$/', $message, $matches))
79     {
80       $type    = $matches[1];
81       $message = $matches[2];
82     }
83
84     // build the object containing the complete log information.
85     $logEntry = array(
86       'priority'       => $priority,
87       'priorityString' => $priorityName,
88       'time'           => time(),
89       'message'        => $message,
90       'type'           => $type,
91       'debugStack'     => $debug_stack,
92     );
93
94     // send the log object.
95     $this->webDebug->log($logEntry);
96   }
97 }
98
Note: See TracBrowser for help on using the browser.