Hi! Please consider following me on twitter: @hanekomu.
2009年06月07日
Logging to Firefox with HTTP::Engine::FirePHP
I have released HTTP::Engine::FirePHP on CPAN; the development version is on Github.
If you are developing a web application and don't want to or can't check the error log, the traditional way is to include debug messages in the HTML page. However, this messes up the layout and mixes content with logging; the two really need to be separate.
FirePHP is a Firebug plugin which enables you to log to your Firebug Console by sending certain HTTP headers in the HTTP response. FirePHP is not just useful for PHP, though; any server-side application that can manipulate HTTP headers can log to Firebug.
The FirePHP response headers use the Wildfire protocol. The CPAN module FirePHP::Dispatcher can generate these headers.
This module then integrates FirePHP::Dispatcher with HTTP::Engine. By simply using this module,
HTTP::Engine::Response gets a fire_php() accessor
through which you can log to FirePHP.
Here is an example:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use HTTP::Engine; use HTTP::Engine::Response; use HTTP::Engine::FirePHP; HTTP::Engine->new( interface => { module => 'ServerSimple', args => { host => 'localhost', port => '10012', }, request_handler => sub { my $req = shift; my $res = HTTP::Engine::Response->new(body => 'Hello'); $res->fire_php->info('Hello from HTTP::Engine'); $res->fire_php->warn(sprintf 'path was %s', $req->uri->path); $res->fire_php->log(Dumper $req); $res; }, }, )->run;
When you load the response into Firefox, open the Firebug Console and you will find the logged messages there.
When you restart the HTTP::Engine-based server, be sure to do a
shift-reload of the relevant page in Firefox; this ensures that headers aren't
cached. If you don't do this, you might see remnant headers from previous
responses.
Tags: FirePHP, HTTP::Engine, web.
posted at: 14:54 | path: /dev | permalink | 0 comments | 0 trackbacks
Comments are closed for this story.
Trackbacks are closed for this story.
