From cb4f77636ec43c0dd6195c8321b7d265e48c5e43 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 13 Aug 2016 09:07:21 -0700 Subject: Add image for psgichrome article. --- posts/2011-02-20-psgichrome.md | 74 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/posts/2011-02-20-psgichrome.md b/posts/2011-02-20-psgichrome.md index 1cd58a8..1618818 100644 --- a/posts/2011-02-20-psgichrome.md +++ b/posts/2011-02-20-psgichrome.md @@ -4,8 +4,7 @@ The principle of this extension is to allow you to log from your PHP application Let's mimic their page. -Installation ------------- +## Installation 1. install [Plack::Middleware::ConsoleLogger](http://search.cpan.org/perldoc?Plack::Middleware::ConsoleLogger) with `cpanm Plack::Middleware::ConsoleLogger` 2. no step 2 @@ -13,37 +12,37 @@ Installation 4. write a simple PSGI application and log ``` perl - use strict; - use warnings; - - use Plack::Builder; - - my $app = sub { - my $env = shift; - my $content = "this is foo"; - foreach my $k ( keys %$env ) { - if ( $k =~ /HTTP_/ ) { - $env->{'psgix.logger'}->({ - level => 'debug', - message => "$k => " . $env->{$k}, - }); - } - } - $env->{'psgix.logger'}->({ - level => 'warn', - message => 'this is a warning', - }); +use strict; +use warnings; + +use Plack::Builder; + +my $app = sub { + my $env = shift; + my $content = "this is foo"; + foreach my $k ( keys %$env ) { + if ( $k =~ /HTTP_/ ) { $env->{'psgix.logger'}->({ - level => 'error', - message => 'this is an error', + level => 'debug', + message => "$k => " . $env->{$k}, }); - return [ 200, [ 'Content-Type' => 'text/html' ], [$content] ]; - }; - - builder { - enable "ConsoleLogger"; - $app; } + } + $env->{'psgix.logger'}->({ + level => 'warn', + message => 'this is a warning', + }); + $env->{'psgix.logger'}->({ + level => 'error', + message => 'this is an error', + }); + return [ 200, [ 'Content-Type' => 'text/html' ], [$content] ]; +}; + +builder { + enable "ConsoleLogger"; + $app; +} ``` Load this application with plackup: `plackup chromeplack.pl` @@ -52,18 +51,19 @@ point your browser to , activate the javascript console. If this works correctly, you should have a smiliar output in your console: -Dancer ------- +![output](../assets/plack_chrome.webp) + +## 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'. -``` example - logger: "PSGI" - plack_middlewares: - - - - ConsoleLogger +``` yaml +logger: "PSGI" +plack_middlewares: + - + - ConsoleLogger ``` Now you can start your application (running in a 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. -- cgit v1.2.3