log4j是在java中应用非常广泛的日志管理工具,log4php的应用也非常方便,具体配置见下代码:
test.properties:
log4php.rootLogger=DEBUG, A1
log4php.appender.A1=LoggerAppenderDailyFile
log4php.appender.A1.datePattern = YmdH
log4php.appender.A1.file=/www/log/%s/test_%s.log
log4php.appender.A1.layout=LoggerLayoutSimple
test.log.php
<?php require_once('log4php/Logger.php'); Logger::configure('test.properties');
$logger = Logger::getLogger("musicList");
$args="datetime:\"".date("Y-m-d H:i:s",time())."\","; foreach($_GET as $key => $val) $args.=$key.":\"".$val."\","; foreach($_POST as $key => $val) $args.=$key.":\"".$val."\","; $args.="ip:\"".$_SERVER['REMOTE_ADDR']."\"";
$logger->info($args);
?>
|
test.php
<?php include('test.log.php'); ?>
|
日志存储方式即为每小时一个文件。
阅读(1783) | 评论(0) | 转发(0) |