PEAR等を使わずに単純に使う方法
log4phpのダウンロードページよりzip形式のSource packageをダウンロード。
phpフォルダの下にlibsフォルダを作成してダウンロードしたlog4phpを展開
Logger.phpがあるフォルダにPATHを通すためにphp.iniのinclude_pathを設定
;;;;;;;;;;;;;;;;;;;;;;;;; ; 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"
PATHが通ったフォルダ(今回はD:\php\libs\apache-log4php-2.3.0\src\main\php)に設定ファイル(log4php.xml)を作成して配置
<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>
以下がログの出力
require_once("Logger.php"); Logger::configure('log4php.xml'); // 設定ファイルの読み込み $logger = Logger::getLogger('myLogger'); // myLoggerという名前のloggerを使用 $logger->debug("debug message");