Source for file Ethna_Logger.php
Documentation is available at Ethna_Logger.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @author Masaki Fujimoto <fujimoto@php.net>
/** @var array ログファシリティ一覧 */
var $log_facility_list =
array(
'auth' =>
array('name' =>
'LOG_AUTH'),
'cron' =>
array('name' =>
'LOG_CRON'),
'daemon' =>
array('name' =>
'LOG_DAEMON'),
'kern' =>
array('name' =>
'LOG_KERN'),
'lpr' =>
array('name' =>
'LOG_LPR'),
'mail' =>
array('name' =>
'LOG_MAIL'),
'news' =>
array('name' =>
'LOG_NEWS'),
'syslog' =>
array('name' =>
'LOG_SYSLOG'),
'user' =>
array('name' =>
'LOG_USER'),
'uucp' =>
array('name' =>
'LOG_UUCP'),
'file' =>
array('name' =>
'LOG_FILE'),
'echo' =>
array('name' =>
'LOG_ECHO'),
/** @var array ログレベル一覧 */
var $log_level_list =
array(
'emerg' =>
array('name' =>
'LOG_EMERG', 'value' =>
7),
'alert' =>
array('name' =>
'LOG_ALERT', 'value' =>
6),
'crit' =>
array('name' =>
'LOG_CRIT', 'value' =>
5),
'err' =>
array('name' =>
'LOG_ERR', 'value' =>
4),
'warning' =>
array('name' =>
'LOG_WARNING', 'value' =>
3),
'notice' =>
array('name' =>
'LOG_NOTICE', 'value' =>
2),
'info' =>
array('name' =>
'LOG_INFO', 'value' =>
1),
'debug' =>
array('name' =>
'LOG_DEBUG', 'value' =>
0),
/** @var object Ethna_Controller controllerオブジェクト */
/** @var object Ethna_Controller controllerオブジェクト($controllerの省略形) */
/** @var array ログファシリティ */
/** @var array ログオプション */
/** @var array メッセージフィルタ(出力) */
var $message_filter_do =
array();
/** @var array メッセージフィルタ(無視) */
var $message_filter_ignore =
array();
/** @var string アラートメールアドレス */
/** @var array Ethna_LogWriter ログ出力オブジェクト */
/** @var bool ログ出力開始フラグ */
/** @var array ログスタック(begin()前にlog()が呼び出された場合のスタック) */
var $log_stack =
array();
* Ethna_Loggerクラスのコンストラクタ
* @param object Ethna_Controller $controller controllerオブジェクト
$this->controller =
& $controller;
$this->ctl =
& $this->controller;
$config =
& $controller->getConfig();
// ログファシリティテーブル補完(LOCAL0〜LOCAL8)
for ($i =
0; $i <
8; $i++
) {
$this->log_facility_list["local$i"] =
array('name' =>
"LOG_LOCAL$i");
$config_log =
$config->get('log');
$this->facility =
$this->_parseLogFacility($config->get('log_facility'));
foreach ($this->facility as $f) {
if (isset
($config_log[$f]['level'])) {
$this->level[$f] =
$this->_parseLogLevel($config_log[$f]['level']);
} else if (($level =
$config->get("log_level_$f")) !==
null) {
$this->level[$f] =
$this->_parseLogLevel($level);
} else if (($level =
$config->get("log_level")) !==
null) {
$this->level[$f] =
$this->_parseLogLevel($level);
$this->level[$f] =
LOG_WARNING;
if (isset
($config_log[$f]['filter_do'])) {
$this->message_filter_do[$f] =
$config_log[$f]['filter_do'];
} else if (($filter =
$config->get("log_filter_do_$f")) !==
null) {
$this->message_filter_do[$f] =
$filter;
} else if (($filter =
$config->get("log_filter_do")) !==
null) {
$this->message_filter_do[$f] =
$filter;
$this->message_filter_do[$f] =
'';
// メッセージフィルタ(filter_ignore)
if (isset
($config_log[$f]['filter_ignore'])) {
$this->message_filter_ignore[$f] =
$config_log[$f]['filter_ignore'];
} else if (($filter =
$config->get("log_filter_ignore_$f")) !==
null) {
$this->message_filter_ignore[$f] =
$filter;
} else if (($filter =
$config->get("log_filter_ignore")) !==
null) {
$this->message_filter_ignore[$f] =
$filter;
$this->message_filter_ignore[$f] =
'';
// そのたオプション (unsetはせずにそのまま渡す)
if (isset
($config_log[$f])) {
$this->option[$f] =
$config_log[$f];
$this->option[$f] =
array();
// 'option' によるオプション指定 (for B.C.)
if (isset
($config_log[$f]['option'])) {
$option =
$this->_parseLogOption($config_log[$f]['option']);
} else if (($option =
$config->get("log_option_$f")) !==
null) {
$option =
$this->_parseLogOption($option);
} else if (($option =
$config->get("log_option")) !==
null) {
$option =
$this->_parseLogOption($option);
$this->option[$f] =
array_merge($this->option[$f], $option);
$this->_parseLogLevel($config->get('log_alert_level'));
=
preg_split('/\s*,\s*/', $config->get('log_alert_mailaddress'));
* @return mixed ログファシリティ(ファシリティが1つ以下ならscalar、
if (count($this->facility) ==
0) {
} else if (count($this->facility) ==
1) {
return $this->facility[0];
// {{{ errorLevelToLogLevel
* @param int $errno PHPエラーレベル
* @return array ログレベル(LOG_NOTICE,...), エラーレベル表示名("E_NOTICE"...)
case E_ERROR:
$code =
"E_ERROR"; $level =
LOG_ERR; break;
case E_WARNING:
$code =
"E_WARNING"; $level =
LOG_WARNING; break;
case E_PARSE:
$code =
"E_PARSE"; $level =
LOG_CRIT; break;
case E_NOTICE:
$code =
"E_NOTICE"; $level =
LOG_NOTICE; break;
case E_USER_ERROR:
$code =
"E_USER_ERROR"; $level =
LOG_ERR; break;
case E_USER_WARNING:
$code =
"E_USER_WARNING"; $level =
LOG_WARNING; break;
case E_USER_NOTICE:
$code =
"E_USER_NOTICE"; $level =
LOG_NOTICE; break;
case E_STRICT:
$code =
"E_STRICT"; $level =
LOG_NOTICE; return;
default:
$code =
"E_UNKNOWN"; $level =
LOG_DEBUG; break;
return array($level, $code);
foreach ($this->facility as $f) {
$this->writer[$f] =
& $this->_getLogWriter($this->option[$f], $f);
$this->writer[$key]->begin();
if (count($this->log_stack) >
0) {
// copy and clear for recursive calls
$tmp_stack =
$this->log_stack;
$this->log_stack =
array();
while (count($tmp_stack) >
0) {
$this->log($log[0], $log[1]);
* @param int $level ログレベル(LOG_DEBUG, LOG_NOTICE...)
* @param string $message ログメッセージ(+引数)
function log($level, $message)
if ($this->is_begin ==
false) {
$this->log_stack[] =
array($level, $message);
// ログメッセージフィルタ(レベルフィルタに優先する)
$r =
$this->_evalMessageMask($this->message_filter_do[$key], $message);
$r =
$this->_evalMessageMask($this->message_filter_ignore[$key],
if ($this->_evalLevelMask($this->level[$key], $level)) {
$output =
$this->writer[$key]->log($level, $message);
if ($this->_evalLevelMask($this->alert_level, $level) ==
false) {
if (count($this->alert_mailaddress) >
0) {
$this->writer[$key]->end();
* @param array $option ログオプション
* @param string $facility ログファシリティ
* @return object LogWriter LogWriterオブジェクト
$facility =
$facility[0];
} else if (isset
($this->log_facility_list[$facility])) {
if ($facility ==
"file" ||
$facility ==
"echo") {
$plugin_manager =
& $this->controller->getPlugin();
$plugin_object =
$plugin_manager->getPlugin('Logwriter',
if (isset
($option['ident']) ==
false) {
$option['ident'] =
$this->controller->getAppId();
if (isset
($option['facility']) ==
false) {
$option['facility'] =
$facility;
$plugin_object->setOption($option);
* @param string $message ログメッセージ
$header =
"Mime-Version: 1.0\n";
$header .=
"Content-Type: text/plain; charset=ISO-2022-JP\n";
$header .=
"X-Alert: " .
$this->controller->getAppId();
$subject =
sprintf("[%s] alert (%s%s)\n",
strlen($message) >
12 ?
"..." :
"");
$mail =
sprintf("--- [log message] ---\n%s\n\n", $message);
$mail .=
sprintf("--- [backtrace] ---\n%s\n",
foreach ($this->alert_mailaddress as $mailaddress) {
* @param string $filter フィルタ
* @param string $message ログメッセージ
* @return mixed true:match, null:skip
function _evalMessageMask($filter, $message)
$regexp =
sprintf("/%s/", $filter);
* @param int $src ログレベルマスク
* @return bool true:閾値以下 false:閾値以上
function _evalLevelMask($src, $dst)
static $log_level_table =
null;
if (is_null($log_level_table)) {
$log_level_table =
array();
foreach ($this->log_level_list as $key =>
$def) {
if (defined($def['name']) ==
false) {
$log_level_table[constant($def['name'])] =
$def['value'];
if (isset
($log_level_table[$src]) ==
false
|| isset
($log_level_table[$dst]) ==
false) {
if ($log_level_table[$dst] >=
$log_level_table[$src]) {
* @param mixed $option ログオプション(設定ファイル値)
* @return array 解析された設定ファイル値(アラート通知メールアドレス,
function _parseLogOption($option)
foreach ($elts as $elt) {
if (preg_match('/^(.*?)\s*:\s*(.*)/', $elt, $match)) {
$ret[$match[1]] =
$match[2];
* @param string $facility ログファシリティ(設定ファイル値)
* @return array ログファシリティ(LOG_LOCAL0, LOG_FILE...)を格納した配列
function _parseLogFacility($facility)
$facility_list =
preg_split('/\s*,\s*/', $facility, -
1, PREG_SPLIT_NO_EMPTY);
* @param string $level ログレベル(設定ファイル値)
* @return int ログレベル(LOG_DEBUG, LOG_NOTICE...)
function _parseLogLevel($level)
if (isset
($this->log_level_list[strtolower($level)]) ==
false) {
$constant_name =
$this->log_level_list[strtolower($level)]['name'];
Documentation generated on Fri, 11 Nov 2011 03:59:54 +0900 by phpDocumentor 1.4.3