/** * Log exception * */ public function logException(\Exception $ex) { $exceptionClass = get_class($ex); $level = \OCP\Util::FATAL; if (isset($this->nonFatalExceptions[$exceptionClass])) { $level = \OCP\Util::DEBUG; } $message = $ex->getMessage(); if ($ex instanceof Exception) { if (empty($message)) { $response = new Response($ex->getHTTPCode()); $message = $response->getStatusText(); } $message = "HTTP/1.1 {$ex->getHTTPCode()} {$message}"; } $exception = ['Message' => $message, 'Code' => $ex->getCode(), 'Trace' => $ex->getTraceAsString(), 'File' => $ex->getFile(), 'Line' => $ex->getLine()]; $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); }
/** * create shared secret and return it * * @return \OC_OCS_Result */ public function getSharedSecret() { $url = $this->request->getParam('url'); $token = $this->request->getParam('token'); if ($this->trustedServers->isTrustedServer($url) === false) { $this->logger->log(\OCP\Util::ERROR, 'remote server not trusted (' . $url . ') while getting shared secret'); return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN); } if ($this->isValidToken($url, $token) === false) { $this->logger->log(\OCP\Util::ERROR, 'remote server (' . $url . ') didn\'t send a valid token (got ' . $token . ') while getting shared secret'); return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN); } $sharedSecret = $this->secureRandom->generate(32); $this->trustedServers->addSharedSecret($url, $sharedSecret); // reset token after the exchange of the shared secret was successful $this->dbHandler->addToken($url, ''); return new \OC_OCS_Result(['sharedSecret' => $sharedSecret], Http::STATUS_OK); }
/** * @inheritdoc */ public function log($level, $message, array $context = array()) { $this->logger->log($level, $message, array_merge($this->context, $context)); }
private function log($level, $message, $params) { $msg = vsprintf($message, $params); $this->logger->log($level, $msg, ['app' => $this->loggerName]); }