问题
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