plackup access log - locale and open pragma - encoding problem

南笙酒味 提交于 2019-12-08 00:40:46

问题


My locale setting is utf8, so, when starting plackup the date strings are localized too. Therefore I getting console access-log like the following:

$ plackup a.psgi 
HTTP::Server::PSGI: Accepting connections at http://0:5000/
127.0.0.1 - - [24/júl/2011:12:15:44 +0200] "GET / HTTP/1.1" 200 11 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7) AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 Safari/534.48.3"
                   ^- garbage

my partial a.psgi:

use 5.014;
use warnings;
use utf8;
use open qw(:std :utf8); #the problem....
use Encode;

use Plack::Builder;

use MyApp;
my $runner = MyApp->new(...);
my $app = sub {
    $runner->run(shift);
};

builder {$app;};

The problematic line is the open pragma. (I need the open pragma in MyApp). Without it, the the acccess log correctly print Júl, with it the access log got garbages.

So, How to fix my access log?

  • for either garbage-free printouts of localized date strings, or
  • converting access-log messages into C-locale

Any idea?

Ps: I know, than PSGI is byte oriented specification (and MyApp correctly handling it), but this problem is outside of MyApp.


回答1:


I think your open pragma is too broad. You say you need it, but did not name the details. You should be able to restrict it to the streams you're only using explicitely.

If that's too difficult to figure out, simply straighten out the IO layer for the STDERR stream where the log messages go:

binmode STDERR, ':bytes';


来源:https://stackoverflow.com/questions/6806310/plackup-access-log-locale-and-open-pragma-encoding-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!