Source for file Ethna_Plugin_Logwriter.php

Documentation is available at Ethna_Plugin_Logwriter.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Logwriter.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id$
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Logwriter
  13. /**
  14.  *  ログ出力基底クラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**#@+
  22.      *  @access private
  23.      */
  24.  
  25.     /** @var    string  ログアイデンティティ文字列 */
  26.     var $ident;
  27.  
  28.     /** @var    int     ログファシリティ */
  29.     var $facility;
  30.  
  31.     /** @var    int     ログオプション */
  32.     var $option;
  33.  
  34.     /** @var    bool    バックトレースが取得可能かどうか */
  35.     var $have_backtrace;
  36.  
  37.     /** @var    array   ログレベル名テーブル */
  38.     var $level_name_table array(
  39.         LOG_EMERG   => 'EMERG',
  40.         LOG_ALERT   => 'ALERT',
  41.         LOG_CRIT    => 'CRIT',
  42.         LOG_ERR     => 'ERR',
  43.         LOG_WARNING => 'WARNING',
  44.         LOG_NOTICE  => 'NOTICE',
  45.         LOG_INFO    => 'INFO',
  46.         LOG_DEBUG   => 'DEBUG',
  47.     );
  48.  
  49.     /**#@-*/
  50.  
  51.     /**
  52.      *  Ethna_Plugin_Logwriterクラスのコンストラクタ
  53.      *
  54.      *  @access public
  55.      *  @param  string  $log_ident      ログアイデンティティ文字列(プロセス名等)
  56.      *  @param  int     $log_facility   ログファシリティ
  57.      *  @param  string  $log_file       ログ出力先ファイル名(LOG_FILEオプションが指定されている場合のみ)
  58.      *  @param  int     $log_option     ログオプション(LOG_FILE,LOG_FUNCTION...)
  59.      */
  60.     function Ethna_Plugin_Logwriter()
  61.     {
  62.     }
  63.  
  64.     /**
  65.      *  ログオプションを設定する
  66.      *
  67.      *  @access public
  68.      *  @param  int     $option     ログオプション(LOG_FILE,LOG_FUNCTION...)
  69.      */
  70.     function setOption($option)
  71.     {
  72.         $this->ident $option['ident'];
  73.         $this->facility $option['facility'];
  74.         $this->option $option;
  75.         $this->have_backtrace function_exists('debug_backtrace');
  76.     }
  77.  
  78.     /**
  79.      *  ログ出力を開始する
  80.      *
  81.      *  @access public
  82.      */
  83.     function begin()
  84.     {
  85.     }
  86.  
  87.     /**
  88.      *  ログを出力する
  89.      *
  90.      *  @access public
  91.      *  @param  int     $level      ログレベル(LOG_DEBUG, LOG_NOTICE...)
  92.      *  @param  string  $message    ログメッセージ(+引数)
  93.      */
  94.     function log($level$message)
  95.     {
  96.     }
  97.  
  98.     /**
  99.      *  ログ出力を終了する
  100.      *
  101.      *  @access public
  102.      */
  103.     function end()
  104.     {
  105.     }
  106.  
  107.     /**
  108.      *  ログアイデンティティ文字列を取得する
  109.      *
  110.      *  @access public
  111.      *  @return string  ログアイデンティティ文字列
  112.      */
  113.     function getIdent()
  114.     {
  115.         return $this->ident;
  116.     }
  117.  
  118.     /**
  119.      *  ログレベルを表示文字列に変換する
  120.      *
  121.      *  @access private
  122.      *  @param  int     $level  ログレベル(LOG_DEBUG,LOG_NOTICE...)
  123.      *  @return string  ログレベル表示文字列(LOG_DEBUG→"DEBUG")
  124.      */
  125.     function _getLogLevelName($level)
  126.     {
  127.         if (isset($this->level_name_table[$level]== false{
  128.             return null;
  129.         }
  130.         return $this->level_name_table[$level];
  131.     }
  132.  
  133.     /**
  134.      *  ログ出力箇所の情報(関数名/ファイル名等)を取得する
  135.      *
  136.      *  @access private
  137.      *  @return array   ログ出力箇所の情報
  138.      */
  139.     function _getBacktrace()
  140.     {
  141.         $skip_method_list array(
  142.             array('ethna''raise'),
  143.             array(null'raiseerror'),
  144.             array(null'handleerror'),
  145.             array('ethna_logger'null),
  146.             array('ethna_plugin_logwriter'null),
  147.             array('ethna_error'null),
  148.             array('ethna_apperror'null),
  149.             array('ethna_actionerror'null),
  150.             array('ethna_backend''log'),
  151.             array(null'ethna_error_handler'),
  152.             array(null'trigger_error'),
  153.         );
  154.  
  155.         if ($this->have_backtrace == false{
  156.             return null;
  157.         }
  158.  
  159.         $bt debug_backtrace();
  160.         $i 0;
  161.         while ($i count($bt)) {
  162.             if (isset($bt[$i]['class']== false{
  163.                 $bt[$i]['class'null;
  164.             }
  165.             if (isset($bt[$i]['file']== false{
  166.                 $bt[$i]['file'null;
  167.             }
  168.             if (isset($bt[$i]['line']== false{
  169.                 $bt[$i]['line'null;
  170.             }
  171.  
  172.             $skip false;
  173.  
  174.             // メソッドスキップ処理
  175.             foreach ($skip_method_list as $method{
  176.                 $class $function true;
  177.                 if ($method[0!= null{
  178.                     $class preg_match("/^$method[0]/i"$bt[$i]['class']);
  179.                 }
  180.                 if ($method[1!= null{
  181.                     $function preg_match("/^$method[1]/i"$bt[$i]['function']);
  182.                 }
  183.                 if ($class && $function{
  184.                     $skip true;
  185.                     break;
  186.                 }
  187.             }
  188.  
  189.             if ($skip{
  190.                 $i++;
  191.             else {
  192.                 break;
  193.             }
  194.         }
  195.  
  196.         $c =Ethna_Controller::getInstance();
  197.         $basedir $c->getBasedir();
  198.  
  199.         $function sprintf("%s.%s"isset($bt[$i]['class']$bt[$i]['class''global'$bt[$i]['function']);
  200.  
  201.         $file $bt[$i]['file'];
  202.         if (strncmp($file$basedirstrlen($basedir)) == 0{
  203.             $file substr($filestrlen($basedir));
  204.         }
  205.         if (strncmp($fileETHNA_BASEstrlen(ETHNA_BASE)) == 0{
  206.             $file preg_replace('#^/+#'''substr($filestrlen(ETHNA_BASE)));
  207.         }
  208.         $line $bt[$i]['line'];
  209.         return array('function' => $function'pos' => sprintf('%s:%s'$file$line));
  210.     }
  211. }
  212. // }}}
  213. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:35 +0900 by phpDocumentor 1.4.3