Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Firephp Bundle Laravel Package

dvelopment/firephp-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. Enable FirePHP Add the following to your config/packages/framework.yaml:

    framework:
        http_client:
            on_kernel_response: ['Development\FirePHPBundle\EventListener\FirePHPListener']
    
  3. 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)');
        }
    }
    

Where to Look First

  • Documentation: Check the GitHub README for basic setup.
  • Service: The FirePHPCore service is the primary entry point for logging.
  • Event Listener: The FirePHPListener processes responses to inject FirePHP headers.

Implementation Patterns

Logging Workflows

  1. 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);
    
  2. 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);
    }
    
  3. Grouping Logs Use FirePHP’s grouping feature to organize logs:

    $firephp->group('Database Query');
    $firephp->log('SELECT * FROM users WHERE id = 1');
    $firephp->groupEnd();
    

Integration Tips

  1. 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);
    }
    
  2. 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 %}
    
  3. 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);
    }
    

Gotchas and Tips

Pitfalls

  1. 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:

    • Headless browsers (e.g., Selenium).
    • curl or API clients.
    • Production environments (unless explicitly enabled).
  2. 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
    
  3. Symfony 5+ Compatibility The bundle may not be fully tested with newer Symfony versions. Check for:

    • Deprecated on_kernel_response in HttpClient.
    • Changes in service container autowiring.
  4. 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.

Debugging Tips

  1. Verify Headers Inspect response headers for X-FirePHP- keys. Missing headers indicate:

    • The FirePHPListener isn’t registered.
    • The bundle is disabled in config.
  2. 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
    
  3. Clear Cache After updating the bundle, run:

    php bin/console cache:clear
    

Extension Points

  1. 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);
    
  2. 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(),
        ]);
    }
    
  3. 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());
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours