Apacheのエラーログで日本語のメッセージを参照するとこのように文字化けしてしまいます。
[yuuki@localhost ~]$ sudo less /var/log/httpd/error_log
[Mon Jan 25 00:01:17.680845 2021] [php:warn] [pid 16380] [client 10.0.2.2:57111] PHP Warning: \xe3\x81\x93\xe3\x81\xae\xe3\x83\x95\xe3\x82\xa1\xe3\x82\xa4\xe3\x83\xab\xe3\x82\x92\xe5\xae\x9f\xe8\xa1\x8c\xe3\x81\x99\xe3\x82\x8b\xe3\x81\xb9\xe3\x81\x8d\xe3\x81\xa7\xe3\x81\xaf\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93\xef\xbc\x81 in /var/www/html/work/hello.php on line 6
16進数で表示されてしまってるので、これをデコードして日本語に戻しましょう。
日本語に戻して表示するコマンド
[yuuki@localhost ~]$ tail -f /var/log/httpd/error_log | perl -nle 's/\?\\([a-f\d]{3})/chr($1)/ieg;s/\\x([a-f\d]{2})/pack("C", hex($1))/ieg;print $_;' #リアルタイムで日本語メッセージをデコード
[Mon Jan 25 00:01:17.680845 2021] [php:warn] [pid 16380] [client 10.0.2.2:57111] PHP Warning: このファイルを実行するべきではありません! in /var/www/html/work/hello.php on line 6
※/var/log/httpd/error_log の部分は、ご自身の環境で使用しているエラーログのパスに変更してください。
これでユーザー定義のエラーログも正しく参照できますね。
ついでに、.bashrcに関数定義して簡単に呼び出せるようにしましょう。
.bashrcに文字化けを直す関数を定義する
[yuuki@localhost ~]$ vim ~/.bashrc
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# Apacheエラーログ日本語出力する関数
function error_log(){
tail -f /var/log/httpd/error_log | perl -nle 's/\?\\([a-f\d]{3})/chr($1)/ieg;s/\\x([a-f\d]{2})/pack("C", hex($1))/ieg;print $_;'
[yuuki@localhost ~]$ source ~/.bashrc #.bashrcを反映
[yuuki@localhost ~]$ error_log #関数呼び出し
[Mon Jan 25 00:01:17.680845 2021] [php:warn] [pid 16380] [client 10.0.2.2:57111] PHP Warning: このファイルを実行するべきではありません! in /var/www/html/work/hello.php on line 6
これで毎回長いコマンドを打たずに済みますね!