/** * Builds and returns the HTML needed to fill a tab to display * within the Debug Bar * * @return string */ public function display() : string { $logger = Services::logger(true); $logs = $logger->logCache; if (empty($logs) || !is_array($logs)) { return '<p>Nothing was logged. If you were expecting logged items, ensure that LoggerConfig file has the correct threshold set.</p>'; } $output = "<table><theader><tr><th>Severity</th><th>Message</th></tr></theader><tbody>"; foreach ($logs as $log) { $output .= "<tr>"; $output .= "<td>{$log['level']}</td>"; $output .= "<td>" . htmlspecialchars($log['msg'], ENT_SUBSTITUTE, 'UTF-8') . "</td>"; $output .= "</tr>"; } return $output . "</tbody></table>"; }
/** * The class entry point. This is where the magic happens and all * of the framework pieces are pulled together and shown how to * make beautiful music together. Or something like that. :) * * @param RouteCollectionInterface $routes */ public function run(RouteCollectionInterface $routes = null) { $this->startBenchmark(); //-------------------------------------------------------------------- // Is there a "pre-system" hook? //-------------------------------------------------------------------- Hooks::trigger('pre_system'); $this->getRequestObject(); $this->getResponseObject(); $this->forceSecureAccess(); try { $this->tryToRouteIt($routes); //-------------------------------------------------------------------- // Are there any "pre-controller" hooks? //-------------------------------------------------------------------- Hooks::trigger('pre_controller'); $this->startController(); // Closure controller has run in startController(). if (!is_callable($this->controller)) { $controller = $this->createController(); //-------------------------------------------------------------------- // Is there a "post_controller_constructor" hook? //-------------------------------------------------------------------- Hooks::trigger('post_controller_constructor'); $this->runController($controller); } //-------------------------------------------------------------------- // Is there a "post_controller" hook? //-------------------------------------------------------------------- Hooks::trigger('post_controller'); $this->gatherOutput(); $this->sendResponse(); //-------------------------------------------------------------------- // Is there a post-system hook? //-------------------------------------------------------------------- Hooks::trigger('post_system'); } catch (Router\RedirectException $e) { $logger = Services::logger(); $logger->info('REDIRECTED ROUTE at ' . $e->getMessage()); // If the route is a 'redirect' route, it throws // the exception with the $to as the message $this->response->redirect($e->getMessage(), 'auto', $e->getCode()); $this->callExit(EXIT_SUCCESS); } catch (HTTP\RedirectException $e) { $this->callExit(EXIT_SUCCESS); } catch (PageNotFoundException $e) { $this->display404errors($e); } }
/** * A convenience/compatibility method for logging events through * the Log system. * * Allowed log levels are: * - emergency * - alert * - critical * - error * - warning * - notice * - info * - debug * * @param string $level * @param string $message * @param array|null $context * * @return mixed */ function log_message(string $level, string $message, array $context = []) { // When running tests, we want to always ensure that the // TestLogger is running, which provides utilities for // for asserting that logs were called in the test code. if (ENVIRONMENT == 'testing') { $logger = new \CodeIgniter\Log\TestLogger(new \Config\Logger()); return $logger->log($level, $message, $context); } return Services::logger(true)->log($level, $message, $context); }
/** * Constructor. * * @param RequestInterface $request * @param ResponseInterface $response * @param Logger $logger */ public function __construct(RequestInterface $request, ResponseInterface $response, Logger $logger = null) { $this->request = $request; $this->response = $response; $this->logger = is_null($logger) ? Services::logger(true) : $logger; $this->logger->info('Controller "' . get_class($this) . '" loaded.'); if ($this->forceHTTPS > 0) { $this->forceHTTPS($this->forceHTTPS); } $this->loadHelpers(); }