Source for file Alertmail.php

Documentation is available at Alertmail.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Alertmail.php
  5.  *
  6.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: e416536d64fef98cfe656df5bca8fc3cb8cf2c87 $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Logwriter_Alertmail
  13. /**
  14.  *  ログ出力クラス(アラートメール)
  15.  *  Ethna_Logger にある _alert() をプラグインにしただけです。
  16.  *
  17.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  18.  *  @access     public
  19.  *  @package    Ethna
  20.  */
  21. {
  22.     /**#@+
  23.      *  @access private
  24.      */
  25.  
  26.     /** @private    array   アラート送信先メールアドレス */
  27.     private $mailaddress array();
  28.  
  29.     /**#@-*/
  30.  
  31.     /**
  32.      *  ログオプションを設定する
  33.      *
  34.      *  @access public
  35.      *  @param  int     $option     ログオプション(LOG_FILE,LOG_FUNCTION...)
  36.      */
  37.     function setOption($option)
  38.     {
  39.         parent::setOption($option);
  40.         
  41.         if (isset($option['mailaddress'])) {
  42.             $this->mailaddress preg_split('/\s*,\s*/',
  43.                                             $option['mailaddress'],
  44.                                             -1PREG_SPLIT_NO_EMPTY);
  45.         }
  46.     }
  47.  
  48.     /**
  49.      *  ログを出力する
  50.      *
  51.      *  @access public
  52.      *  @param  int     $level      ログレベル(LOG_DEBUG, LOG_NOTICE...)
  53.      *  @param  string  $message    ログメッセージ(+引数)
  54.      */
  55.     function log($level$message)
  56.     {
  57.         if (count($this->mailaddress== 0{
  58.             return;
  59.         }
  60.  
  61.         $prefix $this->ident;
  62.         if (array_key_exists("pid"$this->option)) {
  63.             $prefix .= sprintf('[%d]'getmypid());
  64.         }
  65.         $prefix .= sprintf('(%s): '$this->_getLogLevelName($level));
  66.         if (array_key_exists("function"$this->option||
  67.             array_key_exists("pos"$this->option)) {
  68.             $tmp "";
  69.             $bt $this->_getBacktrace();
  70.             if ($bt && $bt['function']
  71.                 && array_key_exists("function"$this->option) ) {
  72.                 $tmp .= $bt['function'];
  73.             }
  74.             if ($bt && array_key_exists("pos"$this->option&& $bt['pos']{
  75.                 $tmp .= $tmp sprintf('(%s)'$bt['pos']$bt['pos'];
  76.             }
  77.             if ($tmp{
  78.                 $prefix .= $tmp ": ";
  79.             }
  80.         }
  81.  
  82.         $this->_alert($prefix $message "\n");
  83.  
  84.         return $prefix $message;
  85.     }
  86.  
  87.     /**
  88.      *  メールを送信する
  89.      *
  90.      *  @access protected
  91.      *  @param  string  $message    ログメッセージ
  92.      */
  93.     function _alert($message)
  94.     {
  95.         restore_error_handler();
  96.  
  97.         $c Ethna_Controller::getInstance();
  98.         $appid $c->getAppId();
  99.  
  100.         $header "Mime-Version: 1.0\n";
  101.         $header .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
  102.         $header .= "X-Alert: " $appid;
  103.         $subject sprintf("[%s] alert (%s%s)\n"$appid,
  104.                            substr($message012),
  105.                            strlen($message12 "..." "");
  106.  
  107.         $message sprintf("--- [log message] ---\n%s\n\n"$message);
  108.         if (function_exists("debug_backtrace")) {
  109.             $bt debug_backtrace();
  110.             $message .= sprintf("--- [backtrace] ---\n%s\n"Ethna_Util::FormatBacktrace($bt));
  111.         }
  112.         
  113.         foreach ($this->mailaddress as $address{
  114.             mail($address,
  115.                  $subject,
  116.                  mb_convert_encoding($message"ISO-2022-JP"),
  117.                  $header);
  118.         }
  119.  
  120.         set_error_handler("ethna_error_handler");
  121.     }
  122. }
  123. // }}}

Documentation generated on Fri, 11 Nov 2011 03:57:31 +0900 by phpDocumentor 1.4.3