ホーム » LOG4PHP

LOG4PHP」カテゴリーアーカイブ

log4php

PEAR等を使わずに単純に使う方法
log4phpダウンロードページよりzip形式のSource packageをダウンロード。

phpフォルダの下にlibsフォルダを作成してダウンロードしたlog4phpを展開

Logger.phpがあるフォルダにPATHを通すためにphp.iniのinclude_pathを設定
[code]
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
include_path = ".;c:\php\includes;D:\php\libs\apache-log4php-2.3.0\src\main\php"
[/code]

PATHが通ったフォルダ(今回はD:\php\libs\apache-log4php-2.3.0\src\main\php)に設定ファイル(log4php.xml)を作成して配置
[code]
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="default" class="LoggerAppenderFile">
<param name="file" value="default.log" />
</appender>
<appender name="myAppender" class="LoggerAppenderFile">
<param name="file" value="d:/log/log4php/myLog.log" />
</appender>
<root>
<level value="warn" />
<appender_ref ref="default" />
</root>
<logger name="myLogger">
<level value="debug" />
<appender_ref ref="myAppender" />
</logger>
</configuration>
[/code]

以下がログの出力
[code]
require_once("Logger.php");
Logger::configure(‘log4php.xml’); // 設定ファイルの読み込み
$logger = Logger::getLogger(‘myLogger’); // myLoggerという名前のloggerを使用
$logger->debug("debug message");
[/code]

LOG4PHPで出力フォーマットに日付を指定したらエラー

LOG4PHPで出力フォーマットを指定しないとログには日時は出力されない
以下はLOG4PHPに渡す設定ファイル(config.xml)の内容
[code]
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="myAppender" class="LoggerAppenderFile">
<param name="file" value="c:/phplog/myLog.log" />
</appender>
<root>
<appender_ref ref="myAppender" />
</root>
</configuration>
[/code]
設定ファイルを以下に変更して日時を出力指定する
[code]
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="myAppender" class="LoggerAppenderFile">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%d %-5p %m%n" />
</layout>
<param name="file" value="c:/phplog/myLog.log" />
</appender>
<root>
<appender_ref ref="myAppender" />
</root>
</configuration>
[/code]
すると以下のエラーが表示された

Warning: date(): It is not safe to rely on the system's timezone settings. 
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. 
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. 
We selected 'Asia/Tokyo' for '9.0/no DST' instead in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\php\php\log4php\pattern\LoggerPatternConverterDate.php on line 74 Warning: date(): 
It is not safe to rely on the system's timezone settings. 
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. 
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. 
We selected 'Asia/Tokyo' for '9.0/no DST' instead in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\php\php\log4php\pattern\LoggerPatternConverterDate.php on line 74 Warning: date(): 
It is not safe to rely on the system's timezone settings. 
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. 
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. 
We selected 'Asia/Tokyo' for '9.0/no DST' instead in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\php\php\log4php\pattern\LoggerPatternConverterDate.php on line 74 Warning: date(): 
It is not safe to rely on the system's timezone settings. 
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. 
We selected 'Asia/Tokyo' for '9.0/no DST' instead in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\php\php\log4php\pattern\LoggerPatternConverterDate.php on line 74

メッセージに従ってphp.iniに以下を追加して対応

date.timezone = Asia/Tokyo