PHP code example of tourze / symfony-logger-bundle

1. Go to this page and download the library: Download tourze/symfony-logger-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / symfony-logger-bundle example snippets




return [
    // ...
    Tourze\SymfonyLoggerBundle\SymfonyLoggerBundle::class => ['all' => true],
];



use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class CustomFileCleanSubscriber implements EventSubscriberInterface
{
    public function onTerminate(TerminateEvent $event): void
    {
        // Your custom cleanup logic here
        // This will run before the default cleanup
    }

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::TERMINATE => ['onTerminate', -9998], // Higher priority
        ];
    }
}



use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

class LoggingFileCleanSubscriber
{
    public function __construct(private LoggerInterface $logger) {}

    public function onTerminate(TerminateEvent $event): void
    {
        foreach ($event->getRequest()->files->all() as $file) {
            $this->logger->info('Cleaning uploaded file', [
                'file' => is_array($file) ? $file['tmp_name'] ?? 'unknown' : $file->getPathname()
            ]);
        }
    }
}