plackup 访问日志 - 区域设置和 open pragma - 编码问题
我的区域设置是 utf8,因此,当启动 plackup 时,日期字符串也会本地化。因此,我得到如下所示的控制台访问日志:
$ 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
我的部分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;};
有问题的行是open pragma
。 (我需要 MyApp 中的 open pragma)。如果没有它,访问日志会正确打印Júl
,有了它,访问日志就会出现垃圾。
那么,如何修复我的访问日志?
- 对于本地化日期字符串的无垃圾打印输出,或者将
- 访问日志消息转换为 C 语言环境
有什么想法吗?
Ps:我知道,PSGI 是面向字节的规范(并且 MyApp 正确处理它),但这个问题不在 MyApp 之外。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的
open
pragma 太宽泛了。你说你需要它,但没有透露细节。您应该能够将其限制为仅明确使用的流。如果这太难弄清楚,只需理清日志所在的 STDERR 流的 IO 层消息去:
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: