plackup 访问日志 - 语言环境和打开 pragma - 编码问题 [英] plackup access log - locale and open pragma - encoding problem

查看:61
本文介绍了plackup 访问日志 - 语言环境和打开 pragma - 编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的语言环境设置是 utf8,因此,当开始 plackup 时,日期字符串也已本地化.因此,我得到如下所示的控制台访问日志:

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

我的部分 a.psgi:

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;};

有问题的行是open pragma.(我需要 MyApp 中的 open pragma).没有它,访问日志正确打印​​Júl,访问日志有垃圾.

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?

  • 用于本地化日期字符串的无垃圾打印输出,或
  • 将访问日志消息转换为 C 语言环境

有什么想法吗?

Ps:我知道,PSGI 是面向字节的规范(并且 MyApp 正确处理它),但这个问题不在 MyApp 范围内.

推荐答案

我认为您的 open pragma 过于宽泛.你说你需要它,但没有说出细节.您应该能够将其限制为仅显式使用的流.

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.

如果这太难弄清楚,只需理顺 STDERR 流的 IO 层日志消息的去向:

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';

这篇关于plackup 访问日志 - 语言环境和打开 pragma - 编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆