1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
---
layout: post
category: perl
title: PSGIChrome
---
Earlier this month, I've read about this extension: "chromePHP":http://www.chromephp.com/.
The principle of this extension is to allow you to log from your PHP application to crhome. You may not be aware, but this is something you already have with every web application if you're using Plack. And not only for Chrome, but every webkit navigator, and Firefox!
Let's mimic their page.
h1. Installation
# install "Plack::Middleware::ConsoleLogger":http://search.cpan.org/perldoc?Plack::Middleware::ConsoleLogger (*cpanminus Plack::Middleware::ConsoleLogger*)
# no step 2
# no step 3
# write a simple PSGI application and log
<script
src="https://gist.github.com/750108.js?file=chromeplack.pl"></script>
Load this application with plackup:
bc. plackup chromeplack.pl
point your browser to *http://localhost:5000*, activate the javascript console (with chrome of firefox, this work with both).
if this works correctly, you should have a smiliar output in your console:
<a href="http://f.lumberjaph.net/blog/misc/plack_chrome.png"><img class="img_center" src="http://f.lumberjaph.net/blog/misc/plack_chrome.png" /></a>
h2. Dancer
I don't know for other framework, but you can also log to your browser with "Dancer":http://perldancer.org/.
First, you need to install "Dancer::Logger::PSGI":http://search.cpan.org/perldoc?Dancer::Logger::PSGI, then, in your application, you need to edit the environment file. You'll certainly want to change 'development.yml'.
bc.. logger: "PSGI"
plack_middlewares:
-
- ConsoleLogger
p. Now you can start your application (running in Plack environment, of course), and next time you'll use 'warning' or 'debug' or any other keyword from Dancer::Logger, the message will end up in your javascript console.
|