LoginSignup
1
1

More than 1 year has passed since last update.

[PHP] XAMPPのPHPエラーログを出力する(時刻付き)

Last updated at Posted at 2022-01-23

#1.ログフォルダを作成する
C:\xampp\php\logs\配下に"php_error.log"を作成します。

#2.php.iniファイルを開く
C:\xampp\php\ 配下にあるphp.iniファイルを開きます。

#3.以下の設定を変更する。
・log_errors=On
 →もしOffの設定がされている場合、Onにします。
・error_log = php_errors.log
 →php_error.logのコメントがされている場合コメントを外します。

・タイムゾーンを東京にする
;date.timezone=Europe/Berlin
date.timezone=Asia/Tokyo
 →ログに時刻を表示する場合、上記の設定にします。

#4.xamppを再起動する。
xamppよりapacheを再起動します。


#テストプログラムで確認する。

以下のtest.phpをC:\xampp\htdocs配下に作成します。
そしてhttp://localhost/test.php にアクセスします。

「[時刻][ファイル名][行数]コメント」
のようにログに表示されます。

[test.php]
<?php
header( 'Content-type:text/html; charset=utf-8' );
echo '今日は' . date( 'Y年m月d日 H時i分s秒' ) . 'です';

$fruits = array(
        'orange' => 'みかん',
        'apple' => 'リンゴ',
        'greep' => 'ぶどう'
);
error_log(date("[Y/m/d H:i:s][").basename(__FILE__).']['.__LINE__.']'.print_r($fruits,true)."\n","3","C:\\xampp\\php\\logs\\php_error.log");
error_log(date("[Y/m/d H:i:s][").basename(__FILE__).']['.__LINE__.']'.'TEST'."\n","3","C:\\xampp\\php\\logs\\php_error.log");
error_log(date("[Y/m/d H:i:s][").basename(__FILE__).']['.__LINE__.']'.'TESTA'."\n","3","C:\\xampp\\php\\logs\\php_error.log");
error_log(date("[Y/m/d H:i:s][").basename(__FILE__).']['.__LINE__.']'.'TESTB'."\n","3","C:\\xampp\\php\\logs\\php_error.log");
error_log(date("[Y/m/d H:i:s][").basename(__FILE__).']['.__LINE__.']'.'TESTC'."\n","3","C:\\xampp\\php\\logs\\php_error.log");

?>~~~


1
1
2

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
1
1