Installation
Add the bundle to your composer.json:
composer require dvelopment/firephp-bundle
Register the bundle in config/bundles.php:
return [
// ...
Development\FirePHPBundle\DevelopmentFirePHPBundle::class => ['all' => true],
];
Enable FirePHP
Add the following to your config/packages/framework.yaml:
framework:
http_client:
on_kernel_response: ['Development\FirePHPBundle\EventListener\FirePHPListener']
First Usage
Inject the FirePHPCore service and log a message in a controller:
use Development\FirePHPBundle\FirePHPCore;
class DebugController extends AbstractController
{
public function log(FirePHPCore $firephp): Response
{
$firephp->log('This is a FirePHP message');
return new Response('Check your browser console (FirePHP extension required)');
}
}
FirePHPCore service is the primary entry point for logging.FirePHPListener processes responses to inject FirePHP headers.Basic Logging
Use FirePHPCore to log messages, arrays, or exceptions:
$firephp->log('User created', FirePHPCore::LOG_INFO);
$firephp->log(['user_id' => 1, 'name' => 'John'], FirePHPCore::LOG_DEBUG);
$firephp->log(new \RuntimeException('Oops!'), FirePHPCore::LOG_ERROR);
Conditional Logging Wrap logs in debug checks to avoid clutter in production:
if ($this->get('kernel')->getEnvironment() === 'dev') {
$firephp->log('Debug info', FirePHPCore::LOG_DEBUG);
}
Grouping Logs Use FirePHP’s grouping feature to organize logs:
$firephp->group('Database Query');
$firephp->log('SELECT * FROM users WHERE id = 1');
$firephp->groupEnd();
Event Subscribers
Attach FirePHP logging to Symfony events (e.g., kernel.exception):
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
public function onKernelException(GetResponseForExceptionEvent $event)
{
$firephp = $this->get('firephp.core');
$firephp->log($event->getThrowable(), FirePHPCore::LOG_ERROR);
}
Twig Integration Log variables in Twig templates (via a custom extension):
// src/Twig/Extension/FirePHPExtension.php
public function getFunctions()
{
return [
new \Twig\TwigFunction('fire_log', [$this, 'fireLog']),
];
}
public function fireLog($message, $level = FirePHPCore::LOG_INFO)
{
$this->firephp->log($message, $level);
}
Usage in Twig:
{% if app.environment == 'dev' %}
{{ fire_log('Template variable: ' ~ dump(variable)) }}
{% endif %}
Command-Line Logging Use FirePHP in CLI commands (requires browser-based inspection):
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
protected function execute(InputInterface $input, OutputInterface $output)
{
$firephp = $this->get('firephp.core');
$firephp->log('Command executed', FirePHPCore::LOG_INFO);
}
Browser Extension Required FirePHP logs only appear in browsers with the Firebug extension (or Chrome’s built-in console with FirePHP support). Logs won’t show in:
curl or API clients.Performance Overhead FirePHP adds HTTP headers to responses, which may impact performance in high-traffic apps. Disable in production:
# config/packages/dev/firephp.yaml
development_firephp:
enabled: true
Symfony 5+ Compatibility The bundle may not be fully tested with newer Symfony versions. Check for:
on_kernel_response in HttpClient.Log Level Confusion
FirePHP’s log levels (LOG_INFO, LOG_DEBUG) differ from Symfony’s LoggerInterface. Stick to the bundle’s constants to avoid unexpected behavior.
Verify Headers
Inspect response headers for X-FirePHP- keys. Missing headers indicate:
FirePHPListener isn’t registered.Check Kernel Environment
FirePHP often defaults to dev mode. Override in config/packages/dev/firephp.yaml:
development_firephp:
enabled: true
log_level: LOG_DEBUG # Override default level
Clear Cache After updating the bundle, run:
php bin/console cache:clear
Custom Log Levels
Extend the bundle by adding custom log levels in FirePHPCore:
const LOG_CUSTOM = 7;
// Then use:
$firephp->log('Custom message', self::LOG_CUSTOM);
Modify Headers
Override the FirePHPListener to customize headers or payloads:
// src/EventListener/CustomFirePHPListener.php
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$firephp = $this->get('firephp.core');
$response->headers->add([
'X-Custom-FirePHP' => $firephp->getHeaders(),
]);
}
Integrate with Monolog Bridge FirePHP logs to Monolog for persistence:
use Monolog\Logger;
$firephp->log('Message', FirePHPCore::LOG_INFO);
$this->monolog->addRecord(Logger::INFO, 'FirePHP: ' . $firephp->getLastMessage());
How can I help you explore Laravel packages today?