本文整理匯總了PHP中Horde::getLogger方法的典型用法代碼示例。如果您正苦於以下問題:PHP Horde::getLogger方法的具體用法?PHP Horde::getLogger怎麽用?PHP Horde::getLogger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Horde
的用法示例。
在下文中一共展示了Horde::getLogger方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: logMessage
/**
* Logs a message to the global Horde log backend.
*
* @param mixed $message Either a string or a PEAR_Error object.
* @param string $file What file was the log function called from
* (e.g. __FILE__)?
* @param integer $line What line was the log function called from
* (e.g. __LINE__)?
* @param integer $priority The priority of the message. One of:
* <pre>
* PEAR_LOG_EMERG
* PEAR_LOG_ALERT
* PEAR_LOG_CRIT
* PEAR_LOG_ERR
* PEAR_LOG_WARNING
* PEAR_LOG_NOTICE
* PEAR_LOG_INFO
* PEAR_LOG_DEBUG
* </pre>
*/
function logMessage($message, $file, $line, $priority = PEAR_LOG_INFO)
{
$logger =& Horde::getLogger();
if ($logger === false) {
return;
}
if ($priority > $GLOBALS['conf']['log']['priority']) {
return;
}
if (is_a($message, 'PEAR_Error')) {
$userinfo = $message->getUserInfo();
$message = $message->getMessage();
if (!empty($userinfo)) {
if (is_array($userinfo)) {
$old_error = error_reporting(0);
$userinfo = implode(', ', $userinfo);
error_reporting($old_error);
}
$message .= ': ' . $userinfo;
}
} elseif (is_callable(array($message, 'getMessage'))) {
$message = $message->getMessage();
}
$app = isset($GLOBALS['registry']) ? $GLOBALS['registry']->getApp() : 'horde';
$message = '[' . $app . '] ' . $message . ' [pid ' . getmypid() . ' on line ' . $line . ' of "' . $file . '"]';
/* Make sure to log in the system's locale. */
$locale = setlocale(LC_TIME, 0);
setlocale(LC_TIME, 'C');
$logger->log($message, $priority);
/* Restore original locale. */
setlocale(LC_TIME, $locale);
return true;
}