} switch ($e->getStatusCode()) { case 404: $viewer = new Syonix\LogViewer\LogManager($app['config']['logs']); return $app['twig']->render('error/log_file_not_found.html.twig', ['clients' => $viewer->getLogCollections(), 'current_client_slug' => null, 'current_log_slug' => null, 'error' => $e]); default: try { $viewer = new Syonix\LogViewer\LogManager($app['config']['logs']); $clients = $viewer->getLogCollections(); } catch (\Exception $e) { $clients = []; } return $app['twig']->render('error/error.html.twig', ['clients' => $clients, 'clientSlug' => null, 'logSlug' => null, 'message' => 'Something went wrong!', 'icon' => 'bug', 'error' => $e]); } }); $app->error(function (\Exception $e, $code) use($app) { if ($app['debug']) { return; } switch ($code) { default: try { $viewer = new Syonix\LogViewer\LogManager($app['config']['logs']); $clients = $viewer->getLogCollections(); } catch (\Exception $e) { $clients = []; } return $app['twig']->render('error/error.html.twig', ['clients' => $clients, 'clientSlug' => null, 'logSlug' => null, 'message' => 'Something went wrong!', 'icon' => 'bug', 'error' => $e]); } }); $app->run();
<?php use League\Flysystem\Adapter\Local; use Symfony\Component\HttpFoundation\Request; $api = $app['controllers_factory']; $api->get('/config', function (Silex\Application $app) { return $app->json(['debug' => $app['config']['debug'], 'timezone' => $app['config']['timezone'], 'date_format' => $app['config']['date_format'], 'display_logger' => $app['config']['display_logger'], 'default_limit' => $app['config']['default_limit'], 'reverse_line_order' => $app['config']['reverse_line_order']]); }); $api->get('/logs', function (Silex\Application $app, Request $request) { $viewer = new Syonix\LogViewer\LogManager($app['config']['logs']); $logCollections = $viewer->getLogCollections(); $returnLogs = (bool) $request->query->get('logs', false); $return = []; foreach ($logCollections as $logCollection) { $element = ['name' => $logCollection->getName(), 'slug' => $logCollection->getSlug(), 'url' => BASE_URL . '/api/logs/' . $logCollection->getSlug()]; if ($returnLogs) { foreach ($logCollection->getLogs() as $log) { $element['logs'][] = ['name' => $log->getName(), 'slug' => $log->getSlug(), 'url' => BASE_URL . '/api/logs/' . $logCollection->getSlug() . '/' . $log->getSlug()]; } } $return[] = $element; } $response = ['clients' => $return]; return $app->json($response); }); $api->get('/cache/clear', function (Silex\Application $app) { $cache = new \Syonix\LogViewer\LogFileCache(new Local(APP_PATH . '/cache')); $cache->emptyCache(); return $app->json(['message' => 'success']); }); $api->get('/logs/{clientSlug}', function (Silex\Application $app, $clientSlug) {