backtrace() public method

public backtrace ( $sh = null, $backtrace = null )
Example #1
0
 public static function transform($xml, $xsltName, $mimeType = 'text/html', $status = 200)
 {
     if (null !== self::$lock) {
         Logger::backtrace('XSLT recursion: ' . $xsltName . ' while in ' . self::$lock);
         throw new RuntimeException(t('Рекурсия в XSLT недопустима.'));
     }
     $mode = empty($_GET['xslt']) ? 'server' : $_GET['xslt'];
     $xml = self::fixEntities($xml);
     if ('none' == $mode or empty($xsltName)) {
         return new Response('<?xml version="1.0"?>' . $xml, 'text/xml', $status);
     }
     if (!file_exists($xsltName)) {
         throw new RuntimeException(t('Шаблон %name не найден.', array('%name' => $xsltName)));
     }
     if ('client' == $mode) {
         $xml = str_replace('?>', '?><?xml-stylesheet type="text/xsl" href="' . $xsltName . '"?>', $xml);
         return new Response($xml, 'text/xml');
     }
     $nocache = !empty($_GET['nocache']);
     $cache = cache::getInstance();
     $ckey = 'xml:xsl:' . md5($xml) . ',' . filemtime($xsltName);
     if (false === ($output = $cache->{$ckey}) or $nocache) {
         set_error_handler(array(__CLASS__, 'eh'));
         $doc = new DOMDocument();
         $doc->loadXML($xml);
         if (class_exists('xsltCache') and !$nocache) {
             $proc = new xsltCache();
             $proc->importStyleSheet($xsltName);
         } else {
             $xsl = new DOMDocument();
             @$xsl->load($xsltName);
             $proc = new XSLTProcessor();
             $proc->importStyleSheet($xsl);
         }
         self::$lock = $xsltName;
         if ($output = str_replace(' xmlns=""', '', $proc->transformToXML($doc))) {
             $cache->{$ckey} = $output;
         }
         self::$lock = null;
         restore_error_handler();
     }
     if (empty($output)) {
         throw new RuntimeException(t('Шаблон %xslt ничего не вернул.', array('%xslt' => $xsltName)));
     }
     if (null === $mimeType) {
         return trim(str_replace('<?xml version="1.0"?>', '', $output));
     }
     return new Response($output, $mimeType, $status);
 }
Example #2
0
 public static function debug()
 {
     if (empty($_SERVER['HTTP_HOST']) or $ctx = Context::last() and $ctx->canDebug()) {
         if (ob_get_length()) {
             ob_end_clean();
         }
         $output = array();
         if (func_num_args()) {
             foreach (func_get_args() as $arg) {
                 if (is_resource($arg)) {
                     $output[] = 'resource';
                 } elseif (is_string($arg) and !empty($arg)) {
                     $output[] = $arg;
                 } else {
                     $output[] = preg_replace('/ =>\\s+/', ' => ', self::dump($arg)) . ';';
                 }
             }
         } else {
             $output[] = 'breakpoint';
         }
         if (ob_get_length()) {
             ob_end_clean();
         }
         if (!empty($_SERVER['REQUEST_METHOD'])) {
             header("Content-Type: text/plain; charset=utf-8");
         }
         print join("\n\n", $output) . "\n\n";
         if (true) {
             printf("--- backtrace (request duration: %s) ---\n", microtime(true) - MCMS_START_TIME);
             print Logger::backtrace();
             if (function_exists('memory_get_peak_usage')) {
                 printf("\n--- memory usage ---\nnow:  %s\npeak: %s\n", self::filesize(memory_get_usage()), self::filesize(memory_get_peak_usage()));
             }
         }
         die;
     }
 }
Example #3
0
 /**
  * Отправляет сообщение об ошибке куда следует.
  */
 private static function send_error($message = "undefined", $extra = null)
 {
     Logger::trace($message);
     if (class_exists('BebopMimeMail')) {
         $message = wordwrap(strip_tags($message), 75, "\n         ");
         $referer = empty($_SERVER['HTTP_REFERER']) ? null : "Referer: {$_SERVER['HTTP_REFERER']}\n";
         $subject = "Error at " . MCMS_HOST_NAME;
         $content = "<pre>Message: {$message}\nMethod:  {$_SERVER['REQUEST_METHOD']}\n" . "URL:     http://" . MCMS_HOST_NAME . MCMS_REQUEST_URI . "\n{$extra}\n{$referer}" . "Backtrace follows.\n\n" . Logger::backtrace() . '</pre>';
         BebopMimeMail::send(null, Context::last()->config->get('main/errors/mail'), $subject, $content);
     }
 }
Example #4
0
File: cli.php Project: nexgenta/log
 public function main($args)
 {
     Logger::$stderr = array();
     if ($this->stderr) {
         Logger::$stderr[] = $this->pri[1];
     }
     Logger::$syslog = array();
     Logger::$syslogFacility = $this->pri[0];
     Logger::$backtrace = array();
     /* No point in backtracing */
     if ($this->syslog) {
         Logger::$syslog[] = $this->pri[1];
     }
     if ($this->filename) {
         $f = fopen($this->filename, 'r');
     } else {
         if (strlen($this->text)) {
             Logger::log($this->text, $this->pri[1], $this->tag, $this->request);
             return;
         } else {
             $f = fopen('php://stdin', 'r');
         }
     }
     if (!$f) {
         return false;
     }
     while (!feof($f)) {
         $line = trim(fgets($f));
         if (strlen($line)) {
             Logger::log($line, $this->pri[1], $this->tag, $this->request);
         }
     }
     fclose($f);
 }
Example #5
0
 public function __construct($args)
 {
     global $LOG_SYSLOG, $LOG_SYSLOG_FACILITY, $LOG_BACKTRACE, $LOG_STDERR;
     if (isset($args['db'])) {
         parent::__construct($args);
     }
     if (!self::$pid) {
         self::$pid = getmypid();
     }
     if (!self::$ferr) {
         self::$ferr = fopen('php://stderr', 'w');
     }
     if (defined('CLUSTER_IRI') && !self::$clusterName) {
         require_once APPS_ROOT . 'cluster/model.php';
         $cluster = ClusterModel::getInstance();
         self::$clusterName = $cluster->clusterName;
         self::$instanceName = $cluster->instanceName;
         self::$clusterSpec = ' ' . self::$clusterName . '/' . self::$instanceName;
     }
     if (!isset(self::$syslog)) {
         self::$syslog = $LOG_SYSLOG;
     }
     if (!isset(self::$syslogFacility)) {
         self::$syslogFacility = $LOG_SYSLOG_FACILITY;
     }
     if (!isset(self::$backtrace)) {
         self::$backtrace = $LOG_BACKTRACE;
     }
     if (!isset(self::$stderr)) {
         self::$stderr = $LOG_STDERR;
     }
     if ($this->db) {
         do {
             $this->db->begin();
             if (self::$clusterName) {
                 if ($this->db->row('SELECT * FROM {log_count} WHERE "log_cluster" = ? AND "log_instance" = ?', self::$clusterName, self::$instanceName)) {
                     $this->db->rollback();
                     break;
                 }
             } else {
                 if ($this->db->row('SELECT * FROM {log_count} WHERE "log_cluster" IS NULL AND "log_instance" IS NULL')) {
                     $this->db->rollback();
                     break;
                 }
             }
             $this->db->insert('log_count', array('log_cluster' => self::$clusterName, 'log_instance' => self::$instanceName, 'log_count' => 0));
         } while (!$this->db->commit());
     }
 }