19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apacheのログで日本語の文字化けを直す

Posted at

直すという表現はあまり正確では無いかも知れないですが、Apacheのログに日本語などのマルチバイトの文字列を表示すると文字化けをしていた見れないということがよくあると思います。

[Thu Jan 21 12:35:07 2016] [error] [client xxx.xxx.xxx.xxx] \xe6\x96\x87\xe5\xad\x97\xe5\x8c\x96\xe3\x81\x91\xe5\x8a\xa9\xe3\x81\x91\xe3\x81\xa6

tailコマンドでよく確認することが多いですが、その時に以下のようなコマンドで表示をすると文字化けが解消されます。

tail -f error.log | perl -nle 's/\?\\([a-f\d]{3})/chr($1)/ieg;s/\\x([a-f\d]{2})/pack("C", hex($1))/ieg;print $_;'

実行すると

[Thu Jan 21 12:35:07 2016] [error] [client xxx.xxx.xxx.xxx] 文字化け助けて

素晴らしい。

参考記事

http://raharu0425.hatenablog.com/entry/20121126/1353911491

19
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?