-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kobo): Add device info into logs and improve UX
- Loading branch information
Showing
6 changed files
with
107 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Controller\Kobo; | ||
|
||
use Devdot\Monolog\Parser; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
#[Route('/user/kobo')] | ||
class KoboDeviceLogsController extends AbstractController | ||
{ | ||
public function __construct( | ||
#[Autowire(param: 'kernel.logs_dir')] | ||
protected string $kernelLogsDir, | ||
#[Autowire(param: 'kernel.environment')] | ||
protected string $kernelEnvironment, | ||
) { | ||
} | ||
|
||
#[Route('/logs', name: 'app_kobodevice_user_logs', methods: ['GET'])] | ||
public function logs(): Response | ||
{ | ||
if (!$this->getUser() instanceof UserInterface) { | ||
throw $this->createAccessDeniedException(); | ||
} | ||
|
||
$records = []; | ||
|
||
try { | ||
$parser = new Parser($this->kernelLogsDir.'/kobo.'.$this->kernelEnvironment.'-'.date('Y-m-d').'.log'); | ||
|
||
$records = $parser->get(); | ||
} catch (\Exception $e) { | ||
$this->addFlash('warning', $e->getMessage()); | ||
} | ||
|
||
return $this->render('kobodevice_user/logs.html.twig', [ | ||
'records' => $records, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Kobo\LogProcessor; | ||
|
||
use App\Entity\KoboDevice; | ||
use App\Kobo\ParamConverter\KoboParamConverter; | ||
use Monolog\LogRecord; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class KoboContextProcessor | ||
{ | ||
public function __construct( | ||
private readonly RequestStack $requestStack, | ||
private readonly KoboParamConverter $koboParamConverter, | ||
) { | ||
} | ||
|
||
public function __invoke(LogRecord $record): LogRecord | ||
{ | ||
$request = $this->requestStack->getCurrentRequest(); | ||
|
||
if (!$request instanceof Request) { | ||
return $record; | ||
} | ||
|
||
if (false === $request->attributes->has('isKoboRequest')) { | ||
return $record; | ||
} | ||
|
||
$kobo = $this->getKoboFromRequest($request); | ||
$koboString = $kobo?->getId() ?? 'unknown'; | ||
$record->extra['kobo'] = $koboString; | ||
|
||
return $record; | ||
} | ||
|
||
private function getKoboFromRequest(Request $request): ?KoboDevice | ||
{ | ||
$device = $request->attributes->get('koboDevice'); | ||
if ($device instanceof KoboDevice) { | ||
return $device; | ||
} | ||
|
||
return $this->koboParamConverter->apply($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters