/** * 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; }