Source for file Logwriter.php

Documentation is available at Logwriter.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  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: c23b0fef239d47faac8af5d0f659b586956ec85f $
  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.     /** @protected    string  ログアイデンティティ文字列 */
  26.     protected $ident;
  27.  
  28.     /** @protected    int     ログファシリティ */
  29.     protected $facility;
  30.  
  31.     /** @protected    int     ログオプション */
  32.     protected $option;
  33.  
  34.     /** @protected    bool    バックトレースが取得可能かどうか */
  35.     protected $have_backtrace;
  36.  
  37.     /** @protected    array   ログレベル名テーブル */
  38.     protected $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.     /**
  53.      *  ログオプションを設定する
  54.      *
  55.      *  @access public
  56.      *  @param  int     $option     ログオプション(LOG_FILE,LOG_FUNCTION...)
  57.      */
  58.     function setOption($option)
  59.     {
  60.         $this->ident = $option['ident'];
  61.         $this->facility = $option['facility'];
  62.         $this->option = $option;
  63.         $this->have_backtrace = function_exists('debug_backtrace');
  64.     }
  65.  
  66.     /**
  67.      *  ログ出力を開始する
  68.      *
  69.      *  @access public
  70.      */
  71.     function begin()
  72.     {
  73.     }
  74.  
  75.     /**
  76.      *  ログを出力する
  77.      *
  78.      *  @access public
  79.      *  @param  int     $level      ログレベル(LOG_DEBUG, LOG_NOTICE...)
  80.      *  @param  string  $message    ログメッセージ(+引数)
  81.      */
  82.     function log($level$message)
  83.     {
  84.     }
  85.  
  86.     /**
  87.      *  ログ出力を終了する
  88.      *
  89.      *  @access public
  90.      */
  91.     function end()
  92.     {
  93.     }
  94.  
  95.     /**
  96.      *  ログアイデンティティ文字列を取得する
  97.      *
  98.      *  @access public
  99.      *  @return string  ログアイデンティティ文字列
  100.      */
  101.     function getIdent()
  102.     {
  103.         return $this->ident;
  104.     }
  105.  
  106.     /**
  107.      *  ログレベルを表示文字列に変換する
  108.      *
  109.      *  @access private
  110.      *  @param  int     $level  ログレベル(LOG_DEBUG,LOG_NOTICE...)
  111.      *  @return string  ログレベル表示文字列(LOG_DEBUG→"DEBUG")
  112.      */
  113.     function _getLogLevelName($level)
  114.     {
  115.         if (isset($this->level_name_table[$level]== false{
  116.             return null;
  117.         }
  118.         return $this->level_name_table[$level];
  119.     }
  120.  
  121.     /**
  122.      *  ログ出力箇所の情報(関数名/ファイル名等)を取得する
  123.      *
  124.      *  @access private
  125.      *  @return array   ログ出力箇所の情報
  126.      */
  127.     function _getBacktrace()
  128.     {
  129.         $skip_method_list array(
  130.             array('ethna''raise'),
  131.             array(null'raiseerror'),
  132.             array(null'handleerror'),
  133.             array('ethna_logger'null),
  134.             array('ethna_plugin_logwriter'null),
  135.             array('ethna_error'null),
  136.             array('ethna_apperror'null),
  137.             array('ethna_actionerror'null),
  138.             array('ethna_backend''log'),
  139.             array(null'ethna_error_handler'),
  140.             array(null'trigger_error'),
  141.         );
  142.  
  143.         if ($this->have_backtrace == false{
  144.             return null;
  145.         }
  146.  
  147.         $bt debug_backtrace();
  148.         $i 0;
  149.         while ($i count($bt)) {
  150.             if (isset($bt[$i]['class']== false{
  151.                 $bt[$i]['class'null;
  152.             }
  153.             if (isset($bt[$i]['file']== false{
  154.                 $bt[$i]['file'null;
  155.             }
  156.             if (isset($bt[$i]['line']== false{
  157.                 $bt[$i]['line'null;
  158.             }
  159.  
  160.             $skip false;
  161.  
  162.             // メソッドスキップ処理
  163.             foreach ($skip_method_list as $method{
  164.                 $class $function true;
  165.                 if ($method[0!= null{
  166.                     $class preg_match("/^$method[0]/i"$bt[$i]['class']);
  167.                 }
  168.                 if ($method[1!= null{
  169.                     $function preg_match("/^$method[1]/i"$bt[$i]['function']);
  170.                 }
  171.                 if ($class && $function{
  172.                     $skip true;
  173.                     break;
  174.                 }
  175.             }
  176.  
  177.             if ($skip{
  178.                 $i++;
  179.             else {
  180.                 break;
  181.             }
  182.         }
  183.  
  184.         $c Ethna_Controller::getInstance();
  185.         $basedir $c->getBasedir();
  186.  
  187.         $function sprintf("%s.%s"isset($bt[$i]['class']$bt[$i]['class''global'$bt[$i]['function']);
  188.  
  189.         $file $bt[$i]['file'];
  190.         if (strncmp($file$basedirstrlen($basedir)) == 0{
  191.             $file substr($filestrlen($basedir));
  192.         }
  193.         if (strncmp($fileETHNA_BASEstrlen(ETHNA_BASE)) == 0{
  194.             $file preg_replace('#^/+#'''substr($filestrlen(ETHNA_BASE)));
  195.         }
  196.         $line $bt[$i]['line'];
  197.         return array('function' => $function'pos' => sprintf('%s:%s'$file$line));
  198.     }
  199. }
  200. // }}}

Documentation generated on Fri, 11 Nov 2011 03:58:32 +0900 by phpDocumentor 1.4.3